8 use \Magento\Framework\DB\Adapter\AdapterInterface;
9 use \Magento\Framework\Indexer\BatchSizeManagement;
21 private $rowSizeEstimatorMock;
30 $this->rowSizeEstimatorMock = $this->createMock(
31 \
Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface::class
33 $this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
40 $maxHeapTableSize = 16384;
41 $tmpTableSize = 16384;
43 $innodbPollSize = 100;
45 $this->rowSizeEstimatorMock->expects($this->once())->method(
'estimateRowSize')->willReturn(100);
46 $adapterMock = $this->createMock(AdapterInterface::class);
47 $adapterMock->expects($this->at(0))
49 ->with(
'SELECT @@max_heap_table_size;', [])
50 ->willReturn($maxHeapTableSize);
51 $adapterMock->expects($this->at(1))
53 ->with(
'SELECT @@tmp_table_size;', [])
54 ->willReturn($tmpTableSize);
55 $adapterMock->expects($this->at(2))
57 ->with(
'SELECT @@innodb_buffer_pool_size;', [])
58 ->willReturn($innodbPollSize);
60 $this->loggerMock->expects($this->once())
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]
70 $adapterMock->expects($this->at(3))
72 ->with(
'SET SESSION tmp_table_size = ' . $size .
';', []);
74 $adapterMock->expects($this->at(4))
76 ->with(
'SET SESSION max_heap_table_size = ' . $size .
';', []);
78 $this->model->ensureBatchSize($adapterMock, $batchSize);