use of org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback in project pulsar by yahoo.
the class ManagedLedgerErrorsTest method recoverLongTimeAfterMultipleWriteErrors.
@Test
public void recoverLongTimeAfterMultipleWriteErrors() throws Exception {
ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("recoverLongTimeAfterMultipleWriteErrors");
ManagedCursor cursor = ledger.openCursor("c1");
bkc.failNow(BKException.Code.BookieHandleNotAvailableException, BKException.Code.BookieHandleNotAvailableException);
CountDownLatch counter = new CountDownLatch(2);
AtomicReference<ManagedLedgerException> ex = new AtomicReference<>();
// Write 2 entries, both should fail the first time and get re-tried internally in a new ledger
AddEntryCallback cb = new AddEntryCallback() {
@Override
public void addComplete(Position position, Object ctx) {
counter.countDown();
}
@Override
public void addFailed(ManagedLedgerException exception, Object ctx) {
log.warn("Error in write", exception);
ex.set(exception);
counter.countDown();
}
};
ledger.asyncAddEntry("entry-1".getBytes(), cb, null);
ledger.asyncAddEntry("entry-2".getBytes(), cb, null);
counter.await();
assertNull(ex.get());
assertEquals(cursor.getNumberOfEntriesInBacklog(), 2);
// Ensure that we are only creating one new ledger
// even when there are multiple (here, 2) add entry failed ops
assertEquals(ledger.getLedgersInfoAsList().size(), 1);
ledger.addEntry("entry-3".getBytes());
List<Entry> entries = cursor.readEntries(10);
assertEquals(entries.size(), 3);
assertEquals(new String(entries.get(0).getData()), "entry-1");
assertEquals(new String(entries.get(1).getData()), "entry-2");
assertEquals(new String(entries.get(2).getData()), "entry-3");
entries.forEach(e -> e.release());
}
Aggregations