use of org.apache.bookkeeper.client.AsyncCallback.CloseCallback in project bookkeeper by apache.
the class BookieReadWriteTest method testWriteUsingReadOnlyHandle.
@Test
public void testWriteUsingReadOnlyHandle() throws Exception {
// Create a ledger
lh = bkc.createLedger(digestType, ledgerPassword);
ledgerId = lh.getId();
LOG.info("Ledger ID: " + lh.getId());
long lac = writeNEntriesLastWriteSync(lh, numEntriesToWrite);
LedgerHandle lhOpen = bkc.openLedgerNoRecovery(ledgerId, digestType, ledgerPassword);
// addEntry on ReadOnlyHandle should fail
CountDownLatch latch = new CountDownLatch(1);
final int[] rcArray = { 0 };
lhOpen.asyncAddEntry("".getBytes(), new AddCallback() {
@Override
public void addComplete(int rc, LedgerHandle lh, long entryId, Object ctx) {
CountDownLatch latch = (CountDownLatch) ctx;
rcArray[0] = rc;
latch.countDown();
}
}, latch);
latch.await();
if (rcArray[0] != BKException.Code.IllegalOpException) {
Assert.fail("Test1 - asyncAddOperation is supposed to be failed, but it got following rc - " + KeeperException.Code.get(rcArray[0]));
}
// addEntry on ReadOnlyHandle should fail
latch = new CountDownLatch(1);
rcArray[0] = 0;
lhOpen.asyncAddEntry("".getBytes(), 0, 0, new AddCallback() {
@Override
public void addComplete(int rc, LedgerHandle lh, long entryId, Object ctx) {
CountDownLatch latch = (CountDownLatch) ctx;
rcArray[0] = rc;
latch.countDown();
}
}, latch);
latch.await();
if (rcArray[0] != BKException.Code.IllegalOpException) {
Assert.fail("Test2 - asyncAddOperation is supposed to fail with IllegalOpException, but it got following rc - " + KeeperException.Code.get(rcArray[0]));
}
// close readonlyhandle
latch = new CountDownLatch(1);
rcArray[0] = 0;
lhOpen.asyncClose(new CloseCallback() {
@Override
public void closeComplete(int rc, LedgerHandle lh, Object ctx) {
CountDownLatch latch = (CountDownLatch) ctx;
rcArray[0] = rc;
latch.countDown();
}
}, latch);
latch.await();
if (rcArray[0] != KeeperException.Code.OK.intValue()) {
Assert.fail("Test3 - asyncClose failed because of exception - " + KeeperException.Code.get(rcArray[0]));
}
// close of readonlyhandle should not affect the writehandle
writeNEntriesLastWriteSync(lh, 5);
lh.close();
}
use of org.apache.bookkeeper.client.AsyncCallback.CloseCallback in project bookkeeper by apache.
the class BookKeeperCloseTest method testCloseLedger.
/**
* Test that closing a ledger using bookkeeper client which is closed should
* throw ClientClosedException.
*/
@Test
public void testCloseLedger() throws Exception {
BookKeeper bk = new BookKeeper(baseClientConf, zkc);
LOG.info("Create ledger and add entries to it");
LedgerHandle lh = createLedgerWithEntries(bk, 100);
LedgerHandle lh2 = createLedgerWithEntries(bk, 100);
LOG.info("Closing bookkeeper client");
bk.close();
try {
lh.close();
fail("should have failed, client is closed");
} catch (BKClientClosedException e) {
// correct
}
final CountDownLatch completeLatch = new CountDownLatch(1);
final AtomicInteger rc = new AtomicInteger(BKException.Code.OK);
lh2.asyncClose(new CloseCallback() {
public void closeComplete(int rccb, LedgerHandle lh, Object ctx) {
rc.set(rccb);
completeLatch.countDown();
}
}, null);
LOG.info("Waiting to finish adding another entry asynchronously");
assertTrue("Close ledger call should have completed", completeLatch.await(20, TimeUnit.SECONDS));
assertEquals("Close ledger should have succeeded through closed bkclient!", BKException.Code.ClientClosedException, rc.get());
}
use of org.apache.bookkeeper.client.AsyncCallback.CloseCallback in project incubator-pulsar by apache.
the class ManagedCursorImpl method asyncCloseCursorLedger.
void asyncCloseCursorLedger(final AsyncCallbacks.CloseCallback callback, final Object ctx) {
LedgerHandle lh = cursorLedger;
ledger.mbean.startCursorLedgerCloseOp();
log.info("[{}] [{}] Closing metadata ledger {}", ledger.getName(), name, lh.getId());
lh.asyncClose(new CloseCallback() {
@Override
public void closeComplete(int rc, LedgerHandle lh, Object ctx) {
ledger.mbean.endCursorLedgerCloseOp();
if (rc == BKException.Code.OK) {
callback.closeComplete(ctx);
} else {
callback.closeFailed(createManagedLedgerException(rc), ctx);
}
}
}, ctx);
}
use of org.apache.bookkeeper.client.AsyncCallback.CloseCallback in project pulsar by yahoo.
the class ManagedCursorImpl method asyncCloseCursorLedger.
void asyncCloseCursorLedger(final AsyncCallbacks.CloseCallback callback, final Object ctx) {
LedgerHandle lh = cursorLedger;
ledger.mbean.startCursorLedgerCloseOp();
log.info("[{}] [{}] Closing metadata ledger {}", ledger.getName(), name, lh.getId());
lh.asyncClose(new CloseCallback() {
@Override
public void closeComplete(int rc, LedgerHandle lh, Object ctx) {
ledger.mbean.endCursorLedgerCloseOp();
if (rc == BKException.Code.OK) {
callback.closeComplete(ctx);
} else {
callback.closeFailed(new ManagedLedgerException(BKException.getMessage(rc)), ctx);
}
}
}, ctx);
}
Aggregations