|
3 | 3 | namespace Algolia\AlgoliaSearch\Test\Integration\Indexing\Queue;
|
4 | 4 |
|
5 | 5 | use Algolia\AlgoliaSearch\Helper\ConfigHelper;
|
| 6 | +use Algolia\AlgoliaSearch\Helper\Configuration\QueueHelper; |
6 | 7 | use Algolia\AlgoliaSearch\Model\Indexer\QueueRunner;
|
7 | 8 | use Algolia\AlgoliaSearch\Model\IndicesConfigurator;
|
8 | 9 | use Algolia\AlgoliaSearch\Model\Job;
|
@@ -44,11 +45,11 @@ protected function setUp(): void
|
44 | 45 | public function testFill()
|
45 | 46 | {
|
46 | 47 | $this->resetConfigs([
|
47 |
| - ConfigHelper::NUMBER_OF_JOB_TO_RUN, |
| 48 | + QueueHelper::NUMBER_OF_JOB_TO_RUN, |
48 | 49 | ConfigHelper::NUMBER_OF_ELEMENT_BY_PAGE,
|
49 | 50 | ]);
|
50 | 51 |
|
51 |
| - $this->setConfig(ConfigHelper::IS_ACTIVE, '1'); |
| 52 | + $this->setConfig(QueueHelper::IS_ACTIVE, '1'); |
52 | 53 | $this->connection->query('TRUNCATE TABLE algoliasearch_queue');
|
53 | 54 |
|
54 | 55 | $productBatchQueueProcessor = $this->objectManager->get(ProductBatchQueueProcessor::class);
|
@@ -84,7 +85,7 @@ public function testFill()
|
84 | 85 |
|
85 | 86 | public function testExecute()
|
86 | 87 | {
|
87 |
| - $this->setConfig(ConfigHelper::IS_ACTIVE, '1'); |
| 88 | + $this->setConfig(QueueHelper::IS_ACTIVE, '1'); |
88 | 89 | $this->connection->query('TRUNCATE TABLE algoliasearch_queue');
|
89 | 90 |
|
90 | 91 | $productBatchQueueProcessor = $this->objectManager->get(ProductBatchQueueProcessor::class);
|
@@ -136,16 +137,57 @@ public function testExecute()
|
136 | 137 | $this->assertEquals(0, count($rows));
|
137 | 138 | }
|
138 | 139 |
|
| 140 | + public function testTmpIndexConfig() |
| 141 | + { |
| 142 | + $this->setConfig(QueueHelper::IS_ACTIVE, '1'); |
| 143 | + // Setting "Use a temporary index for full products reindex" configuration to "No" |
| 144 | + $this->setConfig(QueueHelper::USE_TMP_INDEX, '0'); |
| 145 | + $this->connection->query('TRUNCATE TABLE algoliasearch_queue'); |
| 146 | + |
| 147 | + $productBatchQueueProcessor = $this->objectManager->get(ProductBatchQueueProcessor::class); |
| 148 | + $productBatchQueueProcessor->processBatch(1); |
| 149 | + |
| 150 | + $rows = $this->connection->query('SELECT * FROM algoliasearch_queue')->fetchAll(); |
| 151 | + // Without temporary index enabled, there are only 2 jobs (saveConfigurationToAlgolia and buildIndexFull) |
| 152 | + $this->assertEquals(2, count($rows)); |
| 153 | + |
| 154 | + $indexingJob = $rows[1]; |
| 155 | + $jobData = json_decode($indexingJob['data'], true); |
| 156 | + |
| 157 | + $this->assertEquals('buildIndexFull', $indexingJob['method']); |
| 158 | + $this->assertFalse($jobData['options']['useTmpIndex']); |
| 159 | + |
| 160 | + /** @var Queue $queue */ |
| 161 | + $queue = $this->objectManager->get(Queue::class); |
| 162 | + |
| 163 | + // Run the first job (saveSettings) |
| 164 | + $queue->runCron(1, true); |
| 165 | + |
| 166 | + $this->algoliaConnector->waitLastTask(); |
| 167 | + |
| 168 | + $indices = $this->algoliaConnector->listIndexes(); |
| 169 | + |
| 170 | + $existsDefaultTmpIndex = false; |
| 171 | + foreach ($indices['items'] as $index) { |
| 172 | + if ($index['name'] === $this->indexPrefix . 'default_products_tmp') { |
| 173 | + $existsDefaultTmpIndex = true; |
| 174 | + } |
| 175 | + } |
| 176 | + // Checking if the temporary index hasn't been created |
| 177 | + $this->assertFalse($existsDefaultTmpIndex, 'Temporary index exists and it should not'); |
| 178 | + } |
| 179 | + |
139 | 180 | public function testSettings()
|
140 | 181 | {
|
141 | 182 | $this->resetConfigs([
|
142 |
| - ConfigHelper::NUMBER_OF_JOB_TO_RUN, |
| 183 | + QueueHelper::NUMBER_OF_JOB_TO_RUN, |
143 | 184 | ConfigHelper::NUMBER_OF_ELEMENT_BY_PAGE,
|
144 | 185 | ConfigHelper::FACETS,
|
| 186 | + QueueHelper::USE_TMP_INDEX, |
145 | 187 | ConfigHelper::PRODUCT_ATTRIBUTES
|
146 | 188 | ]);
|
147 | 189 |
|
148 |
| - $this->setConfig(ConfigHelper::IS_ACTIVE, '1'); |
| 190 | + $this->setConfig(QueueHelper::IS_ACTIVE, '1'); |
149 | 191 |
|
150 | 192 | $this->connection->query('DELETE FROM algoliasearch_queue');
|
151 | 193 |
|
@@ -178,8 +220,8 @@ public function testSettings()
|
178 | 220 |
|
179 | 221 | public function testMergeSettings()
|
180 | 222 | {
|
181 |
| - $this->setConfig(ConfigHelper::IS_ACTIVE, '1'); |
182 |
| - $this->setConfig(ConfigHelper::NUMBER_OF_JOB_TO_RUN, 1); |
| 223 | + $this->setConfig(QueueHelper::IS_ACTIVE, '1'); |
| 224 | + $this->setConfig(QueueHelper::NUMBER_OF_JOB_TO_RUN, 1); |
183 | 225 | $this->setConfig(ConfigHelper::NUMBER_OF_ELEMENT_BY_PAGE, 300);
|
184 | 226 |
|
185 | 227 | $this->connection->query('DELETE FROM algoliasearch_queue');
|
@@ -791,7 +833,7 @@ public function testGetJobs()
|
791 | 833 | public function testHugeJob()
|
792 | 834 | {
|
793 | 835 | // Default value - maxBatchSize = 1000
|
794 |
| - $this->setConfig(ConfigHelper::NUMBER_OF_JOB_TO_RUN, 10); |
| 836 | + $this->setConfig(QueueHelper::NUMBER_OF_JOB_TO_RUN, 10); |
795 | 837 | $this->setConfig(ConfigHelper::NUMBER_OF_ELEMENT_BY_PAGE, 100);
|
796 | 838 |
|
797 | 839 | $productIds = range(1, 5000);
|
@@ -829,7 +871,7 @@ public function testHugeJob()
|
829 | 871 | public function testMaxSingleJobSize()
|
830 | 872 | {
|
831 | 873 | // Default value - maxBatchSize = 1000
|
832 |
| - $this->setConfig(ConfigHelper::NUMBER_OF_JOB_TO_RUN, 10); |
| 874 | + $this->setConfig(QueueHelper::NUMBER_OF_JOB_TO_RUN, 10); |
833 | 875 | $this->setConfig(ConfigHelper::NUMBER_OF_ELEMENT_BY_PAGE, 100);
|
834 | 876 |
|
835 | 877 | $productIds = range(1, 99);
|
@@ -870,13 +912,13 @@ public function testMaxSingleJobSize()
|
870 | 912 | public function testMaxSingleJobsSizeOnProductReindex()
|
871 | 913 | {
|
872 | 914 | $this->resetConfigs([
|
873 |
| - ConfigHelper::NUMBER_OF_JOB_TO_RUN, |
| 915 | + QueueHelper::NUMBER_OF_JOB_TO_RUN, |
874 | 916 | ConfigHelper::NUMBER_OF_ELEMENT_BY_PAGE,
|
875 | 917 | ]);
|
876 | 918 |
|
877 |
| - $this->setConfig(ConfigHelper::IS_ACTIVE, '1'); |
| 919 | + $this->setConfig(QueueHelper::IS_ACTIVE, '1'); |
878 | 920 |
|
879 |
| - $this->setConfig(ConfigHelper::NUMBER_OF_JOB_TO_RUN, 10); |
| 921 | + $this->setConfig(QueueHelper::NUMBER_OF_JOB_TO_RUN, 10); |
880 | 922 | $this->setConfig(ConfigHelper::NUMBER_OF_ELEMENT_BY_PAGE, 100);
|
881 | 923 |
|
882 | 924 | $this->connection->query('TRUNCATE TABLE algoliasearch_queue');
|
|
0 commit comments