Source:
<code>public void testEntryMemTableParallelFlush() throws Exception { int gcWaitTime = 1000; ServerConfiguration conf = TestBKConfiguration.newServerConfiguration(); conf.setGcWaitTime(gcWaitTime); conf.setLedgerDirNames(createAndGetLedgerDirs(1)); conf.setLedgerStorageClass(FlushTestSortedLedgerStorage.class.getName()); conf.setEntryLogPerLedgerEnabled(true); Bookie bookie = new Bookie(conf); FlushTestSortedLedgerStorage flushTestSortedLedgerStorage = (FlushTestSortedLedgerStorage) bookie.ledgerStorage; EntryMemTable memTable = flushTestSortedLedgerStorage.memTable; bookie.addEntry(generateEntry(1, 1), false, new Bookie.NopWriteCallback(), null, "passwd".getBytes()); bookie.addEntry(generateEntry(2, 1), false, new Bookie.NopWriteCallback(), null, "passwd".getBytes()); bookie.addEntry(generateEntry(3, 1), false, new Bookie.NopWriteCallback(), null, "passwd".getBytes()); flushTestSortedLedgerStorage.addEntry(generateEntry(1, 2)); flushTestSortedLedgerStorage.addEntry(generateEntry(2, 2)); flushTestSortedLedgerStorage.addEntry(generateEntry(3, 2)); assertTrue("EntryMemTable SnapShot is expected to be empty", memTable.snapshot.isEmpty()); assertFalse("EntryMemTable is not expected to be empty", memTable.isEmpty()); flushTestSortedLedgerStorage.setInjectMemTableSizeLimitReached(true); flushTestSortedLedgerStorage.addEntry(generateEntry(1, 3)); <START> Thread.sleep(1000); <END> assertTrue("EntryMemTable SnapShot is expected to be empty", memTable.snapshot.isEmpty()); assertEquals("Flusher called", 1, flushTestSortedLedgerStorage.getNumOfTimesFlushSnapshotCalled()); }</code><technical_language>hmm behavior more deterministic depending timing</technical_language>

Target:
public void testEntryMemTableParallelFlush() throws Exception { int gcWaitTime = 1000; ServerConfiguration conf = TestBKConfiguration.newServerConfiguration(); conf.setGcWaitTime(gcWaitTime); conf.setLedgerDirNames(createAndGetLedgerDirs(1)); conf.setLedgerStorageClass(FlushTestSortedLedgerStorage.class.getName()); conf.setEntryLogPerLedgerEnabled(true); Bookie bookie = new Bookie(conf); FlushTestSortedLedgerStorage flushTestSortedLedgerStorage = (FlushTestSortedLedgerStorage) bookie.ledgerStorage; EntryMemTable memTable = flushTestSortedLedgerStorage.memTable; bookie.addEntry(generateEntry(1, 1), false, new Bookie.NopWriteCallback(), null, "passwd".getBytes()); bookie.addEntry(generateEntry(2, 1), false, new Bookie.NopWriteCallback(), null, "passwd".getBytes()); bookie.addEntry(generateEntry(3, 1), false, new Bookie.NopWriteCallback(), null, "passwd".getBytes()); flushTestSortedLedgerStorage.addEntry(generateEntry(1, 2)); flushTestSortedLedgerStorage.addEntry(generateEntry(2, 2)); flushTestSortedLedgerStorage.addEntry(generateEntry(3, 2)); assertTrue("EntryMemTable SnapShot is expected to be empty", memTable.snapshot.isEmpty()); assertFalse("EntryMemTable is not expected to be empty", memTable.isEmpty()); flushTestSortedLedgerStorage.setInjectMemTableSizeLimitReached(true); flushTestSortedLedgerStorage.addEntry(generateEntry(1, 3)); assertTrue("EntryMemTable SnapShot is expected to be empty", memTable.snapshot.isEmpty()); assertEquals("Flusher called", 1, flushTestSortedLedgerStorage.getNumOfTimesFlushSnapshotCalled()); }