use of org.apache.bookkeeper.mledger.ManagedLedger in project pulsar by yahoo.
the class ManagedCursorTest method testFindNewestMatching.
@Test(timeOut = 20000)
void testFindNewestMatching() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ManagedCursorImpl c1 = (ManagedCursorImpl) ledger.openCursor("c1");
ledger.addEntry("not-expired".getBytes(Encoding));
ledger.addEntry("not-expired".getBytes(Encoding));
ledger.addEntry("not-expired".getBytes(Encoding));
ledger.addEntry("not-expired".getBytes(Encoding));
ledger.addEntry("not-expired".getBytes(Encoding));
assertNull(c1.findNewestMatching(entry -> Arrays.equals(entry.getDataAndRelease(), "expired".getBytes(Encoding))));
}
use of org.apache.bookkeeper.mledger.ManagedLedger 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.ManagedLedger 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);
}
use of org.apache.bookkeeper.mledger.ManagedLedger in project pulsar by yahoo.
the class ManagedCursorTest method testRateLimitMarkDelete.
@Test(timeOut = 20000)
void testRateLimitMarkDelete() throws Exception {
ManagedLedgerConfig config = new ManagedLedgerConfig();
// Throttle to 1/s
config.setThrottleMarkDelete(1);
ManagedLedger ledger = factory.open("my_test_ledger", config);
ManagedCursor c1 = ledger.openCursor("c1");
Position p1 = ledger.addEntry("dummy-entry-1".getBytes(Encoding));
Position p2 = ledger.addEntry("dummy-entry-2".getBytes(Encoding));
Position p3 = ledger.addEntry("dummy-entry-3".getBytes(Encoding));
assertEquals(c1.getNumberOfEntriesInBacklog(), 3);
c1.markDelete(p1);
c1.markDelete(p2);
c1.markDelete(p3);
assertEquals(c1.getNumberOfEntriesInBacklog(), 0);
// Re-open to recover from storage
ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ledger = factory2.open("my_test_ledger", new ManagedLedgerConfig());
c1 = ledger.openCursor("c1");
// Only the 1st mark-delete was persisted
assertEquals(c1.getNumberOfEntriesInBacklog(), 2);
factory2.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedger in project pulsar by yahoo.
the class ManagedCursorTest method errorCreatingCursor.
@Test(timeOut = 20000)
void errorCreatingCursor() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
bkc.failAfter(1, BKException.Code.NotEnoughBookiesException);
try {
ledger.openCursor("c1");
fail("should have failed");
} catch (ManagedLedgerException e) {
// ok
}
}
Aggregations