Search in sources :

Example 96 with ManagedLedger

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

the class ManagedLedgerErrorsTest method recoverLongTimeAfterWriteError.

@Test
public void recoverLongTimeAfterWriteError() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ManagedCursor cursor = ledger.openCursor("c1");
    bkc.failNow(BKException.Code.BookieHandleNotAvailableException);
    // With one single error, the write should succeed
    ledger.addEntry("entry-1".getBytes());
    assertEquals(cursor.getNumberOfEntriesInBacklog(), 1);
    bkc.failNow(BKException.Code.BookieHandleNotAvailableException);
    zkc.failNow(Code.CONNECTIONLOSS);
    try {
        ledger.addEntry("entry-2".getBytes());
        fail("should fail");
    } catch (ManagedLedgerException e) {
    // ok
    }
    Thread.sleep(ManagedLedgerImpl.WaitTimeAfterLedgerCreationFailureMs / 2);
    try {
        ledger.addEntry("entry-3".getBytes());
        fail("should fail");
    } catch (ManagedLedgerException e) {
    // ok
    }
    // After some time, the managed ledger will be available for writes again
    Thread.sleep(ManagedLedgerImpl.WaitTimeAfterLedgerCreationFailureMs / 2 + 10);
    // Next add should succeed, and the previous write should not appear
    ledger.addEntry("entry-4".getBytes());
    assertEquals(cursor.getNumberOfEntriesInBacklog(), 2);
    List<Entry> entries = cursor.readEntries(10);
    assertEquals(entries.size(), 2);
    assertEquals(new String(entries.get(0).getData()), "entry-1");
    assertEquals(new String(entries.get(1).getData()), "entry-4");
    entries.forEach(e -> e.release());
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 97 with ManagedLedger

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

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 98 with ManagedLedger

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

the class ManagedLedgerErrorsTest method errorInRecovering4.

@Test
public void errorInRecovering4() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ledger.addEntry("entry".getBytes());
    ledger.close();
    factory = new ManagedLedgerFactoryImpl(bkc, zkc);
    zkc.failAfter(1, Code.CONNECTIONLOSS);
    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 99 with ManagedLedger

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

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 100 with ManagedLedger

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

the class ManagedLedgerErrorsTest method handleCursorRecoveryFailure.

@Test
public void handleCursorRecoveryFailure() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ManagedCursor cursor = ledger.openCursor("my-cursor");
    Position p0 = cursor.getMarkDeletedPosition();
    Position p1 = ledger.addEntry("entry-1".getBytes());
    cursor.markDelete(p1);
    // Re-open from a different factory
    ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(bkc, zkc);
    bkc.failAfter(3, BKException.Code.LedgerRecoveryException);
    ledger = factory2.open("my_test_ledger");
    cursor = ledger.openCursor("my-cursor");
    // Since the cursor was rewind, it will be back to p0
    assertEquals(cursor.getMarkDeletedPosition(), p0);
    factory2.shutdown();
}
Also used : Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) 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