Search in sources :

Example 71 with ManagedCursor

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

the class ManagedCursorTest method testGetEntryAfterNWithIndividualDeletedMessages.

@Test(timeOut = 20000)
void testGetEntryAfterNWithIndividualDeletedMessages() throws Exception {
    ManagedLedger ledger = factory.open("testGetEnteryAfterNWithIndividualDeletedMessages");
    ManagedCursor c1 = ledger.openCursor("c1");
    Position pos1 = ledger.addEntry("msg1".getBytes());
    Position pos2 = ledger.addEntry("msg2".getBytes());
    Position pos3 = ledger.addEntry("msg3".getBytes());
    Position pos4 = ledger.addEntry("msg4".getBytes());
    Position pos5 = ledger.addEntry("msg5".getBytes());
    c1.delete(pos3);
    c1.delete(pos4);
    Entry e = c1.getNthEntry(3, IndividualDeletedEntries.Exclude);
    assertEquals(e.getDataAndRelease(), "msg5".getBytes());
    e = c1.getNthEntry(3, IndividualDeletedEntries.Include);
    assertEquals(e.getDataAndRelease(), "msg3".getBytes());
}
Also used : Entry(org.apache.bookkeeper.mledger.Entry) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 72 with ManagedCursor

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

the class ManagedCursorTest method asyncMarkDeleteBlocking.

@Test(timeOut = 20000)
public void asyncMarkDeleteBlocking() throws Exception {
    ManagedLedgerConfig config = new ManagedLedgerConfig();
    config.setMaxEntriesPerLedger(10);
    config.setMetadataMaxEntriesPerLedger(5);
    ManagedLedger ledger = factory.open("my_test_ledger", config);
    final ManagedCursor c1 = ledger.openCursor("c1");
    final AtomicReference<Position> lastPosition = new AtomicReference<Position>();
    final int N = 100;
    final CountDownLatch latch = new CountDownLatch(N);
    for (int i = 0; i < N; i++) {
        ledger.asyncAddEntry("entry".getBytes(Encoding), new AddEntryCallback() {

            public void addFailed(ManagedLedgerException exception, Object ctx) {
            }

            public void addComplete(Position position, Object ctx) {
                lastPosition.set(position);
                c1.asyncMarkDelete(position, new MarkDeleteCallback() {

                    public void markDeleteFailed(ManagedLedgerException exception, Object ctx) {
                    }

                    public void markDeleteComplete(Object ctx) {
                        latch.countDown();
                    }
                }, null);
            }
        }, null);
    }
    latch.await();
    assertEquals(c1.getNumberOfEntries(), 0);
    // Reopen
    ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
    ledger = factory2.open("my_test_ledger");
    ManagedCursor c2 = ledger.openCursor("c1");
    assertEquals(c2.getMarkDeletedPosition(), lastPosition.get());
    factory2.shutdown();
}
Also used : Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) MarkDeleteCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.MarkDeleteCallback) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) AddEntryCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback) Test(org.testng.annotations.Test)

Example 73 with ManagedCursor

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

the class ManagedCursorTest method markDeleteWithErrors.

@Test(timeOut = 20000)
void markDeleteWithErrors() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ManagedCursor cursor = ledger.openCursor("c1");
    ledger.addEntry("dummy-entry-1".getBytes(Encoding));
    List<Entry> entries = cursor.readEntries(100);
    stopBookKeeper();
    assertEquals(entries.size(), 1);
    try {
        cursor.markDelete(entries.get(0).getPosition());
        fail("call should have failed");
    } catch (ManagedLedgerException e) {
    // ok
    }
    entries.forEach(e -> e.release());
}
Also used : Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 74 with ManagedCursor

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

the class ManagedCursorContainerTest method removingCursor.

