Skip to content

Commit 3071023

Browse files
committed
Travis tests for dump and load data from ES
1 parent be669e6 commit 3071023

21 files changed

Lines changed: 4361 additions & 88 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"nette/di": "^2.4.10",
3030
"nette/security": "^2.4.3",
3131
"nette/utils": "^2.5.3",
32-
"spameri/elastic-query": "^0.4.0",
32+
"spameri/elastic-query": "^0.5.0",
3333
"elasticsearch/elasticsearch": "^6.0",
3434
"kdyby/console": "^2.7.1",
3535
"kdyby/datetime-provider": "v1.0.0",

makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66

77
tests:
8-
vendor/bin/tester tests
8+
vendor/bin/tester -s -c ./tests/php.ini-unix ./tests
99

1010
tests-local:
11-
vendor/bin/tester -c tests/SpameriTests/php.ini tests
11+
vendor/bin/tester -c ./tests/SpameriTests/php.ini tests
1212

1313
phpstan:
1414
vendor/bin/phpstan analyse -l 7 -c phpstan.neon src tests
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Spameri\Elastic\Commands;
44

55

6-
class RestoreIndex extends \Symfony\Component\Console\Command\Command
6+
class LoadDump extends \Symfony\Component\Console\Command\Command
77
{
88

99
/**
@@ -22,13 +22,13 @@ public function __construct(
2222

2323

2424
/**
25-
* @example spameri:elastic:restore-index
25+
* @example spameri:elastic:load-dump
2626
*/
2727
protected function configure() : void
2828
{
2929
$this
30-
->setName('spameri:elastic:restore-index')
31-
->setDescription('Restores data from provided dump file.')
30+
->setName('spameri:elastic:load-dump')
31+
->setDescription('Loads data from provided dump file.')
3232
->addArgument('filename', \Symfony\Component\Console\Input\InputArgument::REQUIRED)
3333
->addArgument(
3434
'step',

src/Commands/TypeToNewIndex.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ protected function configure() : void
3333
->addArgument('typeFrom', \Symfony\Component\Console\Input\InputArgument::REQUIRED)
3434
->addArgument('indexTo', \Symfony\Component\Console\Input\InputArgument::REQUIRED)
3535
->addArgument('aliasTo', \Symfony\Component\Console\Input\InputArgument::REQUIRED)
36+
->addArgument('typeTo', \Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'Use only on old ElasticSearch', NULL)
3637
->addOption('allowClose', 'c', NULL,
3738
'Allows command to close index for data transfer. After data is transferred index is opened and resumes normal operations. When open it needs to check changed files after move and sync remaining.',
3839
TRUE
@@ -51,10 +52,11 @@ protected function execute(
5152
$typeFrom = $input->getArgument('typeFrom');
5253
$indexTo = $input->getArgument('indexTo');
5354
$aliasTo = $input->getArgument('aliasTo');
55+
$typeTo = $input->getOption('typeTo');
5456
$allowClose = $input->getOption('allowClose');
5557

5658
$this->migrate->setOutput($output);
57-
$this->migrate->execute($indexFrom, $typeFrom, $indexTo, $aliasTo, $allowClose);
59+
$this->migrate->execute($indexFrom, $typeFrom, $indexTo, $aliasTo, $typeTo, $allowClose);
5860

5961
$output->writeln('Done');
6062
}

src/Config/Elastic.neon

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ services:
5050
indicePutMapping:
5151
class: Spameri\Elastic\Model\Indices\PutMapping
5252

53+
indicePutSettings:
54+
class: Spameri\Elastic\Model\Indices\PutSettings
55+
5356
indicesCreate:
5457
class: Spameri\Elastic\Model\Indices\Create
5558

@@ -92,7 +95,7 @@ services:
9295
modelDumpIndex:
9396
class: \Spameri\Elastic\Model\DumpIndex
9497

95-
modelRestoreIndex:
98+
restoreIndex:
9699
class: \Spameri\Elastic\Model\RestoreIndex
97100

98101
# ###
@@ -147,8 +150,8 @@ services:
147150
- kdyby.console.command
148151
- console.command
149152

150-
restoreIndex:
151-
class: Spameri\Elastic\Commands\RestoreIndex
153+
loadDump:
154+
class: Spameri\Elastic\Commands\LoadDump
152155
tags:
153156
- kdyby.console.command
154157
- console.command
@@ -174,6 +177,3 @@ services:
174177

175178
dateTime:
176179
class: \DateTimeImmutable
177-
178-
resultMapper:
179-
class: Spameri\ElasticQuery\Response\ResultMapper

src/DI/ElasticSearch30Extension.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/DI/ElasticSearchExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function loadConfiguration() : void
106106

107107
$services = $this->toggleDebugBar($config, $services);
108108

109-
if ( ! class_exists(\Symfony\Component\Console\Command\Command::class)) {
109+
if ( ! \class_exists(\Symfony\Component\Console\Command\Command::class)) {
110110
$services = $this->removeCommandDefinitions($services);
111111
}
112112

src/Model/TypeToNewIndex/DocumentMigrateStatus.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class DocumentMigrateStatus
99
/**
1010
* @var array<string=>int>
1111
*/
12-
private $storage;
12+
private $storage = [];
1313

1414

1515
public function add(

src/Model/TypeToNewIndex/Migrate.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public function execute(
125125
, string $typeFrom
126126
, string $indexTo
127127
, string $aliasTo
128+
, ?string $typeTo
128129
, bool $allowClose
129130
) : void
130131
{
@@ -143,10 +144,9 @@ public function execute(
143144
$settings = \reset($oldIndexSettings);
144145
$this->create->execute($indexTo, [
145146
'settings' => [
146-
'index' => $settings['settings']['index']['analysis'],
147+
'index' => $settings['settings']['index']['analysis'] ?? [],
147148
]
148149
]);
149-
// TODO otestovat
150150

151151
// 2b. Set mapping in new index
152152
$this->output->writeln('Transferring mapping from index: ' . $indexFrom . ' and type: ' . $typeFrom . ' to index: ' . $indexTo);
@@ -169,17 +169,18 @@ public function execute(
169169
// 4. Input data to new index
170170
// 4a. if closed delete data
171171
// 4b. if open store migrated version
172-
/** @var \Spameri\ElasticQuery\Response\Result\Hit $hit */
173-
foreach ($result as $hit) {
174-
$this->processHit($indexTo, $indexFrom, $hit, $allowClose);
175-
176-
/** @noinspection DisconnectedForeachInstructionInspection */
177-
$progressBar->advance();
172+
/** @var \Spameri\ElasticQuery\Response\Result\Hit $response */
173+
foreach ($result->hits() as $response) {
174+
$this->processHit($indexTo, $typeTo, $indexFrom, $response, $allowClose);
178175
}
179-
$from += 5000;
180-
$elasticQuery->options()->changeFrom($from);
181-
if ($result->stats()->total() === 0) {
176+
177+
if (\count($result->hits()->getIterator()) === 0) {
182178
$continue = FALSE;
179+
180+
} else {
181+
$progressBar->advance(5000);
182+
$from += 5000;
183+
$elasticQuery->options()->changeFrom($from);
183184
}
184185
}
185186
$progressBar->finish();
@@ -197,15 +198,15 @@ public function execute(
197198
while ($canContinue) {
198199
$changed = 0;
199200
foreach ($this->documentMigrateStatus->storage() as $documentId => $documentVersion) {
200-
$hit = $this->get->execute(
201-
new \Spameri\Elastic\Entity\Property\ElasticId($documentId),
201+
$response = $this->get->execute(
202+
new \Spameri\Elastic\Entity\Property\ElasticId((string) $documentId),
202203
$indexFrom,
203204
$typeFrom
204205
);
205206

206-
if ($this->documentMigrateStatus->isChanged($documentId, $hit->version())) {
207+
if ($this->documentMigrateStatus->isChanged((string) $documentId, $response->hit()->version())) {
207208
// Reindex this document
208-
$this->processHit($indexTo, $indexFrom, $hit, $allowClose);
209+
$this->processHit($indexTo, $typeTo, $indexFrom, $response, $allowClose);
209210
$changed++;
210211

211212
/** @noinspection DisconnectedForeachInstructionInspection */
@@ -246,6 +247,7 @@ public function execute(
246247
*/
247248
public function processHit(
248249
string $indexTo
250+
, ?string $typeTo
249251
, string $indexFrom
250252
, \Spameri\ElasticQuery\Response\Result\Hit $hit
251253
, bool $allowClose
@@ -254,7 +256,7 @@ public function processHit(
254256
$document = new \Spameri\ElasticQuery\Document(
255257
$indexTo,
256258
new \Spameri\ElasticQuery\Document\Body\Plain($hit->source()),
257-
$indexTo,
259+
$typeTo,
258260
$hit->id()
259261
);
260262

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace SpameriTests\Elastic;
4+
5+
class Config
6+
{
7+
8+
public const INDEX = 'spameri_product';
9+
public const TYPE = 'product';
10+
public const HOST = 'http://127.0.0.1';
11+
12+
public const INDEX_DUMP = 'spameri_product_dump';
13+
public const INDEX_RESTORE = 'spameri_product_restore';
14+
public const INDEX_MIGRATE = 'spameri_product_migrate';
15+
public const INDEX_MIGRATE_NEW = 'spameri_product_migrate_new';
16+
17+
}

0 commit comments

Comments
 (0)