use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class NonDurableCursorTest method rewind.
@Test(timeOut = 20000)
void rewind() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2).setRetentionTime(1, TimeUnit.HOURS).setRetentionSizeInMB(1));
ManagedCursor c1 = ledger.newNonDurableCursor(PositionImpl.earliest);
Position p1 = ledger.addEntry("dummy-entry-1".getBytes(Encoding));
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));
log.debug("p1: {}", p1);
log.debug("p2: {}", p2);
log.debug("p3: {}", p3);
log.debug("p4: {}", p4);
assertEquals(c1.getNumberOfEntries(), 4);
assertEquals(c1.getNumberOfEntriesInBacklog(), 4);
c1.markDelete(p1);
assertEquals(c1.getNumberOfEntries(), 3);
assertEquals(c1.getNumberOfEntriesInBacklog(), 3);
List<Entry> entries = c1.readEntries(10);
assertEquals(entries.size(), 3);
entries.forEach(e -> e.release());
assertEquals(c1.getNumberOfEntries(), 0);
assertEquals(c1.getNumberOfEntriesInBacklog(), 3);
c1.rewind();
assertEquals(c1.getNumberOfEntries(), 3);
assertEquals(c1.getNumberOfEntriesInBacklog(), 3);
c1.markDelete(p2);
assertEquals(c1.getNumberOfEntries(), 2);
assertEquals(c1.getNumberOfEntriesInBacklog(), 2);
entries = c1.readEntries(10);
assertEquals(entries.size(), 2);
entries.forEach(e -> e.release());
assertEquals(c1.getNumberOfEntries(), 0);
assertEquals(c1.getNumberOfEntriesInBacklog(), 2);
c1.rewind();
assertEquals(c1.getNumberOfEntries(), 2);
c1.markDelete(p4);
assertEquals(c1.getNumberOfEntries(), 0);
assertEquals(c1.getNumberOfEntriesInBacklog(), 0);
c1.rewind();
assertEquals(c1.getNumberOfEntries(), 0);
ledger.addEntry("dummy-entry-5".getBytes(Encoding));
assertEquals(c1.getNumberOfEntries(), 1);
ledger.addEntry("dummy-entry-6".getBytes(Encoding));
assertEquals(c1.getNumberOfEntries(), 2);
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class NonDurableCursorTest method testResetCursor.
@Test(timeOut = 20000)
void testResetCursor() throws Exception {
ManagedLedger ledger = factory.open("my_test_move_cursor_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(10));
ManagedCursor cursor = ledger.newNonDurableCursor(PositionImpl.latest);
ledger.addEntry("dummy-entry-1".getBytes(Encoding));
ledger.addEntry("dummy-entry-2".getBytes(Encoding));
ledger.addEntry("dummy-entry-3".getBytes(Encoding));
PositionImpl lastPosition = (PositionImpl) ledger.addEntry("dummy-entry-4".getBytes(Encoding));
final AtomicBoolean moveStatus = new AtomicBoolean(false);
PositionImpl resetPosition = new PositionImpl(lastPosition.getLedgerId(), lastPosition.getEntryId() - 2);
try {
cursor.resetCursor(resetPosition);
moveStatus.set(true);
} catch (Exception e) {
log.warn("error in reset cursor", e.getCause());
}
assertTrue(moveStatus.get());
assertTrue(cursor.getReadPosition().equals(resetPosition));
cursor.close();
ledger.close();
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class NonDurableCursorTest method readWithCacheDisabled.
@Test(timeOut = 20000)
void readWithCacheDisabled() throws Exception {
ManagedLedgerFactoryConfig config = new ManagedLedgerFactoryConfig();
config.setMaxCacheSize(0);
factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle(), config);
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(1).setRetentionTime(1, TimeUnit.HOURS).setRetentionSizeInMB(1));
ManagedCursor c1 = ledger.newNonDurableCursor(PositionImpl.latest);
ManagedCursor c2 = ledger.newNonDurableCursor(PositionImpl.latest);
ledger.addEntry("entry-1".getBytes(Encoding));
ledger.addEntry("entry-2".getBytes(Encoding));
List<Entry> entries = c1.readEntries(2);
assertEquals(entries.size(), 2);
assertEquals(new String(entries.get(0).getData(), Encoding), "entry-1");
assertEquals(new String(entries.get(1).getData(), Encoding), "entry-2");
entries.forEach(e -> e.release());
entries = c1.readEntries(2);
assertEquals(entries.size(), 0);
entries.forEach(e -> e.release());
entries = c2.readEntries(2);
assertEquals(entries.size(), 2);
entries.forEach(e -> e.release());
entries = c2.readEntries(2);
assertEquals(entries.size(), 0);
entries.forEach(e -> e.release());
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class NonDurableCursorTest method subscribeToEarliestPositionWithDeferredDeletion.
// (timeOut = 20000)
@Test
void subscribeToEarliestPositionWithDeferredDeletion() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(1).setRetentionTime(1, TimeUnit.HOURS).setRetentionSizeInMB(1));
Position p1 = ledger.addEntry("entry-1".getBytes());
Position p2 = ledger.addEntry("entry-2".getBytes());
/* Position p3 = */
ledger.addEntry("entry-3".getBytes());
/* Position p4 = */
ledger.addEntry("entry-4".getBytes());
/* Position p5 = */
ledger.addEntry("entry-5".getBytes());
/* Position p6 = */
ledger.addEntry("entry-6".getBytes());
ManagedCursor c1 = ledger.newNonDurableCursor(PositionImpl.earliest);
assertEquals(c1.getReadPosition(), p1);
assertEquals(c1.getMarkDeletedPosition(), new PositionImpl(3, -1));
assertEquals(c1.getNumberOfEntries(), 6);
assertEquals(c1.getNumberOfEntriesInBacklog(), 6);
ManagedCursor c2 = ledger.newNonDurableCursor(p1);
assertEquals(c2.getReadPosition(), p2);
assertEquals(c2.getMarkDeletedPosition(), p1);
assertEquals(c2.getNumberOfEntries(), 5);
assertEquals(c2.getNumberOfEntriesInBacklog(), 5);
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class NonDurableCursorTest method testNumberOfEntries.
@Test(timeOut = 20000)
void testNumberOfEntries() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2).setRetentionTime(1, TimeUnit.HOURS).setRetentionSizeInMB(1));
ManagedCursor c1 = ledger.newNonDurableCursor(PositionImpl.latest);
ledger.addEntry("dummy-entry-1".getBytes(Encoding));
ManagedCursor c2 = ledger.newNonDurableCursor(PositionImpl.latest);
ledger.addEntry("dummy-entry-2".getBytes(Encoding));
ManagedCursor c3 = ledger.newNonDurableCursor(PositionImpl.latest);
ledger.addEntry("dummy-entry-3".getBytes(Encoding));
ManagedCursor c4 = ledger.newNonDurableCursor(PositionImpl.latest);
ledger.addEntry("dummy-entry-4".getBytes(Encoding));
ManagedCursor c5 = ledger.newNonDurableCursor(PositionImpl.latest);
assertEquals(c1.getNumberOfEntries(), 4);
assertEquals(c1.hasMoreEntries(), true);
assertEquals(c2.getNumberOfEntries(), 3);
assertEquals(c2.hasMoreEntries(), true);
assertEquals(c3.getNumberOfEntries(), 2);
assertEquals(c3.hasMoreEntries(), true);
assertEquals(c4.getNumberOfEntries(), 1);
assertEquals(c4.hasMoreEntries(), true);
assertEquals(c5.getNumberOfEntries(), 0);
assertEquals(c5.hasMoreEntries(), false);
List<Entry> entries = c1.readEntries(2);
assertEquals(entries.size(), 2);
c1.markDelete(entries.get(1).getPosition());
assertEquals(c1.getNumberOfEntries(), 2);
entries.forEach(e -> e.release());
}
Aggregations