@Test
void removingCursor() throws Exception {
    ManagedCursorContainer container = new ManagedCursorContainer();
    ManagedCursor cursor1 = new MockManagedCursor(container, "test1", new PositionImpl(5, 5));
    container.add(cursor1);
    assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 5));
    assertEquals(container.get("test1"), cursor1);
    MockManagedCursor cursor2 = new MockManagedCursor(container, "test2", new PositionImpl(2, 2));
    container.add(cursor2);
    assertEquals(container.getSlowestReaderPosition(), new PositionImpl(2, 2));
    assertEquals(container.get("test2"), cursor2);
    MockManagedCursor cursor3 = new MockManagedCursor(container, "test3", new PositionImpl(1, 1));
    container.add(cursor3);
    assertEquals(container.getSlowestReaderPosition(), new PositionImpl(1, 1));
    assertEquals(container.get("test3"), cursor3);
    assertEquals(container, Lists.newArrayList(cursor1, cursor2, cursor3));
    // Remove the cursor in the middle
    container.removeCursor("test2");
    assertEquals(container, Lists.newArrayList(cursor1, cursor3));
    assertEquals(container.get("test2"), null);
    assertEquals(container.getSlowestReaderPosition(), new PositionImpl(1, 1));
    container.removeCursor("test3");
    assertEquals(container, Lists.newArrayList(cursor1));
    assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 5));
}
Also used : ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 75 with ManagedCursor

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

the class ManagedCursorContainerTest method simple.

@Test
void simple() throws Exception {
    ManagedCursorContainer container = new ManagedCursorContainer();
    assertEquals(container.getSlowestReaderPosition(), null);
    ManagedCursor cursor1 = new MockManagedCursor(container, "test1", new PositionImpl(5, 5));
    container.add(cursor1);
    assertEquals(container.getSlowestReaderPosition(), new PositionImpl(5, 5));
    ManagedCursor cursor2 = new MockManagedCursor(container, "test2", new PositionImpl(2, 2));
    container.add(cursor2);
    assertEquals(container.getSlowestReaderPosition(), new PositionImpl(2, 2));
    ManagedCursor cursor3 = new MockManagedCursor(container, "test3", new PositionImpl(2, 0));
    container.add(cursor3);
    assertEquals(container.getSlowestReaderPosition(), new PositionImpl(2, 0));
    assertEquals(container.toString(), "[test1=5:5, test2=2:2, test3=2:0]");
    ManagedCursor cursor4 = new MockManagedCursor(container, "test4", new PositionImpl(4, 0));
    container.add(cursor4);
    assertEquals(container.getSlowestReaderPosition(), new PositionImpl(2, 0));
    ManagedCursor cursor5 = new MockManagedCursor(container, "test5", new PositionImpl(3, 5));
    container.add(cursor5);
    assertEquals(container.getSlowestReaderPosition(), new PositionImpl(2, 0));
    cursor3.markDelete(new PositionImpl(3, 0));
    assertEquals(container.getSlowestReaderPosition(), new PositionImpl(2, 2));
    cursor2.markDelete(new PositionImpl(10, 5));
    assertEquals(container.getSlowestReaderPosition(), new PositionImpl(3, 0));
    container.removeCursor(cursor3.getName());
    assertEquals(container.getSlowestReaderPosition(), new PositionImpl(3, 5));
    container.removeCursor(cursor2.getName());
    container.removeCursor(cursor5.getName());
    container.removeCursor(cursor1.getName());
    assertEquals(container.getSlowestReaderPosition(), new PositionImpl(4, 0));
    assertFalse(container.isEmpty());
    container.removeCursor(cursor4.getName());
    assertEquals(container.getSlowestReaderPosition(), null);
    assertTrue(container.isEmpty());
    ManagedCursor cursor6 = new MockManagedCursor(container, "test6", new PositionImpl(6, 5));
    container.add(cursor6);
    assertEquals(container.getSlowestReaderPosition(), new PositionImpl(6, 5));
    assertEquals(container.toString(), "[test6=6:5]");
}
Also used : 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