use of org.apache.bookkeeper.mledger.ManagedLedger in project incubator-pulsar by apache.
the class ManagedLedgerErrorsTest method recoverLongTimeAfterWriteError.
@Test
public void recoverLongTimeAfterWriteError() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ManagedCursor cursor = ledger.openCursor("c1");
bkc.failNow(BKException.Code.BookieHandleNotAvailableException);
// With one single error, the write should succeed
ledger.addEntry("entry-1".getBytes());
assertEquals(cursor.getNumberOfEntriesInBacklog(), 1);
bkc.failNow(BKException.Code.BookieHandleNotAvailableException);
zkc.failNow(Code.CONNECTIONLOSS);
try {
ledger.addEntry("entry-2".getBytes());
fail("should fail");
} catch (ManagedLedgerException e) {
// ok
}
Thread.sleep(ManagedLedgerImpl.WaitTimeAfterLedgerCreationFailureMs / 2);
try {
ledger.addEntry("entry-3".getBytes());
fail("should fail");
} catch (ManagedLedgerException e) {
// ok
}
// After some time, the managed ledger will be available for writes again
Thread.sleep(ManagedLedgerImpl.WaitTimeAfterLedgerCreationFailureMs / 2 + 10);
// Next add should succeed, and the previous write should not appear
ledger.addEntry("entry-4".getBytes());
assertEquals(cursor.getNumberOfEntriesInBacklog(), 2);
List<Entry> entries = cursor.readEntries(10);
assertEquals(entries.size(), 2);
assertEquals(new String(entries.get(0).getData()), "entry-1");
assertEquals(new String(entries.get(1).getData()), "entry-4");
entries.forEach(e -> e.release());
}
use of org.apache.bookkeeper.mledger.ManagedLedger in project incubator-pulsar by apache.
the class ManagedLedgerErrorsTest method asyncClosingManagedLedger.
@Test
public void asyncClosingManagedLedger() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ledger.openCursor("c1");
bkc.failNow(BKException.Code.NoSuchLedgerExistsException);
final CountDownLatch latch = new CountDownLatch(1);
ledger.asyncClose(new CloseCallback() {
public void closeFailed(ManagedLedgerException exception, Object ctx) {
latch.countDown();
}
public void closeComplete(Object ctx) {
fail("should have failed");
}
}, null);
latch.await();
}
use of org.apache.bookkeeper.mledger.ManagedLedger in project incubator-pulsar by apache.
the class ManagedLedgerErrorsTest method errorInRecovering4.
@Test
public void errorInRecovering4() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ledger.addEntry("entry".getBytes());
ledger.close();
factory = new ManagedLedgerFactoryImpl(bkc, zkc);
zkc.failAfter(1, Code.CONNECTIONLOSS);
try {
ledger = factory.open("my_test_ledger");
fail("should fail");
} catch (ManagedLedgerException e) {
// ok
}
// It should be fine now
ledger = factory.open("my_test_ledger");
}
use of org.apache.bookkeeper.mledger.ManagedLedger in project incubator-pulsar by apache.
the class ManagedLedgerErrorsTest method errorInUpdatingLedgersList.
@Test(timeOut = 20000, invocationCount = 1, skipFailedInvocations = true, enabled = false)
public void errorInUpdatingLedgersList() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(1));
final CountDownLatch latch = new CountDownLatch(1);
zkc.failAfter(0, Code.CONNECTIONLOSS);
ledger.asyncAddEntry("entry".getBytes(), new AddEntryCallback() {
public void addFailed(ManagedLedgerException exception, Object ctx) {
// not-ok
}
public void addComplete(Position position, Object ctx) {
// ok
}
}, null);
ledger.asyncAddEntry("entry".getBytes(), new AddEntryCallback() {
public void addFailed(ManagedLedgerException exception, Object ctx) {
latch.countDown();
}
public void addComplete(Position position, Object ctx) {
fail("should have failed");
}
}, null);
latch.await();
}
use of org.apache.bookkeeper.mledger.ManagedLedger in project incubator-pulsar by apache.
the class ManagedLedgerErrorsTest method handleCursorRecoveryFailure.
@Test
public void handleCursorRecoveryFailure() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ManagedCursor cursor = ledger.openCursor("my-cursor");
Position p0 = cursor.getMarkDeletedPosition();
Position p1 = ledger.addEntry("entry-1".getBytes());
cursor.markDelete(p1);
// Re-open from a different factory
ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(bkc, zkc);
bkc.failAfter(3, BKException.Code.LedgerRecoveryException);
ledger = factory2.open("my_test_ledger");
cursor = ledger.openCursor("my-cursor");
// Since the cursor was rewind, it will be back to p0
assertEquals(cursor.getMarkDeletedPosition(), p0);
factory2.shutdown();
}
Aggregations