use of org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback in project incubator-pulsar by apache.
the class ManagedLedgerTest method asyncAddEntryWithError.
@Test(timeOut = 20000)
public void asyncAddEntryWithError() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ledger.openCursor("test-cursor");
final CountDownLatch counter = new CountDownLatch(1);
stopBookKeeper();
stopZooKeeper();
ledger.asyncAddEntry("dummy-entry-1".getBytes(Encoding), new AddEntryCallback() {
@Override
public void addComplete(Position position, Object ctx) {
fail("Should have failed");
}
@Override
public void addFailed(ManagedLedgerException exception, Object ctx) {
counter.countDown();
}
}, null);
counter.await();
}
use of org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback in project incubator-pulsar by apache.
the class ManagedLedgerTest method doubleAsyncAddEntryWithoutError.
@Test(timeOut = 20000)
public void doubleAsyncAddEntryWithoutError() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ledger.openCursor("test-cursor");
final CountDownLatch done = new CountDownLatch(10);
for (int i = 0; i < 10; i++) {
final String content = "dummy-entry-" + i;
ledger.asyncAddEntry(content.getBytes(Encoding), new AddEntryCallback() {
@Override
public void addComplete(Position position, Object ctx) {
assertNotNull(ctx);
log.info("Successfully added {}", content);
done.countDown();
}
@Override
public void addFailed(ManagedLedgerException exception, Object ctx) {
fail(exception.getMessage());
}
}, this);
}
done.await();
assertEquals(ledger.getNumberOfEntries(), 10);
}
use of org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback in project incubator-pulsar by apache.
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);
}
use of org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback in project incubator-pulsar by apache.
the class NonDurableCursorTest 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.AsyncCallbacks.AddEntryCallback in project incubator-pulsar by apache.
the class ManagedLedgerBkTest method managedLedgerClosed.
@Test(timeOut = 30000)
public void managedLedgerClosed() throws Exception {
ManagedLedgerFactoryImpl factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ManagedLedgerConfig config = new ManagedLedgerConfig();
config.setEnsembleSize(2).setAckQuorumSize(2).setMetadataEnsembleSize(2);
ManagedLedgerImpl ledger1 = (ManagedLedgerImpl) factory.open("my_test_ledger", config);
int N = 100;
AtomicReference<ManagedLedgerException> res = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(N);
for (int i = 0; i < N; i++) {
ledger1.asyncAddEntry(("entry-" + i).getBytes(), new AddEntryCallback() {
@Override
public void addComplete(Position position, Object ctx) {
latch.countDown();
}
@Override
public void addFailed(ManagedLedgerException exception, Object ctx) {
res.compareAndSet(null, exception);
latch.countDown();
}
}, null);
if (i == 1) {
ledger1.close();
}
}
// Ensures all the callback must have been invoked
latch.await();
assertNotNull(res.get());
assertEquals(res.get().getClass(), ManagedLedgerAlreadyClosedException.class);
factory.shutdown();
}
Aggregations