Search in sources :

Example 56 with ManagedLedgerException

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

the class ManagedCursorTest method testReplayEntries.

@Test(timeOut = 20000)
void testReplayEntries() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ManagedCursorImpl c1 = (ManagedCursorImpl) ledger.openCursor("c1");
    PositionImpl p1 = (PositionImpl) ledger.addEntry("entry1".getBytes(Encoding));
    PositionImpl p2 = (PositionImpl) ledger.addEntry("entry2".getBytes(Encoding));
    PositionImpl p3 = (PositionImpl) ledger.addEntry("entry3".getBytes(Encoding));
    ledger.addEntry("entry4".getBytes(Encoding));
    // 1. Replay empty position set should return empty entry set
    Set<PositionImpl> positions = Sets.newHashSet();
    assertTrue(c1.replayEntries(positions).isEmpty());
    positions.add(p1);
    positions.add(p3);
    // 2. entries 1 and 3 should be returned, but they can be in any order
    List<Entry> entries = c1.replayEntries(positions);
    assertEquals(entries.size(), 2);
    assertTrue((Arrays.equals(entries.get(0).getData(), "entry1".getBytes(Encoding)) && Arrays.equals(entries.get(1).getData(), "entry3".getBytes(Encoding))) || (Arrays.equals(entries.get(0).getData(), "entry3".getBytes(Encoding)) && Arrays.equals(entries.get(1).getData(), "entry1".getBytes(Encoding))));
    entries.forEach(Entry::release);
    // 3. Fail on reading non-existing position
    PositionImpl invalidPosition = new PositionImpl(100, 100);
    positions.add(invalidPosition);
    try {
        c1.replayEntries(positions);
        fail("Should fail");
    } catch (ManagedLedgerException e) {
    // ok
    }
    positions.remove(invalidPosition);
    // 4. Fail to attempt to read mark-deleted position (p1)
    c1.markDelete(p2);
    try {
        // as mark-delete is at position: p2 it should read entry : p3
        assertEquals(1, c1.replayEntries(positions).size());
    } catch (ManagedLedgerException e) {
        fail("Should have not failed");
    }
}
Also used : Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) Test(org.testng.annotations.Test)

Example 57 with ManagedLedgerException

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

the class ManagedLedgerTest method deleteWithErrors2.

@Test(timeOut = 20000)
public void deleteWithErrors2() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ledger.addEntry("dummy-entry-1".getBytes(Encoding));
    stopZooKeeper();
    try {
        ledger.delete();
        fail("should have failed");
    } catch (ManagedLedgerException e) {
    // ok
    } catch (RejectedExecutionException e) {
    // ok
    }
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Test(org.testng.annotations.Test)

Example 58 with ManagedLedgerException

use of org.apache.bookkeeper.mledger.ManagedLedgerException 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 59 with ManagedLedgerException

use of org.apache.bookkeeper.mledger.ManagedLedgerException 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 60 with ManagedLedgerException

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

Aggregations

ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)133 Test (org.testng.annotations.Test)70 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)65 CountDownLatch (java.util.concurrent.CountDownLatch)63 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)46 Entry (org.apache.bookkeeper.mledger.Entry)36 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)33 Position (org.apache.bookkeeper.mledger.Position)33 CompletableFuture (java.util.concurrent.CompletableFuture)23 AddEntryCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback)21 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)19 List (java.util.List)18 ReadEntriesCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback)18 BKException (org.apache.bookkeeper.client.BKException)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)13 CloseCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.CloseCallback)13 MarkDeleteCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.MarkDeleteCallback)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13