Search in sources :

Example 66 with ManagedLedger

use of org.apache.bookkeeper.mledger.ManagedLedger 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)

Example 67 with ManagedLedger

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

the class ManagedLedgerErrorsTest method removingCursor.

@Test
public void removingCursor() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ManagedCursor c1 = ledger.openCursor("c1");
    assertEquals(zkc.exists("/managed-ledgers/my_test_ledger/c1", false) != null, true);
    zkc.failNow(Code.BADVERSION);
    try {
        c1.close();
        fail("should fail");
    } catch (ManagedLedgerException e) {
    // ok
    }
    bkc.failNow(BKException.Code.NoSuchLedgerExistsException);
    // Cursor ledger deletion will fail, but that should not prevent the deleteCursor to fail
    ledger.deleteCursor("c1");
    assertEquals(zkc.exists("/managed-ledgers/my_test_ledger/c1", false) != null, false);
    assertEquals(bkc.getLedgers().size(), 2);
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 68 with ManagedLedger

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

the class ManagedLedgerErrorsTest method errorInUpdatingLedgersList.

@Test(timeOut = 20000, invocationCount = 1, skipFailedInvocations = true, enabled = false)
public void errorInUpdatingLedgersList() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(1));
    final CountDownLatch latch = new CountDownLatch(1);
    zkc.failAfter(0, Code.CONNECTIONLOSS);
    ledger.asyncAddEntry("entry".getBytes(), new AddEntryCallback() {

        public void addFailed(ManagedLedgerException exception, Object ctx) {
        // not-ok
        }

        public void addComplete(Position position, Object ctx) {
        // ok
        }
    }, null);
    ledger.asyncAddEntry("entry".getBytes(), new AddEntryCallback() {

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

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

Example 69 with ManagedLedger

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

the class ManagedLedgerErrorsTest method errorInRecovering.

@Test
public void errorInRecovering() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ledger.addEntry("entry".getBytes());
    ledger.close();
    factory = new ManagedLedgerFactoryImpl(bkc, zkc);
    bkc.failNow(BKException.Code.LedgerFencedException);
    try {
        ledger = factory.open("my_test_ledger");
        fail("should fail");
    } catch (ManagedLedgerException e) {
    // ok
    }
    // It should be fine now
    ledger = factory.open("my_test_ledger");
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) Test(org.testng.annotations.Test)

Example 70 with ManagedLedger

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

the class ManagedLedgerErrorsTest method errorInRecovering3.

@Test
public void errorInRecovering3() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ledger.addEntry("entry".getBytes());
    ledger.close();
    factory = new ManagedLedgerFactoryImpl(bkc, zkc);
    bkc.failAfter(1, BKException.Code.LedgerFencedException);
    try {
        ledger = factory.open("my_test_ledger");
        fail("should fail");
    } catch (ManagedLedgerException e) {
    // ok
    }
    // It should be fine now
    ledger = factory.open("my_test_ledger");
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) Test(org.testng.annotations.Test)

Aggregations

ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)363 Test (org.testng.annotations.Test)354 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)262 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)198 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)180 Position (org.apache.bookkeeper.mledger.Position)167 Entry (org.apache.bookkeeper.mledger.Entry)151 CountDownLatch (java.util.concurrent.CountDownLatch)117 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)98 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)74 AddEntryCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback)68 CyclicBarrier (java.util.concurrent.CyclicBarrier)66 ManagedLedgerFactoryConfig (org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig)59 MarkDeleteCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.MarkDeleteCallback)58 ArrayList (java.util.ArrayList)57 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)57 Future (java.util.concurrent.Future)56 AtomicReference (java.util.concurrent.atomic.AtomicReference)55 ExecutorService (java.util.concurrent.ExecutorService)54 BKException (org.apache.bookkeeper.client.BKException)54