Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BatchSizeManagementTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\DB\Adapter\AdapterInterface;
9 use \Magento\Framework\Indexer\BatchSizeManagement;
10 
11 class BatchSizeManagementTest extends \PHPUnit\Framework\TestCase
12 {
16  private $model;
17 
21  private $rowSizeEstimatorMock;
22 
26  private $loggerMock;
27 
28  protected function setUp()
29  {
30  $this->rowSizeEstimatorMock = $this->createMock(
31  \Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface::class
32  );
33  $this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
34  $this->model = new BatchSizeManagement($this->rowSizeEstimatorMock, $this->loggerMock);
35  }
36 
37  public function testEnsureBatchSize()
38  {
39  $batchSize = 200;
40  $maxHeapTableSize = 16384;
41  $tmpTableSize = 16384;
42  $size = 20000;
43  $innodbPollSize = 100;
44 
45  $this->rowSizeEstimatorMock->expects($this->once())->method('estimateRowSize')->willReturn(100);
46  $adapterMock = $this->createMock(AdapterInterface::class);
47  $adapterMock->expects($this->at(0))
48  ->method('fetchOne')
49  ->with('SELECT @@max_heap_table_size;', [])
50  ->willReturn($maxHeapTableSize);
51  $adapterMock->expects($this->at(1))
52  ->method('fetchOne')
53  ->with('SELECT @@tmp_table_size;', [])
54  ->willReturn($tmpTableSize);
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 the temporary table is more than 20% of innodb_buffer_pool_size. " .
64  "Please update innodb_buffer_pool_size or decrease batch size value ".
65  "(which decreases memory usages for the temporary table). ".
66  "Current batch size: %1; Allocated memory size: %2 bytes; InnoDB buffer pool size: %3 bytes.",
67  [$batchSize, $size, $innodbPollSize]
68  ));
69 
70  $adapterMock->expects($this->at(3))
71  ->method('query')
72  ->with('SET SESSION tmp_table_size = ' . $size . ';', []);
73 
74  $adapterMock->expects($this->at(4))
75  ->method('query')
76  ->with('SET SESSION max_heap_table_size = ' . $size . ';', []);
77 
78  $this->model->ensureBatchSize($adapterMock, $batchSize);
79  }
80 }
__()
Definition: __.php:13