Search in sources :

Example 1 with CreateCallback

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());
}
Also used : CreateCallback(org.apache.bookkeeper.client.AsyncCallback.CreateCallback) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BKClientClosedException(org.apache.bookkeeper.client.BKException.BKClientClosedException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CreateCallback (org.apache.bookkeeper.client.AsyncCallback.CreateCallback)1 BKClientClosedException (org.apache.bookkeeper.client.BKException.BKClientClosedException)1 Test (org.junit.Test)1