use of org.apache.bookkeeper.client.AsyncCallback.CreateCallback 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());
}
Aggregations