Search in sources :

Example 6 with CloseCallback

use of org.apache.bookkeeper.mledger.AsyncCallbacks.CloseCallback in project pulsar by yahoo.

the class ManagedLedgerTest method asyncCloseWithoutError.

@Test(timeOut = 20000)
public void asyncCloseWithoutError() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ledger.openCursor("test-cursor");
    ledger.addEntry("dummy-entry-1".getBytes(Encoding));
    final CountDownLatch counter = new CountDownLatch(1);
    ledger.asyncClose(new CloseCallback() {

        @Override
        public void closeComplete(Object ctx) {
            assertNull(ctx);
            counter.countDown();
        }

        @Override
        public void closeFailed(ManagedLedgerException exception, Object ctx) {
            fail(exception.getMessage());
        }
    }, null);
    counter.await();
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) CloseCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.CloseCallback) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test)

Example 7 with CloseCallback

use of org.apache.bookkeeper.mledger.AsyncCallbacks.CloseCallback in project pulsar by yahoo.

the class ManagedLedgerErrorsTest method asyncClosingManagedLedger.

@Test
public void asyncClosingManagedLedger() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ledger.openCursor("c1");
    bkc.failNow(BKException.Code.NoSuchLedgerExistsException);
    final CountDownLatch latch = new CountDownLatch(1);
    ledger.asyncClose(new CloseCallback() {

        public void closeFailed(ManagedLedgerException exception, Object ctx) {
            latch.countDown();
        }

        public void closeComplete(Object ctx) {
            fail("should have failed");
        }
    }, null);
    latch.await();
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) CloseCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.CloseCallback) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test)

Aggregations

CloseCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.CloseCallback)7 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)7 CompletableFuture (java.util.concurrent.CompletableFuture)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)3 ByteBuf (io.netty.buffer.ByteBuf)2 AddEntryCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback)2 DeleteCursorCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.DeleteCursorCallback)2 OpenCursorCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.OpenCursorCallback)2 OpenLedgerCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.OpenLedgerCallback)2 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)2 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)2 Matchers.anyObject (org.mockito.Matchers.anyObject)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Test (org.testng.annotations.Test)2 PersistenceException (com.yahoo.pulsar.broker.service.BrokerServiceException.PersistenceException)1 SubscriptionBusyException (com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException)1 TopicFencedException (com.yahoo.pulsar.broker.service.BrokerServiceException.TopicFencedException)1 DeleteLedgerCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.DeleteLedgerCallback)1 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)1