Search in sources :

Example 86 with ManagedCursor

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

the class ManagedCursorTest method errorRecoveringCursor.

@Test(timeOut = 20000)
void errorRecoveringCursor() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    Position p1 = ledger.addEntry("entry".getBytes());
    ledger.addEntry("entry".getBytes());
    ManagedCursor c1 = ledger.openCursor("c1");
    Position p3 = ledger.addEntry("entry".getBytes());
    assertEquals(c1.getReadPosition(), p3);
    ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
    bkc.failAfter(3, BKException.Code.LedgerRecoveryException);
    ledger = factory2.open("my_test_ledger");
    c1 = ledger.openCursor("c1");
    // Verify the ManagedCursor was rewind back to the snapshotted position
    assertEquals(c1.getReadPosition(), p3);
    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)

Example 87 with ManagedCursor

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

the class ManagedCursorTest method markDeleteSkippingMessage.

@Test(timeOut = 20000)
void markDeleteSkippingMessage() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(10));
    ManagedCursor cursor = ledger.openCursor("c1");
    Position p1 = ledger.addEntry("dummy-entry-1".getBytes(Encoding));
    Position p2 = ledger.addEntry("dummy-entry-2".getBytes(Encoding));
    ledger.addEntry("dummy-entry-3".getBytes(Encoding));
    PositionImpl p4 = (PositionImpl) ledger.addEntry("dummy-entry-4".getBytes(Encoding));
    assertEquals(cursor.getNumberOfEntries(), 4);
    cursor.markDelete(p1);
    assertEquals(cursor.hasMoreEntries(), true);
    assertEquals(cursor.getNumberOfEntries(), 3);
    assertEquals(cursor.getReadPosition(), p2);
    List<Entry> entries = cursor.readEntries(1);
    assertEquals(entries.size(), 1);
    assertEquals(new String(entries.get(0).getData(), Encoding), "dummy-entry-2");
    entries.forEach(e -> e.release());
    cursor.markDelete(p4);
    assertEquals(cursor.hasMoreEntries(), false);
    assertEquals(cursor.getNumberOfEntries(), 0);
    assertEquals(cursor.getReadPosition(), new PositionImpl(p4.getLedgerId(), p4.getEntryId() + 1));
}
Also used : Entry(org.apache.bookkeeper.mledger.Entry) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 88 with ManagedCursor

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

the class ManagedCursorTest method cursorPersistence2.

@Test(timeOut = 20000)
void cursorPersistence2() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMetadataMaxEntriesPerLedger(1));
    ManagedCursor c1 = ledger.openCursor("c1");
    ManagedCursor c2 = ledger.openCursor("c2");
    ManagedCursor c3 = ledger.openCursor("c3");
    Position p0 = c3.getMarkDeletedPosition();
    Position p1 = ledger.addEntry("dummy-entry-1".getBytes(Encoding));
    ManagedCursor c4 = ledger.openCursor("c4");
    Position p2 = ledger.addEntry("dummy-entry-2".getBytes(Encoding));
    Position p3 = ledger.addEntry("dummy-entry-3".getBytes(Encoding));
    Position p4 = ledger.addEntry("dummy-entry-4".getBytes(Encoding));
    Position p5 = ledger.addEntry("dummy-entry-5".getBytes(Encoding));
    ledger.addEntry("dummy-entry-6".getBytes(Encoding));
    c1.markDelete(p1);
    c1.markDelete(p2);
    c1.markDelete(p3);
    c1.markDelete(p4);
    c1.markDelete(p5);
    c2.markDelete(p1);
    // Reopen
    ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
    ledger = factory.open("my_test_ledger");
    c1 = ledger.openCursor("c1");
    c2 = ledger.openCursor("c2");
    c3 = ledger.openCursor("c3");
    c4 = ledger.openCursor("c4");
    assertEquals(c1.getMarkDeletedPosition(), p5);
    assertEquals(c2.getMarkDeletedPosition(), p1);
    assertEquals(c3.getMarkDeletedPosition(), p0);
    assertEquals(c4.getMarkDeletedPosition(), p1);
    factory2.shutdown();
}
Also used : Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 89 with ManagedCursor

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

the class ManagedCursorTest method seekPosition2.

@Test(timeOut = 20000)
void seekPosition2() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2));
    ManagedCursor cursor = ledger.openCursor("c1");
    ledger.addEntry("dummy-entry-1".getBytes(Encoding));
    ledger.addEntry("dummy-entry-2".getBytes(Encoding));
    PositionImpl seekPosition = (PositionImpl) ledger.addEntry("dummy-entry-3".getBytes(Encoding));
    ledger.addEntry("dummy-entry-4".getBytes(Encoding));
    ledger.addEntry("dummy-entry-5".getBytes(Encoding));
    ledger.addEntry("dummy-entry-6".getBytes(Encoding));
    cursor.seek(new PositionImpl(seekPosition.getLedgerId(), seekPosition.getEntryId()));
}
Also used : ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 90 with ManagedCursor

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

the class ManagedCursorTest method testCountingWithDeletedEntries.

@Test(timeOut = 20000)
void testCountingWithDeletedEntries() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2));
    ManagedCursor cursor = ledger.openCursor("c1");
    Position p1 = ledger.addEntry("entry1".getBytes());
    /* Position p2 = */
    ledger.addEntry("entry2".getBytes());
    /* Position p3 = */
    ledger.addEntry("entry3".getBytes());
    /* Position p4 = */
    ledger.addEntry("entry4".getBytes());
    Position p5 = ledger.addEntry("entry5".getBytes());
    Position p6 = ledger.addEntry("entry6".getBytes());
    Position p7 = ledger.addEntry("entry7".getBytes());
    Position p8 = ledger.addEntry("entry8".getBytes());
    assertEquals(cursor.getNumberOfEntries(), 8);
    assertEquals(cursor.getNumberOfEntriesInBacklog(), 8);
    cursor.delete(p8);
    assertEquals(cursor.getNumberOfEntries(), 7);
    assertEquals(cursor.getNumberOfEntriesInBacklog(), 7);
    cursor.delete(p1);
    assertEquals(cursor.getNumberOfEntries(), 6);
    assertEquals(cursor.getNumberOfEntriesInBacklog(), 6);
    cursor.delete(p7);
    cursor.delete(p6);
    cursor.delete(p5);
    assertEquals(cursor.getNumberOfEntries(), 3);
    assertEquals(cursor.getNumberOfEntriesInBacklog(), 3);
}
Also used : Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Aggregations

ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)135 Test (org.testng.annotations.Test)126 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)102 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)66 Position (org.apache.bookkeeper.mledger.Position)59 Entry (org.apache.bookkeeper.mledger.Entry)57 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)52 CountDownLatch (java.util.concurrent.CountDownLatch)32 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)28 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)17 CyclicBarrier (java.util.concurrent.CyclicBarrier)15 AddEntryCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback)12 ManagedLedgerFactoryConfig (org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig)12 List (java.util.List)10 BKException (org.apache.bookkeeper.client.BKException)10 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)10 Future (java.util.concurrent.Future)9 TimeUnit (java.util.concurrent.TimeUnit)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 MarkDeleteCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.MarkDeleteCallback)9