use of org.apache.bookkeeper.bookie.Journal.ForceWriteRequest in project bookkeeper by apache.
the class BookieJournalForceTest method testAckAfterSync.
@Test
public void testAckAfterSync() throws Exception {
File journalDir = tempDir.newFolder();
Bookie.checkDirectoryStructure(Bookie.getCurrentDirectory(journalDir));
ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
conf.setJournalDirName(journalDir.getPath()).setZkServers(null);
JournalChannel jc = spy(new JournalChannel(journalDir, 1));
whenNew(JournalChannel.class).withAnyArguments().thenReturn(jc);
LedgerDirsManager ledgerDirsManager = mock(LedgerDirsManager.class);
Journal journal = new Journal(0, journalDir, conf, ledgerDirsManager);
// machinery to suspend ForceWriteThread
CountDownLatch forceWriteThreadSuspendedLatch = new CountDownLatch(1);
LinkedBlockingQueue<ForceWriteRequest> supportQueue = enableForceWriteThreadSuspension(forceWriteThreadSuspendedLatch, journal);
journal.start();
LogMark lastLogMarkBeforeWrite = journal.getLastLogMark().markLog().getCurMark();
CountDownLatch latch = new CountDownLatch(1);
long ledgerId = 1;
long entryId = 0;
journal.logAddEntry(ledgerId, entryId, DATA, false, /* ackBeforeSync */
new WriteCallback() {
@Override
public void writeComplete(int rc, long ledgerId, long entryId, BookieSocketAddress addr, Object ctx) {
latch.countDown();
}
}, null);
// wait that an entry is written to the ForceWriteThread queue
while (supportQueue.isEmpty()) {
Thread.sleep(100);
}
assertEquals(1, latch.getCount());
assertEquals(1, supportQueue.size());
// in constructor of JournalChannel we are calling forceWrite(true) but it is not tracked by PowerMock
// because the 'spy' is applied only on return from the constructor
verify(jc, times(0)).forceWrite(true);
// let ForceWriteThread work
forceWriteThreadSuspendedLatch.countDown();
// callback should complete now
assertTrue(latch.await(20, TimeUnit.SECONDS));
verify(jc, atLeast(1)).forceWrite(false);
assertEquals(0, supportQueue.size());
// verify that log marker advanced
LastLogMark lastLogMarkAfterForceWrite = journal.getLastLogMark();
assertTrue(lastLogMarkAfterForceWrite.getCurMark().compare(lastLogMarkBeforeWrite) > 0);
journal.shutdown();
}
Aggregations