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();
}
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());
}
Aggregations