use of org.apache.bookkeeper.mledger.ManagedLedger in project incubator-pulsar by apache.
the class ManagedCursorTest method testIndividuallyDeletedMessages2.
@Test(timeOut = 20000)
void testIndividuallyDeletedMessages2() throws Exception {
ManagedLedger ledger = factory.open("testIndividuallyDeletedMessages2");
ManagedCursorImpl c1 = (ManagedCursorImpl) ledger.openCursor("c1");
ledger.addEntry("entry-0".getBytes(Encoding));
ledger.addEntry("entry-1".getBytes(Encoding));
ledger.addEntry("entry-2".getBytes(Encoding));
ledger.addEntry("entry-3".getBytes(Encoding));
ledger.addEntry("entry-4".getBytes(Encoding));
List<Entry> entries = c1.readEntries(4);
c1.delete(entries.get(1).getPosition());
c1.delete(entries.get(2).getPosition());
c1.delete(entries.get(0).getPosition());
entries.forEach(e -> e.release());
assertTrue(c1.isIndividuallyDeletedEntriesEmpty());
}
use of org.apache.bookkeeper.mledger.ManagedLedger in project incubator-pulsar by apache.
the class ManagedCursorTest method testClearBacklog.
@Test(timeOut = 20000)
void testClearBacklog() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(1));
ManagedCursor c1 = ledger.openCursor("c1");
ledger.addEntry("dummy-entry-1".getBytes(Encoding));
ManagedCursor c2 = ledger.openCursor("c2");
ledger.addEntry("dummy-entry-2".getBytes(Encoding));
ManagedCursor c3 = ledger.openCursor("c3");
ledger.addEntry("dummy-entry-3".getBytes(Encoding));
assertEquals(c1.getNumberOfEntriesInBacklog(), 3);
assertEquals(c1.getNumberOfEntries(), 3);
assertEquals(c1.hasMoreEntries(), true);
c1.clearBacklog();
c3.clearBacklog();
assertEquals(c1.getNumberOfEntriesInBacklog(), 0);
assertEquals(c1.getNumberOfEntries(), 0);
assertEquals(c1.hasMoreEntries(), false);
assertEquals(c2.getNumberOfEntriesInBacklog(), 2);
assertEquals(c2.getNumberOfEntries(), 2);
assertEquals(c2.hasMoreEntries(), true);
assertEquals(c3.getNumberOfEntriesInBacklog(), 0);
assertEquals(c3.getNumberOfEntries(), 0);
assertEquals(c3.hasMoreEntries(), false);
ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ledger = factory2.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(1));
c1 = ledger.openCursor("c1");
c2 = ledger.openCursor("c2");
c3 = ledger.openCursor("c3");
assertEquals(c1.getNumberOfEntriesInBacklog(), 0);
assertEquals(c1.getNumberOfEntries(), 0);
assertEquals(c1.hasMoreEntries(), false);
assertEquals(c2.getNumberOfEntriesInBacklog(), 2);
assertEquals(c2.getNumberOfEntries(), 2);
assertEquals(c2.hasMoreEntries(), true);
assertEquals(c3.getNumberOfEntriesInBacklog(), 0);
assertEquals(c3.getNumberOfEntries(), 0);
assertEquals(c3.hasMoreEntries(), false);
factory2.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedger in project incubator-pulsar by apache.
the class ManagedCursorTest method asyncMarkDeleteBlocking.
@Test(timeOut = 20000)
public void asyncMarkDeleteBlocking() throws Exception {
ManagedLedgerConfig config = new ManagedLedgerConfig();
config.setMaxEntriesPerLedger(10);
config.setMetadataMaxEntriesPerLedger(5);
ManagedLedger ledger = factory.open("my_test_ledger", config);
final ManagedCursor c1 = ledger.openCursor("c1");
final AtomicReference<Position> lastPosition = new AtomicReference<Position>();
final int N = 100;
final CountDownLatch latch = new CountDownLatch(N);
for (int i = 0; i < N; i++) {
ledger.asyncAddEntry("entry".getBytes(Encoding), new AddEntryCallback() {
@Override
public void addFailed(ManagedLedgerException exception, Object ctx) {
}
@Override
public void addComplete(Position position, Object ctx) {
lastPosition.set(position);
c1.asyncMarkDelete(position, new MarkDeleteCallback() {
@Override
public void markDeleteFailed(ManagedLedgerException exception, Object ctx) {
}
@Override
public void markDeleteComplete(Object ctx) {
latch.countDown();
}
}, null);
}
}, null);
}
latch.await();
assertEquals(c1.getNumberOfEntries(), 0);
// Reopen
ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ledger = factory2.open("my_test_ledger");
ManagedCursor c2 = ledger.openCursor("c1");
assertEquals(c2.getMarkDeletedPosition(), lastPosition.get());
factory2.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedger in project incubator-pulsar by apache.
the class ManagedCursorTest 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.openCursor("trc1");
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.ManagedLedger in project incubator-pulsar by apache.
the class ManagedLedgerBkTest method testConcurrentMarkDelete.
@Test
public void testConcurrentMarkDelete() throws Exception {
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, zkc);
ManagedLedgerConfig mlConfig = new ManagedLedgerConfig();
mlConfig.setEnsembleSize(1).setAckQuorumSize(1).setMetadataEnsembleSize(1).setMetadataAckQuorumSize(1);
// set the data ledger size
mlConfig.setMaxEntriesPerLedger(100);
// set the metadata ledger size to 1 to kick off many ledger switching cases
mlConfig.setMetadataMaxEntriesPerLedger(10);
ManagedLedger ledger = factory.open("ml-markdelete-ledger", mlConfig);
final List<Position> addedEntries = Lists.newArrayList();
int numCursors = 10;
final CyclicBarrier barrier = new CyclicBarrier(numCursors);
List<ManagedCursor> cursors = Lists.newArrayList();
for (int i = 0; i < numCursors; i++) {
cursors.add(ledger.openCursor(String.format("c%d", i)));
}
for (int i = 0; i < 50; i++) {
Position pos = ledger.addEntry("entry".getBytes());
addedEntries.add(pos);
}
List<Future<?>> futures = Lists.newArrayList();
for (ManagedCursor cursor : cursors) {
futures.add(executor.submit(() -> {
barrier.await();
for (Position position : addedEntries) {
cursor.markDelete(position);
}
return null;
}));
}
for (Future<?> future : futures) {
future.get();
}
// Since in this test we roll-over the cursor ledger every 10 entries acknowledged, the background roll back
// might still be happening when the futures are completed.
Thread.sleep(1000);
factory.shutdown();
}
Aggregations