use of org.apache.bookkeeper.mledger.ManagedLedgerException in project pulsar by yahoo.
the class ManagedLedgerErrorsTest method errorInRecovering.
@Test
public void errorInRecovering() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ledger.addEntry("entry".getBytes());
ledger.close();
factory = new ManagedLedgerFactoryImpl(bkc, zkc);
bkc.failNow(BKException.Code.LedgerFencedException);
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.ManagedLedgerException in project pulsar by yahoo.
the class ManagedLedgerErrorsTest method errorInRecovering3.
@Test
public void errorInRecovering3() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ledger.addEntry("entry".getBytes());
ledger.close();
factory = new ManagedLedgerFactoryImpl(bkc, zkc);
bkc.failAfter(1, BKException.Code.LedgerFencedException);
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.ManagedLedgerException in project pulsar by yahoo.
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.ManagedLedgerException in project pulsar by yahoo.
the class ManagedLedgerBkTest method testBookieFailure.
@Test
public void testBookieFailure() throws Exception {
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, zkc);
ManagedLedgerConfig config = new ManagedLedgerConfig();
config.setEnsembleSize(2).setAckQuorumSize(2).setMetadataEnsembleSize(2);
ManagedLedger ledger = factory.open("my-ledger", config);
ManagedCursor cursor = ledger.openCursor("my-cursor");
ledger.addEntry("entry-0".getBytes());
killBookie(1);
// Now we want to simulate that:
// 1. The write operation fails because we only have 1 bookie available
// 2. The bk client cannot properly close the ledger (finalizing the number of entries) because ZK is also
// not available
// 3. When we re-establish the service one, the ledger recovery will be triggered and the half-committed entry
// is restored
// Force to close the ZK client object so that BK will fail to close the ledger
bkc.getZkHandle().close();
try {
ledger.addEntry("entry-1".getBytes());
fail("should fail");
} catch (ManagedLedgerException e) {
// ok
}
bkc = new BookKeeperTestClient(baseClientConf);
startNewBookie();
// Reconnect a new bk client
factory = new ManagedLedgerFactoryImpl(bkc, zkc);
ledger = factory.open("my-ledger", config);
cursor = ledger.openCursor("my-cursor");
// Next add should succeed
ledger.addEntry("entry-2".getBytes());
assertEquals(3, cursor.getNumberOfEntriesInBacklog());
List<Entry> entries = cursor.readEntries(1);
assertEquals(1, entries.size());
assertEquals("entry-0", new String(entries.get(0).getData()));
entries.forEach(e -> e.release());
// entry-1 which was half-committed will get fully committed during the recovery phase
entries = cursor.readEntries(1);
assertEquals(1, entries.size());
assertEquals("entry-1", new String(entries.get(0).getData()));
entries.forEach(e -> e.release());
entries = cursor.readEntries(1);
assertEquals(1, entries.size());
assertEquals("entry-2", new String(entries.get(0).getData()));
entries.forEach(e -> e.release());
factory.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedgerException in project pulsar by yahoo.
the class ManagedLedgerBkTest method asyncMarkDeleteAndClose.
@Test
public void asyncMarkDeleteAndClose() throws Exception {
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, zkc);
ManagedLedgerConfig config = new ManagedLedgerConfig().setEnsembleSize(1).setWriteQuorumSize(1).setAckQuorumSize(1).setMetadataEnsembleSize(1).setMetadataWriteQuorumSize(1).setMetadataAckQuorumSize(1);
ManagedLedger ledger = factory.open("my_test_ledger", config);
ManagedCursor cursor = ledger.openCursor("c1");
List<Position> positions = Lists.newArrayList();
for (int i = 0; i < 10; i++) {
Position p = ledger.addEntry("entry".getBytes());
positions.add(p);
}
final CountDownLatch counter = new CountDownLatch(positions.size());
final AtomicBoolean gotException = new AtomicBoolean(false);
for (Position p : positions) {
cursor.asyncDelete(p, new DeleteCallback() {
@Override
public void deleteComplete(Object ctx) {
// Ok
counter.countDown();
}
@Override
public void deleteFailed(ManagedLedgerException exception, Object ctx) {
exception.printStackTrace();
gotException.set(true);
counter.countDown();
}
}, null);
}
cursor.close();
ledger.close();
counter.await();
assertFalse(gotException.get());
factory.shutdown();
}
Aggregations