Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class SystemInfoTest {

private SystemInfo systemInfo;
private DataRegionInfo dataRegionInfo;
private WriteMemoryBlock memoryBlock;
private TsFileProcessor currentProcessor;
private TsFileProcessor largerProcessor;
private ExecutorService originalFlushSubmitter;
Expand All @@ -67,6 +68,10 @@ public void setUp() throws Exception {
DataRegion dataRegion = mock(DataRegion.class);
when(dataRegion.getDatabaseName()).thenReturn("root.test");
dataRegionInfo = new DataRegionInfo(dataRegion);
memoryBlock =
dataRegionInfo
.getWriteMemoryManager()
.createBlock("test-memtable", WriteMemoryBlock.Category.MEMTABLE_ARRAY);
currentProcessor = mock(TsFileProcessor.class);
largerProcessor = mock(TsFileProcessor.class);
mockWorkMemTable(currentProcessor);
Expand All @@ -80,13 +85,14 @@ public void setUp() throws Exception {
@After
public void tearDown() throws Exception {
setMemoryThreshold("flushTaskSubmitThreadPool", originalFlushSubmitter);
memoryBlock.close();
systemInfo.close();
systemInfo.loadWriteMemory();
}

@Test
public void testRejectedWriterCannotFlushSmallerCurrentProcessor() throws Exception {
dataRegionInfo.addStorageGroupMemCost(900);
memoryBlock.add(900);

Assert.assertFalse(systemInfo.reportStorageGroupStatus(dataRegionInfo, currentProcessor));
Assert.assertTrue(systemInfo.isRejected());
Expand All @@ -97,7 +103,7 @@ public void testRejectedWriterCannotFlushSmallerCurrentProcessor() throws Except
@Test
public void testRejectedWriterFirstTabletCannotBypassSelection() throws Exception {
when(currentProcessor.getWorkMemTableRamCost()).thenReturn(0L);
dataRegionInfo.addStorageGroupMemCost(900);
memoryBlock.add(900);

Assert.assertFalse(systemInfo.reportStorageGroupStatus(dataRegionInfo, currentProcessor));
verify(currentProcessor, never()).setWorkMemTableShouldFlush();
Expand All @@ -106,7 +112,7 @@ public void testRejectedWriterFirstTabletCannotBypassSelection() throws Exceptio

@Test
public void testRepeatedReportsSubmitEachMemtableOnce() throws Exception {
dataRegionInfo.addStorageGroupMemCost(900);
memoryBlock.add(900);

for (int i = 0; i < 10; i++) {
Assert.assertFalse(systemInfo.reportStorageGroupStatus(dataRegionInfo, currentProcessor));
Expand All @@ -120,7 +126,7 @@ public void testRepeatedReportsSubmitEachMemtableOnce() throws Exception {
@Test
public void testRepeatedReportsForFirstTabletSubmitOnce() throws Exception {
when(currentProcessor.getWorkMemTableRamCost()).thenReturn(0L);
dataRegionInfo.addStorageGroupMemCost(900);
memoryBlock.add(900);

for (int i = 0; i < 10; i++) {
Assert.assertFalse(systemInfo.reportStorageGroupStatus(dataRegionInfo, currentProcessor));
Expand All @@ -134,7 +140,7 @@ public void testRepeatedReportsForFirstTabletSubmitOnce() throws Exception {
public void testNewMemtableCanBeScheduledAfterPreviousFlush() throws Exception {
when(currentProcessor.getWorkMemTableRamCost()).thenReturn(700L);
when(largerProcessor.getWorkMemTableRamCost()).thenReturn(100L);
dataRegionInfo.addStorageGroupMemCost(900);
memoryBlock.add(900);
Assert.assertTrue(systemInfo.reportStorageGroupStatus(dataRegionInfo, currentProcessor));

mockWorkMemTable(currentProcessor);
Expand All @@ -148,9 +154,9 @@ public void testNewMemtableCanBeScheduledAfterPreviousFlush() throws Exception {
public void testMarkedCurrentProcessorCannotReachHardMemoryLimit() throws Exception {
when(currentProcessor.getWorkMemTableRamCost()).thenReturn(700L);
when(largerProcessor.getWorkMemTableRamCost()).thenReturn(100L);
dataRegionInfo.addStorageGroupMemCost(900);
memoryBlock.add(900);
Assert.assertTrue(systemInfo.reportStorageGroupStatus(dataRegionInfo, currentProcessor));
dataRegionInfo.addStorageGroupMemCost(100);
memoryBlock.add(100);

try {
systemInfo.reportStorageGroupStatus(dataRegionInfo, currentProcessor);
Expand All @@ -166,7 +172,7 @@ public void testMarkedCurrentProcessorCannotReachHardMemoryLimit() throws Except
public void testNoCurrentMemtableCannotBypassRejection() throws Exception {
when(currentProcessor.getWorkMemTable()).thenReturn(null);
when(currentProcessor.getWorkMemTableRamCost()).thenReturn(0L);
dataRegionInfo.addStorageGroupMemCost(900);
memoryBlock.add(900);

Assert.assertFalse(systemInfo.reportStorageGroupStatus(dataRegionInfo, currentProcessor));
Assert.assertTrue(systemInfo.isRejected());
Expand All @@ -176,10 +182,10 @@ public void testNoCurrentMemtableCannotBypassRejection() throws Exception {

@Test
public void testRejectionClearsAfterMemoryIsReleased() throws Exception {
dataRegionInfo.addStorageGroupMemCost(900);
memoryBlock.add(900);
Assert.assertFalse(systemInfo.reportStorageGroupStatus(dataRegionInfo, currentProcessor));

dataRegionInfo.releaseStorageGroupMemCost(500);
memoryBlock.release(500);
systemInfo.resetStorageGroupStatus(dataRegionInfo);
Assert.assertFalse(systemInfo.isRejected());
Assert.assertTrue(systemInfo.reportStorageGroupStatus(dataRegionInfo, currentProcessor));
Expand All @@ -190,7 +196,7 @@ public void testRejectionClearsAfterMemoryIsReleased() throws Exception {
public void testCurrentProcessorCannotExceedHardMemoryLimit() throws Exception {
when(currentProcessor.getWorkMemTableRamCost()).thenReturn(700L);
when(largerProcessor.getWorkMemTableRamCost()).thenReturn(100L);
dataRegionInfo.addStorageGroupMemCost(1100);
memoryBlock.add(1100);

try {
systemInfo.reportStorageGroupStatus(dataRegionInfo, currentProcessor);
Expand All @@ -202,7 +208,7 @@ public void testCurrentProcessorCannotExceedHardMemoryLimit() throws Exception {

@Test
public void testNormalFlushStillSelectsLargestMemtable() throws Exception {
dataRegionInfo.addStorageGroupMemCost(700);
memoryBlock.add(700);

Assert.assertTrue(systemInfo.reportStorageGroupStatus(dataRegionInfo, currentProcessor));
Assert.assertFalse(systemInfo.isRejected());
Expand Down
Loading