use of org.apache.bookkeeper.mledger.ManagedLedger 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.ManagedLedger 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.ManagedLedger in project pulsar by yahoo.
the class ManagedLedgerBkTest method testOfflineTopicBacklog.
@Test
public void testOfflineTopicBacklog() throws Exception {
ManagedLedgerFactoryConfig factoryConf = new ManagedLedgerFactoryConfig();
factoryConf.setMaxCacheSize(0);
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, zkc, factoryConf);
ManagedLedgerConfig config = new ManagedLedgerConfig();
config.setEnsembleSize(1).setWriteQuorumSize(1).setAckQuorumSize(1).setMetadataEnsembleSize(1).setMetadataAckQuorumSize(1);
ManagedLedger ledger = factory.open("property/cluster/namespace/my-ledger", config);
ManagedCursor cursor = ledger.openCursor("c1");
int N = 1;
for (int i = 0; i < N; i++) {
String entry = "entry-" + i;
ledger.addEntry(entry.getBytes());
}
List<Entry> entries = cursor.readEntries(N);
assertEquals(N, entries.size());
entries.forEach(e -> e.release());
ledger.close();
ManagedLedgerOfflineBacklog offlineTopicBacklog = new ManagedLedgerOfflineBacklog(DigestType.CRC32, "".getBytes(Charsets.UTF_8), "", false);
PersistentOfflineTopicStats offlineTopicStats = offlineTopicBacklog.getEstimatedUnloadedTopicBacklog((ManagedLedgerFactoryImpl) factory, "property/cluster/namespace/my-ledger");
factory.shutdown();
assertNotNull(offlineTopicStats);
}
use of org.apache.bookkeeper.mledger.ManagedLedger 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.ManagedLedger in project pulsar by yahoo.
the class ManagedLedgerTest method testAsyncCleanup.
@Test(timeOut = 20000)
public void testAsyncCleanup() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ledger.openCursor("c1");
ledger.addEntry("data".getBytes(Encoding));
assertEquals(bkc.getLedgers().size(), 2);
final CountDownLatch latch = new CountDownLatch(1);
ledger.asyncDelete(new DeleteLedgerCallback() {
@Override
public void deleteLedgerFailed(ManagedLedgerException exception, Object ctx) {
fail("should have succeeded");
}
@Override
public void deleteLedgerComplete(Object ctx) {
latch.countDown();
}
}, null);
latch.await();
assertEquals(bkc.getLedgers().size(), 0);
}
Aggregations