Skip to content

Commit 17dffbe

Browse files
committed
MAGETWO-58174: When catalog is being indexed it should index in place or leverage an index alias so store can still function during a long index run
- Add integration tests to ensure that Index Switcher was actually used in one type of indexation and not used in others
1 parent a053872 commit 17dffbe

File tree

3 files changed

+63
-28
lines changed

3 files changed

+63
-28
lines changed

dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Indexer/IndexSwitcherMock.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
use Magento\CatalogSearch\Model\Indexer\IndexSwitcherInterface;
1111

12+
/**
13+
* The proxy class around index switcher which allows to ensure that the IndexSwitcher was actually used
14+
*/
1215
class IndexSwitcherMock extends \PHPUnit_Framework_Assert implements IndexSwitcherInterface
1316
{
1417
private $isSwitched = false;
@@ -27,7 +30,6 @@ public function __construct(
2730
$this->indexSwitcher = $indexSwitcher;
2831
}
2932

30-
3133
/**
3234
* Switch current index with temporary index
3335
*
@@ -38,7 +40,7 @@ public function __construct(
3840
*/
3941
public function switchIndex(array $dimensions)
4042
{
41-
$this->isSwitched = true;
43+
$this->isSwitched |= true;
4244
$this->indexSwitcher->switchIndex($dimensions);
4345
}
4446

@@ -47,6 +49,6 @@ public function switchIndex(array $dimensions)
4749
*/
4850
public function isSwitched()
4951
{
50-
return $this->isSwitched;
52+
return (bool) $this->isSwitched;
5153
}
5254
}

dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Indexer/SwitcherUsedInFulltextTest.php

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
*/
1616
class SwitcherUsedInFulltextTest extends \PHPUnit_Framework_TestCase
1717
{
18+
/**
19+
* @var IndexSwitcherInterface
20+
*/
21+
private $indexSwitcher;
22+
1823
/**
1924
* @var \Magento\Framework\Indexer\IndexerInterface
2025
*/
@@ -72,54 +77,96 @@ class SwitcherUsedInFulltextTest extends \PHPUnit_Framework_TestCase
7277

7378
protected function setUp()
7479
{
80+
$objectManager = Bootstrap::getObjectManager();
81+
82+
$objectManager->configure(
83+
[
84+
'Magento\CatalogSearch\Model\Indexer\Fulltext' => [
85+
'arguments' => [
86+
'indexSwitcher' => [
87+
'instance' => 'Magento\CatalogSearch\Model\Indexer\IndexSwitcherMock',
88+
],
89+
],
90+
],
91+
]
92+
);
93+
7594
/** @var \Magento\Framework\Indexer\IndexerInterface indexer */
76-
$this->indexer = Bootstrap::getObjectManager()->create(
95+
$this->indexer = $objectManager->create(
7796
\Magento\Indexer\Model\Indexer::class
7897
);
7998
$this->indexer->load('catalogsearch_fulltext');
8099

81-
$objectManager = Bootstrap::getObjectManager();
82100
$this->engine = $objectManager->get(
83101
\Magento\CatalogSearch\Model\ResourceModel\Engine::class
84102
);
85103

86-
$this->resourceFulltext = Bootstrap::getObjectManager()->get(
104+
$this->resourceFulltext = $objectManager->get(
87105
\Magento\CatalogSearch\Model\ResourceModel\Fulltext::class
88106
);
89107

90-
$this->queryFactory = Bootstrap::getObjectManager()->get(
108+
$this->queryFactory = $objectManager->get(
91109
\Magento\Search\Model\QueryFactory::class
92110
);
93111

94-
$this->dimension = Bootstrap::getObjectManager()->create(
112+
$this->dimension = $objectManager->create(
95113
\Magento\Framework\Search\Request\Dimension::class,
96114
['name' => 'scope', 'value' => '1']
97115
);
98116

117+
$this->indexSwitcher = Bootstrap::getObjectManager()->get(
118+
\Magento\CatalogSearch\Model\Indexer\IndexSwitcherMock::class
119+
);
120+
99121
$this->productApple = $this->getProductBySku('fulltext-1');
100122
$this->productBanana = $this->getProductBySku('fulltext-2');
101123
$this->productOrange = $this->getProductBySku('fulltext-3');
102124
$this->productPapaya = $this->getProductBySku('fulltext-4');
103125
$this->productCherry = $this->getProductBySku('fulltext-5');
104126
}
105127

128+
/**
129+
* @magentoAppIsolation enabled
130+
*/
106131
public function testReindexAll()
107132
{
108133
$this->indexer->reindexAll();
109134

110-
$products = $this->search('Apple');
111-
$this->assertCount(1, $products);
112-
$this->assertEquals($this->productApple->getId(), $products[0]->getId());
113-
114-
$products = $this->search('Simple Product');
115-
$this->assertCount(5, $products);
116135
/** @var \Magento\CatalogSearch\Model\Indexer\IndexSwitcherMock $indexSwitcher */
117136
$indexSwitcher = Bootstrap::getObjectManager()->get(
118137
\Magento\CatalogSearch\Model\Indexer\IndexSwitcherMock::class
119138
);
120139
$this->assertTrue($indexSwitcher->isSwitched());
121140
}
122141

142+
/**
143+
* @magentoAppIsolation enabled
144+
*/
145+
public function testReindexList()
146+
{
147+
$this->indexer->reindexList([$this->productApple->getId(), $this->productBanana->getId()]);
148+
149+
/** @var \Magento\CatalogSearch\Model\Indexer\IndexSwitcherMock $indexSwitcher */
150+
$indexSwitcher = Bootstrap::getObjectManager()->get(
151+
\Magento\CatalogSearch\Model\Indexer\IndexSwitcherMock::class
152+
);
153+
$this->assertFalse($indexSwitcher->isSwitched());
154+
}
155+
156+
/**
157+
* @magentoAppIsolation enabled
158+
*/
159+
public function testReindexRow()
160+
{
161+
$this->indexer->reindexRow($this->productPapaya->getId());
162+
163+
/** @var \Magento\CatalogSearch\Model\Indexer\IndexSwitcherMock $indexSwitcher */
164+
$indexSwitcher = Bootstrap::getObjectManager()->get(
165+
\Magento\CatalogSearch\Model\Indexer\IndexSwitcherMock::class
166+
);
167+
$this->assertFalse($indexSwitcher->isSwitched());
168+
}
169+
123170
/**
124171
* Search the text and return result collection
125172
*

dev/tests/integration/testsuite/Magento/CatalogSearch/_files/etc/di.xml

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

0 commit comments

Comments
 (0)