Skip to content

Commit b88d1bf

Browse files
author
Stanislav Idolov
committed
MAGETWO-64187: Batch size algorithm
1 parent 67924ec commit b88d1bf

File tree

3 files changed

+161
-6
lines changed

3 files changed

+161
-6
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/CompositeProductRowSizeEstimator.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,28 @@
66

77
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Price;
88

9-
class CompositeProductRowSizeEstimator implements \Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface
9+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\IndexTableRowSizeEstimator;
10+
use Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface;
11+
12+
class CompositeProductRowSizeEstimator implements IndexTableRowSizeEstimatorInterface
1013
{
1114
/**
12-
* @var \Magento\Catalog\Model\ResourceModel\Product\Indexer\IndexTableRowSizeEstimator
15+
* @var IndexTableRowSizeEstimator
1316
*/
1417
private $indexTableRowSizeEstimator;
1518

1619
/**
17-
* @var \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice
20+
* @var DefaultPrice
1821
*/
1922
private $indexerResource;
2023

2124
/**
2225
* @param DefaultPrice $indexerResource
23-
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\IndexTableRowSizeEstimator $indexTableRowSizeEstimator
26+
* @param IndexTableRowSizeEstimator $indexTableRowSizeEstimator
2427
*/
2528
public function __construct(
26-
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice $indexerResource,
27-
\Magento\Catalog\Model\ResourceModel\Product\Indexer\IndexTableRowSizeEstimator $indexTableRowSizeEstimator
29+
DefaultPrice $indexerResource,
30+
IndexTableRowSizeEstimator $indexTableRowSizeEstimator
2831
) {
2932
$this->indexerResource = $indexerResource;
3033
$this->indexTableRowSizeEstimator = $indexTableRowSizeEstimator;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Unit\Model\ResourceModel\Product\Indexer;
8+
9+
class IndexTableRowSizeEstimatorTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/**
12+
* @var \Magento\Catalog\Model\ResourceModel\Product\Indexer\IndexTableRowSizeEstimator
13+
*/
14+
private $model;
15+
16+
/**
17+
* @var \PHPUnit_Framework_MockObject_MockObject
18+
*/
19+
private $websiteManagementMock;
20+
21+
/**
22+
* @var \PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
private $collectionFactoryMock;
25+
26+
protected function setUp()
27+
{
28+
$this->websiteManagementMock = $this->getMock(\Magento\Store\Api\WebsiteManagementInterface::class);
29+
$this->collectionFactoryMock = $this->getMock(
30+
\Magento\Customer\Model\ResourceModel\Group\CollectionFactory::class,
31+
['create'],
32+
[],
33+
'',
34+
false
35+
);
36+
$this->model = new \Magento\Catalog\Model\ResourceModel\Product\Indexer\IndexTableRowSizeEstimator(
37+
$this->websiteManagementMock,
38+
$this->collectionFactoryMock
39+
);
40+
}
41+
42+
public function testEstimateRowSize()
43+
{
44+
$expectedValue = 1800000;
45+
46+
$this->websiteManagementMock->expects($this->once())->method('getCount')->willReturn(100);
47+
$collectionMock = $this->getMock(
48+
\Magento\Customer\Model\ResourceModel\Group\Collection::class,
49+
[],
50+
[],
51+
'',
52+
false
53+
);
54+
$this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock);
55+
$collectionMock->expects($this->once())->method('getSize')->willReturn(200);
56+
57+
$this->assertEquals(
58+
$expectedValue,
59+
$this->model->estimateRowSize()
60+
);
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Unit\Model\ResourceModel\Product\Indexer\Price;
8+
9+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CompositeProductRowSizeEstimator;
10+
11+
class CompositeProductRowSizeEstimatorTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var CompositeProductRowSizeEstimator
15+
*/
16+
private $model;
17+
18+
/**
19+
* @var \PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
private $rowSizeEstimatorMock;
22+
23+
/**
24+
* @var \PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
private $defaultPriceMock;
27+
28+
protected function setUp()
29+
{
30+
$this->rowSizeEstimatorMock = $this->getMock(
31+
\Magento\Catalog\Model\ResourceModel\Product\Indexer\IndexTableRowSizeEstimator::class,
32+
[],
33+
[],
34+
'',
35+
false
36+
);
37+
$this->defaultPriceMock = $this->getMock(
38+
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice::class,
39+
[],
40+
[],
41+
'',
42+
false
43+
);
44+
$this->model = new CompositeProductRowSizeEstimator($this->defaultPriceMock, $this->rowSizeEstimatorMock);
45+
}
46+
47+
public function testEstimateRowSize()
48+
{
49+
$expectedResult = 2000;
50+
$tableName = 'catalog_product_relation';
51+
$maxRelatedProductCount = 10;
52+
53+
$this->rowSizeEstimatorMock->expects($this->once())->method('estimateRowSize')->willReturn(200);
54+
55+
$connectionMock = $this->getMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
56+
$this->defaultPriceMock->expects($this->once())->method('getConnection')->willReturn($connectionMock);
57+
$this->defaultPriceMock->expects($this->once())->method('getTable')->with($tableName)->willReturn($tableName);
58+
59+
$relationSelectMock = $this->getMock(\Magento\Framework\DB\Select::class, [], [], '', false);
60+
$relationSelectMock->expects($this->once())
61+
->method('from')
62+
->with(
63+
['relation' => $tableName],
64+
['count' => 'count(relation.child_id)']
65+
)
66+
->willReturnSelf();
67+
$relationSelectMock->expects($this->once())->method('group')->with('parent_id')->willReturnSelf();
68+
$connectionMock->expects($this->at(0))->method('select')->willReturn($relationSelectMock);
69+
70+
$maxSelectMock = $this->getMock(\Magento\Framework\DB\Select::class, [], [], '', false);
71+
$maxSelectMock->expects($this->once())
72+
->method('from')
73+
->with(
74+
['max_value' => $relationSelectMock],
75+
['count' => 'MAX(count)']
76+
)
77+
->willReturnSelf();
78+
$connectionMock->expects($this->at(1))->method('select')->willReturn($maxSelectMock);
79+
80+
$connectionMock->expects($this->at(2))
81+
->method('fetchOne')
82+
->with($maxSelectMock)
83+
->willReturn($maxRelatedProductCount);
84+
85+
$this->assertEquals(
86+
$expectedResult,
87+
$this->model->estimateRowSize()
88+
);
89+
}
90+
}

0 commit comments

Comments
 (0)