use of org.apache.bookkeeper.mledger.Position in project pulsar by yahoo.
the class ManagedCursorTest method testFindNewestMatchingEven1.
@Test(timeOut = 20000)
void testFindNewestMatchingEven1() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ManagedCursorImpl c1 = (ManagedCursorImpl) ledger.openCursor("c1");
Position p1 = ledger.addEntry("expired".getBytes(Encoding));
ledger.addEntry("not-expired".getBytes(Encoding));
ledger.addEntry("not-expired".getBytes(Encoding));
ledger.addEntry("not-expired".getBytes(Encoding));
assertEquals(c1.findNewestMatching(entry -> Arrays.equals(entry.getDataAndRelease(), "expired".getBytes(Encoding))), p1);
}
use of org.apache.bookkeeper.mledger.Position in project pulsar by yahoo.
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();
}
use of org.apache.bookkeeper.mledger.Position in project pulsar by yahoo.
the class ManagedLedgerErrorsTest method handleCursorRecoveryFailure.
@Test
public void handleCursorRecoveryFailure() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ManagedCursor cursor = ledger.openCursor("my-cursor");
Position p0 = cursor.getMarkDeletedPosition();
Position p1 = ledger.addEntry("entry-1".getBytes());
cursor.markDelete(p1);
// Re-open from a different factory
ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(bkc, zkc);
bkc.failAfter(3, BKException.Code.LedgerRecoveryException);
ledger = factory2.open("my_test_ledger");
cursor = ledger.openCursor("my-cursor");
// Since the cursor was rewind, it will be back to p0
assertEquals(cursor.getMarkDeletedPosition(), p0);
factory2.shutdown();
}
use of org.apache.bookkeeper.mledger.Position in project pulsar by yahoo.
the class ManagedLedgerTest method cursorReadsWithDiscardedEmptyLedgers.
@Test
public void cursorReadsWithDiscardedEmptyLedgers() throws Exception {
ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("my_test_ledger");
ManagedCursor c1 = ledger.openCursor("c1");
Position p1 = c1.getReadPosition();
c1.close();
ledger.close();
// re-open
ledger = (ManagedLedgerImpl) factory.open("my_test_ledger");
c1 = ledger.openCursor("c1");
assertEquals(c1.getNumberOfEntries(), 0);
assertEquals(c1.hasMoreEntries(), false);
ledger.addEntry("entry".getBytes());
assertEquals(c1.getNumberOfEntries(), 1);
assertEquals(c1.hasMoreEntries(), true);
assertEquals(ledger.getLedgersInfoAsList().size(), 1);
List<Entry> entries = c1.readEntries(1);
assertEquals(entries.size(), 1);
entries.forEach(e -> e.release());
assertEquals(c1.hasMoreEntries(), false);
assertEquals(c1.readEntries(1).size(), 0);
c1.seek(p1);
assertEquals(c1.hasMoreEntries(), true);
assertEquals(c1.getNumberOfEntries(), 1);
entries = c1.readEntries(1);
assertEquals(entries.size(), 1);
entries.forEach(e -> e.release());
assertEquals(c1.readEntries(1).size(), 0);
}
use of org.apache.bookkeeper.mledger.Position in project pulsar by yahoo.
the class ManagedLedgerTest method asyncAddEntryWithoutError.
@Test(timeOut = 20000)
public void asyncAddEntryWithoutError() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ledger.openCursor("test-cursor");
final CountDownLatch counter = new CountDownLatch(1);
ledger.asyncAddEntry("dummy-entry-1".getBytes(Encoding), new AddEntryCallback() {
@Override
public void addComplete(Position position, Object ctx) {
assertNull(ctx);
counter.countDown();
}
@Override
public void addFailed(ManagedLedgerException exception, Object ctx) {
fail(exception.getMessage());
}
}, null);
counter.await();
assertEquals(ledger.getNumberOfEntries(), 1);
assertEquals(ledger.getTotalSize(), "dummy-entry-1".getBytes(Encoding).length);
}
Aggregations