use of org.apache.bookkeeper.mledger.Position in project pulsar by yahoo.
the class ManagedLedgerErrorsTest method errorInUpdatingLedgersList.
@Test(timeOut = 20000, invocationCount = 1, skipFailedInvocations = true, enabled = false)
public void errorInUpdatingLedgersList() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(1));
final CountDownLatch latch = new CountDownLatch(1);
zkc.failAfter(0, Code.CONNECTIONLOSS);
ledger.asyncAddEntry("entry".getBytes(), new AddEntryCallback() {
public void addFailed(ManagedLedgerException exception, Object ctx) {
// not-ok
}
public void addComplete(Position position, Object ctx) {
// ok
}
}, null);
ledger.asyncAddEntry("entry".getBytes(), new AddEntryCallback() {
public void addFailed(ManagedLedgerException exception, Object ctx) {
latch.countDown();
}
public void addComplete(Position position, Object ctx) {
fail("should have failed");
}
}, null);
latch.await();
}
use of org.apache.bookkeeper.mledger.Position in project pulsar by yahoo.
the class PersistentMessageFinderTest method findMessage.
CompletableFuture<Void> findMessage(final Result result, final ManagedCursor c1, final long timestamp) {
PersistentMessageFinder messageFinder = new PersistentMessageFinder("topicname", c1);
final CompletableFuture<Void> future = new CompletableFuture<>();
messageFinder.findMessages(timestamp, new AsyncCallbacks.FindEntryCallback() {
@Override
public void findEntryComplete(Position position, Object ctx) {
result.position = position;
future.complete(null);
}
@Override
public void findEntryFailed(ManagedLedgerException exception, Object ctx) {
result.exception = exception;
future.completeExceptionally(exception);
}
});
return future;
}
use of org.apache.bookkeeper.mledger.Position in project pulsar by yahoo.
the class PersistentTopicConcurrentTest method setup.
@BeforeMethod
public void setup(Method m) throws Exception {
super.setUp(m);
ServiceConfiguration svcConfig = spy(new ServiceConfiguration());
PulsarService pulsar = spy(new PulsarService(svcConfig));
doReturn(svcConfig).when(pulsar).getConfiguration();
mlFactoryMock = mock(ManagedLedgerFactory.class);
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2));
final ManagedCursor cursor = ledger.openCursor("c1");
cursorMock = cursor;
ledgerMock = ledger;
mlFactoryMock = factory;
doReturn(mlFactoryMock).when(pulsar).getManagedLedgerFactory();
ZooKeeper mockZk = mock(ZooKeeper.class);
doReturn(mockZk).when(pulsar).getZkClient();
brokerService = spy(new BrokerService(pulsar));
doReturn(brokerService).when(pulsar).getBrokerService();
serverCnx = spy(new ServerCnx(brokerService));
doReturn(true).when(serverCnx).isActive();
NamespaceService nsSvc = mock(NamespaceService.class);
doReturn(nsSvc).when(pulsar).getNamespaceService();
doReturn(true).when(nsSvc).isServiceUnitOwned(any(NamespaceBundle.class));
doReturn(true).when(nsSvc).isServiceUnitActive(any(DestinationName.class));
final List<Position> addedEntries = Lists.newArrayList();
for (int i = 0; i < 100; i++) {
Position pos = ledger.addEntry("entry".getBytes());
addedEntries.add(pos);
}
}
use of org.apache.bookkeeper.mledger.Position in project incubator-pulsar by apache.
the class ManagedCursorTest method markDeleteAcrossLedgers.
@Test(timeOut = 20000)
void markDeleteAcrossLedgers() throws Exception {
ManagedLedger ml1 = factory.open("my_test_ledger");
ManagedCursor mc1 = ml1.openCursor("c1");
// open ledger id 3 for ml1
// markDeletePosition for mc1 is 3:-1
// readPosition is 3:0
ml1.close();
mc1.close();
// force removal of this ledger from the cache
factory.close(ml1);
ManagedLedger ml2 = factory.open("my_test_ledger");
ManagedCursor mc2 = ml2.openCursor("c1");
// open ledger id 5 for ml2
// this entry is written at 5:0
Position pos = ml2.addEntry("dummy-entry-1".getBytes(Encoding));
List<Entry> entries = mc2.readEntries(1);
assertEquals(entries.size(), 1);
assertEquals(new String(entries.get(0).getData(), Encoding), "dummy-entry-1");
entries.forEach(e -> e.release());
mc2.delete(pos);
// verify if the markDeletePosition moves from 3:-1 to 5:0
assertEquals(mc2.getMarkDeletedPosition(), pos);
assertEquals(mc2.getMarkDeletedPosition().getNext(), mc2.getReadPosition());
}
use of org.apache.bookkeeper.mledger.Position in project incubator-pulsar by apache.
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();
}
Aggregations