@@ -20,24 +20,28 @@ class BatchSizeManagementTest extends \PHPUnit_Framework_TestCase
20
20
*/
21
21
private $ rowSizeEstimatorMock ;
22
22
23
+ /**
24
+ * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
25
+ */
26
+ private $ loggerMock ;
27
+
23
28
protected function setUp ()
24
29
{
25
30
$ this ->rowSizeEstimatorMock = $ this ->getMock (
26
31
\Magento \Framework \Indexer \IndexTableRowSizeEstimatorInterface::class
27
32
);
28
- $ this ->model = new BatchSizeManagement ($ this ->rowSizeEstimatorMock );
33
+ $ this ->loggerMock = $ this ->getMock (\Psr \Log \LoggerInterface::class);
34
+ $ this ->model = new BatchSizeManagement ($ this ->rowSizeEstimatorMock , $ this ->loggerMock );
29
35
}
30
36
31
- /**
32
- * @param int $batchSize number of records in the batch
33
- * @param int $maxHeapTableSize max_heap_table_size MySQL value
34
- * @param int $tmpTableSize tmp_table_size MySQL value
35
- * @param int $size
36
- *
37
- * @dataProvider estimateBatchSizeDataProvider
38
- */
39
- public function testEnsureBatchSize ($ batchSize , $ maxHeapTableSize , $ tmpTableSize , $ size )
37
+ public function testEnsureBatchSize ()
40
38
{
39
+ $ batchSize = 200 ;
40
+ $ maxHeapTableSize = 16384 ;
41
+ $ tmpTableSize = 16384 ;
42
+ $ size = 20000 ;
43
+ $ innodbPollSize = 100 ;
44
+
41
45
$ this ->rowSizeEstimatorMock ->expects ($ this ->once ())->method ('estimateRowSize ' )->willReturn (100 );
42
46
$ adapterMock = $ this ->getMock (AdapterInterface::class);
43
47
$ adapterMock ->expects ($ this ->at (0 ))
@@ -48,28 +52,26 @@ public function testEnsureBatchSize($batchSize, $maxHeapTableSize, $tmpTableSize
48
52
->method ('fetchOne ' )
49
53
->with ('SELECT @@tmp_table_size; ' , [])
50
54
->willReturn ($ tmpTableSize );
51
-
52
55
$ adapterMock ->expects ($ this ->at (2 ))
56
+ ->method ('fetchOne ' )
57
+ ->with ('SELECT @@innodb_buffer_pool_size; ' , [])
58
+ ->willReturn ($ innodbPollSize );
59
+
60
+ $ this ->loggerMock ->expects ($ this ->once ())
61
+ ->method ('warning ' )
62
+ ->with (__ (
63
+ 'Memory size allocated for temporary table is more than 20% innodb_buffer_pool_size. ' .
64
+ 'Please update innodb_buffer_pool_size or decrease batch size value. '
65
+ ));
66
+
67
+ $ adapterMock ->expects ($ this ->at (3 ))
53
68
->method ('query ' )
54
69
->with ('SET SESSION tmp_table_size = ' . $ size . '; ' , []);
55
70
56
- $ adapterMock ->expects ($ this ->at (3 ))
71
+ $ adapterMock ->expects ($ this ->at (4 ))
57
72
->method ('query ' )
58
73
->with ('SET SESSION max_heap_table_size = ' . $ size . '; ' , []);
59
74
60
75
$ this ->model ->ensureBatchSize ($ adapterMock , $ batchSize );
61
76
}
62
-
63
- /**
64
- * @return array
65
- */
66
- public function estimateBatchSizeDataProvider ()
67
- {
68
- return [
69
- [200 , 16384 , 16384 , 20000 ],
70
- [300 , 16384 , 20000 , 30000 ],
71
- [400 , 20000 , 16384 , 40000 ],
72
- [500 , 2000 , 2000 , 50000 ],
73
- ];
74
- }
75
77
}
0 commit comments