use of org.apache.bookkeeper.client.BKException.BKClientClosedException in project bookkeeper by apache.
the class BookKeeperCloseTest method testCreateLedger.
/**
* Test that createledger using bookkeeper client which is closed should
* throw ClientClosedException.
*/
@Test
public void testCreateLedger() throws Exception {
BookKeeper bk = new BookKeeper(baseClientConf, zkc);
LOG.info("Closing bookkeeper client");
bk.close();
try {
bk.createLedger(digestType, PASSWORD.getBytes());
fail("should have failed, client is closed");
} catch (BKClientClosedException e) {
// correct
}
// using async, because this could trigger an assertion
final AtomicInteger returnCode = new AtomicInteger(0);
final CountDownLatch openLatch = new CountDownLatch(1);
CreateCallback cb = new CreateCallback() {
@Override
public void createComplete(int rc, LedgerHandle lh, Object ctx) {
returnCode.set(rc);
openLatch.countDown();
}
};
bk.asyncCreateLedger(3, 2, digestType, PASSWORD.getBytes(), cb, openLatch);
LOG.info("Waiting to finish the ledger creation");
// wait for creating the ledger
assertTrue("create ledger call should have completed", openLatch.await(20, TimeUnit.SECONDS));
assertEquals("Succesfully created ledger through closed bkclient!", BKException.Code.ClientClosedException, returnCode.get());
}
use of org.apache.bookkeeper.client.BKException.BKClientClosedException in project bookkeeper by apache.
the class BookKeeperCloseTest method testFenceLedger.
/**
* Test that opening a ledger using bookkeeper client which is closed should
* throw ClientClosedException.
*/
@Test
public void testFenceLedger() throws Exception {
BookKeeper bk = new BookKeeper(baseClientConf, zkc);
LOG.info("Create ledger and add entries to it");
LedgerHandle lh = createLedgerWithEntries(bk, 100);
LOG.info("Closing bookkeeper client");
restartBookieSlow();
bk.close();
try {
bk.openLedger(lh.getId(), digestType, PASSWORD.getBytes());
fail("should have failed, client is closed");
} catch (BKClientClosedException e) {
// correct
}
try {
bk.openLedgerNoRecovery(lh.getId(), digestType, PASSWORD.getBytes());
fail("should have failed, client is closed");
} catch (BKClientClosedException e) {
// correct
}
final AtomicInteger returnCode = new AtomicInteger(0);
final CountDownLatch openLatch = new CountDownLatch(1);
AsyncCallback.OpenCallback cb = new AsyncCallback.OpenCallback() {
public void openComplete(int rc, LedgerHandle lh, Object ctx) {
returnCode.set(rc);
openLatch.countDown();
}
};
bk.asyncOpenLedger(lh.getId(), digestType, PASSWORD.getBytes(), cb, openLatch);
LOG.info("Waiting to open the ledger asynchronously");
assertTrue("Open call should have completed", openLatch.await(20, TimeUnit.SECONDS));
assertTrue("Open should not have succeeded through closed bkclient!", BKException.Code.ClientClosedException == returnCode.get());
}
Aggregations