Search in sources :

Example 41 with ReadOnlyCursor

use of org.apache.bookkeeper.mledger.ReadOnlyCursor in project pulsar by apache.

the class ReadOnlyCursorTest method skipMultiple.

@Test
void skipMultiple() throws Exception {
    ManagedLedger ledger = factory.open("skip", new ManagedLedgerConfig().setMaxEntriesPerLedger(7).setRetentionTime(1, TimeUnit.HOURS).setRetentionSizeInMB(-1));
    int N = 30;
    for (int i = 0; i < N; i++) {
        ledger.addEntry(("entry-" + i).getBytes());
    }
    ReadOnlyCursor cursor = factory.openReadOnlyCursor("skip", PositionImpl.EARLIEST, new ManagedLedgerConfig());
    assertEquals(cursor.getNumberOfEntries(), N);
    assertTrue(cursor.hasMoreEntries());
    cursor.skipEntries(25);
    assertEquals(cursor.getNumberOfEntries(), 5);
    assertTrue(cursor.hasMoreEntries());
    cursor.skipEntries(5);
    assertEquals(cursor.getNumberOfEntries(), 0);
    assertFalse(cursor.hasMoreEntries());
    cursor.close();
}
Also used : ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ReadOnlyCursor(org.apache.bookkeeper.mledger.ReadOnlyCursor) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Test(org.testng.annotations.Test)

Example 42 with ReadOnlyCursor

use of org.apache.bookkeeper.mledger.ReadOnlyCursor in project pulsar by apache.

the class ReadOnlyCursorTest method specifyStartPosition.

@Test
void specifyStartPosition() throws Exception {
    ManagedLedger ledger = factory.open("simple", new ManagedLedgerConfig().setRetentionTime(1, TimeUnit.HOURS));
    int N = 10;
    for (int i = 0; i < N; i++) {
        ledger.addEntry(("entry-" + i).getBytes());
    }
    ReadOnlyCursor cursor = factory.openReadOnlyCursor("simple", PositionImpl.EARLIEST, new ManagedLedgerConfig());
    assertEquals(cursor.getNumberOfEntries(), N);
    assertTrue(cursor.hasMoreEntries());
    Position readPosition = cursor.getReadPosition();
    cursor = factory.openReadOnlyCursor("simple", readPosition, new ManagedLedgerConfig());
    assertEquals(cursor.getNumberOfEntries(), N);
    assertTrue(cursor.hasMoreEntries());
    cursor.skipEntries(5);
    Position newReadPosition = cursor.getReadPosition();
    cursor = factory.openReadOnlyCursor("simple", newReadPosition, new ManagedLedgerConfig());
    assertEquals(cursor.getNumberOfEntries(), N - 5);
    assertTrue(cursor.hasMoreEntries());
}
Also used : Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ReadOnlyCursor(org.apache.bookkeeper.mledger.ReadOnlyCursor) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Test(org.testng.annotations.Test)

Aggregations

ReadOnlyCursor (org.apache.bookkeeper.mledger.ReadOnlyCursor)42 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)36 Test (org.testng.annotations.Test)24 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)18 Entry (org.apache.bookkeeper.mledger.Entry)15 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)12 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)12 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)12 HashMap (java.util.HashMap)9 LinkedList (java.util.LinkedList)9 NullStatsProvider (org.apache.bookkeeper.stats.NullStatsProvider)9 MessageMetadata (org.apache.pulsar.common.api.proto.MessageMetadata)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 ByteBuf (io.netty.buffer.ByteBuf)6 ArrayList (java.util.ArrayList)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)6 ReadOnlyCursorImpl (org.apache.bookkeeper.mledger.impl.ReadOnlyCursorImpl)6 TopicName (org.apache.pulsar.common.naming.TopicName)6