use of org.apache.bookkeeper.mledger.ManagedCursor in project pulsar by yahoo.
the class ManagedCursorTest method randomOrderAcks.
@Test(timeOut = 20000)
void randomOrderAcks() throws Exception {
ManagedLedger ledger = factory.open("outOfOrderAcks");
ManagedCursor c1 = ledger.openCursor("c1");
int N = 10;
List<Position> positions = new ArrayList<>();
for (int i = 0; i < N; i++) {
positions.add(ledger.addEntry("entry".getBytes()));
}
assertEquals(c1.getNumberOfEntriesInBacklog(), N);
// Randomize the ack sequence
Collections.shuffle(positions);
int toDelete = N;
for (Position p : positions) {
assertEquals(c1.getNumberOfEntriesInBacklog(), toDelete);
c1.delete(p);
--toDelete;
assertEquals(c1.getNumberOfEntriesInBacklog(), toDelete);
}
}
use of org.apache.bookkeeper.mledger.ManagedCursor in project pulsar by yahoo.
the class ManagedCursorTest method testasyncResetCursor.
@Test(timeOut = 20000)
void testasyncResetCursor() throws Exception {
ManagedLedger ledger = factory.open("my_test_move_cursor_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(10));
ManagedCursor cursor = ledger.openCursor("tarc1");
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);
CountDownLatch countDownLatch = new CountDownLatch(1);
PositionImpl resetPosition = new PositionImpl(lastPosition.getLedgerId(), lastPosition.getEntryId() - 2);
cursor.asyncResetCursor(resetPosition, new AsyncCallbacks.ResetCursorCallback() {
@Override
public void resetComplete(Object ctx) {
moveStatus.set(true);
countDownLatch.countDown();
}
@Override
public void resetFailed(ManagedLedgerException exception, Object ctx) {
moveStatus.set(false);
countDownLatch.countDown();
}
});
countDownLatch.await();
assertTrue(moveStatus.get());
assertTrue(cursor.getReadPosition().equals(resetPosition));
cursor.close();
ledger.close();
}
use of org.apache.bookkeeper.mledger.ManagedCursor in project pulsar by yahoo.
the class ManagedCursorTest method testSkipEntries.
@Test(timeOut = 20000)
void testSkipEntries() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2));
Position pos;
ManagedCursor c1 = ledger.openCursor("c1");
// test skip on empty ledger
pos = c1.getReadPosition();
c1.skipEntries(1, IndividualDeletedEntries.Exclude);
assertEquals(c1.getReadPosition(), pos);
pos = ledger.addEntry("dummy-entry-1".getBytes(Encoding));
pos = ledger.addEntry("dummy-entry-2".getBytes(Encoding));
// skip entries in same ledger
c1.skipEntries(1, IndividualDeletedEntries.Exclude);
assertEquals(c1.getNumberOfEntries(), 1);
// skip entries until end of ledger
c1.skipEntries(1, IndividualDeletedEntries.Exclude);
assertEquals(c1.getNumberOfEntries(), 0);
assertEquals(c1.getReadPosition(), pos.getNext());
assertEquals(c1.getMarkDeletedPosition(), pos);
// skip entries across ledgers
for (int i = 0; i < 6; i++) {
pos = ledger.addEntry("dummy-entry".getBytes(Encoding));
}
c1.skipEntries(5, IndividualDeletedEntries.Exclude);
assertEquals(c1.getNumberOfEntries(), 1);
// skip more than the current set of entries
c1.skipEntries(10, IndividualDeletedEntries.Exclude);
assertEquals(c1.getNumberOfEntries(), 0);
assertEquals(c1.hasMoreEntries(), false);
assertEquals(c1.getReadPosition(), pos.getNext());
assertEquals(c1.getMarkDeletedPosition(), pos);
}
use of org.apache.bookkeeper.mledger.ManagedCursor in project pulsar by yahoo.
the class ManagedCursorTest method outOfOrderAcks.
@Test(timeOut = 20000)
void outOfOrderAcks() throws Exception {
ManagedLedger ledger = factory.open("outOfOrderAcks");
ManagedCursor c1 = ledger.openCursor("c1");
int N = 10;
List<Position> positions = new ArrayList<>();
for (int i = 0; i < N; i++) {
positions.add(ledger.addEntry("entry".getBytes()));
}
assertEquals(c1.getNumberOfEntriesInBacklog(), N);
c1.delete(positions.get(3));
assertEquals(c1.getNumberOfEntriesInBacklog(), N - 1);
c1.delete(positions.get(2));
assertEquals(c1.getNumberOfEntriesInBacklog(), N - 2);
c1.delete(positions.get(1));
assertEquals(c1.getNumberOfEntriesInBacklog(), N - 3);
c1.delete(positions.get(0));
assertEquals(c1.getNumberOfEntriesInBacklog(), N - 4);
}
use of org.apache.bookkeeper.mledger.ManagedCursor in project pulsar by yahoo.
the class ManagedCursorTest method testFilteringReadEntries.
@Test(timeOut = 20000)
void testFilteringReadEntries() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(3));
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());
assertEquals(cursor.getNumberOfEntries(), 6);
assertEquals(cursor.getNumberOfEntriesInBacklog(), 6);
List<Entry> entries = cursor.readEntries(3);
assertEquals(entries.size(), 3);
entries.forEach(e -> e.release());
assertEquals(cursor.getNumberOfEntries(), 3);
assertEquals(cursor.getNumberOfEntriesInBacklog(), 6);
log.info("Deleting {}", p5);
cursor.delete(p5);
assertEquals(cursor.getNumberOfEntries(), 2);
assertEquals(cursor.getNumberOfEntriesInBacklog(), 5);
entries = cursor.readEntries(3);
assertEquals(entries.size(), 2);
entries.forEach(e -> e.release());
assertEquals(cursor.getNumberOfEntries(), 0);
assertEquals(cursor.getNumberOfEntriesInBacklog(), 5);
}
Aggregations