use of org.apache.bookkeeper.mledger.ManagedCursor in project pulsar by yahoo.
the class ManagedCursorTest method testReadEntriesOrWait.
@Test(timeOut = 10000)
void testReadEntriesOrWait() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
final int Consumers = 10;
final CountDownLatch counter = new CountDownLatch(Consumers);
for (int i = 0; i < Consumers; i++) {
ManagedCursor c = ledger.openCursor("c" + i);
c.asyncReadEntriesOrWait(1, new ReadEntriesCallback() {
public void readEntriesComplete(List<Entry> entries, Object ctx) {
assertEquals(entries.size(), 1);
entries.forEach(e -> e.release());
counter.countDown();
}
public void readEntriesFailed(ManagedLedgerException exception, Object ctx) {
log.error("Error reading", exception);
}
}, null);
}
ledger.addEntry("test".getBytes());
counter.await();
}
use of org.apache.bookkeeper.mledger.ManagedCursor in project pulsar by yahoo.
the class ManagedCursorTest method testReopenMultipleTimes.
@Test(timeOut = 20000)
public void testReopenMultipleTimes() throws Exception {
ManagedLedger ledger = factory.open("testReopenMultipleTimes");
ManagedCursor c1 = ledger.openCursor("c1");
Position mdPosition = c1.getMarkDeletedPosition();
c1.close();
ledger.close();
ledger = factory.open("testReopenMultipleTimes");
c1 = ledger.openCursor("c1");
// since the empty data ledger will be deleted, the cursor position should also be updated
assertNotEquals(c1.getMarkDeletedPosition(), mdPosition);
c1.close();
ledger.close();
ledger = factory.open("testReopenMultipleTimes");
c1 = ledger.openCursor("c1");
}
use of org.apache.bookkeeper.mledger.ManagedCursor in project pulsar by yahoo.
the class ManagedCursorTest method testOutOfOrderDeletePersistenceWithClose.
@Test(timeOut = 20000)
public void testOutOfOrderDeletePersistenceWithClose() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig());
ManagedCursor c1 = ledger.openCursor("c1");
List<Position> addedPositions = new ArrayList<>();
for (int i = 0; i < 20; i++) {
Position p = ledger.addEntry(("dummy-entry-" + i).getBytes(Encoding));
addedPositions.add(p);
}
// Acknowledge few messages leaving holes
c1.delete(addedPositions.get(2));
c1.delete(addedPositions.get(5));
c1.delete(addedPositions.get(7));
c1.delete(addedPositions.get(8));
c1.delete(addedPositions.get(9));
assertEquals(c1.getNumberOfEntriesInBacklog(), 20 - 5);
ledger.close();
factory.shutdown();
// Re-Open
factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ledger = factory.open("my_test_ledger", new ManagedLedgerConfig());
c1 = ledger.openCursor("c1");
assertEquals(c1.getNumberOfEntriesInBacklog(), 20 - 5);
List<Entry> entries = c1.readEntries(20);
assertEquals(entries.size(), 20 - 5);
List<String> entriesStr = entries.stream().map(e -> new String(e.getDataAndRelease(), Encoding)).collect(Collectors.toList());
assertEquals(entriesStr.get(0), "dummy-entry-0");
assertEquals(entriesStr.get(1), "dummy-entry-1");
// Entry-2 was deleted
assertEquals(entriesStr.get(2), "dummy-entry-3");
assertEquals(entriesStr.get(3), "dummy-entry-4");
// Entry-6 was deleted
assertEquals(entriesStr.get(4), "dummy-entry-6");
assertFalse(c1.hasMoreEntries());
}
use of org.apache.bookkeeper.mledger.ManagedCursor in project pulsar by yahoo.
the class ManagedCursorTest method unorderedAsyncMarkDelete.
@Test(timeOut = 20000)
void unorderedAsyncMarkDelete() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
final ManagedCursor c1 = ledger.openCursor("c1");
Position p1 = ledger.addEntry("entry-1".getBytes(Encoding));
Position p2 = ledger.addEntry("entry-2".getBytes(Encoding));
final CountDownLatch latch = new CountDownLatch(2);
c1.asyncMarkDelete(p2, new MarkDeleteCallback() {
public void markDeleteFailed(ManagedLedgerException exception, Object ctx) {
fail();
}
public void markDeleteComplete(Object ctx) {
latch.countDown();
}
}, null);
c1.asyncMarkDelete(p1, new MarkDeleteCallback() {
public void markDeleteFailed(ManagedLedgerException exception, Object ctx) {
latch.countDown();
}
public void markDeleteComplete(Object ctx) {
fail();
}
}, null);
latch.await();
assertEquals(c1.getMarkDeletedPosition(), p2);
}
use of org.apache.bookkeeper.mledger.ManagedCursor in project pulsar by yahoo.
the class ManagedCursorTest method unorderedMarkDelete.
@Test(timeOut = 20000)
void unorderedMarkDelete() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
final ManagedCursor c1 = ledger.openCursor("c1");
Position p1 = ledger.addEntry("entry-1".getBytes(Encoding));
Position p2 = ledger.addEntry("entry-2".getBytes(Encoding));
c1.markDelete(p2);
try {
c1.markDelete(p1);
fail("Should have thrown exception");
} catch (ManagedLedgerException e) {
// ok
}
assertEquals(c1.getMarkDeletedPosition(), p2);
}
Aggregations