use of org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback in project pulsar by yahoo.
the class ManagedCursorTest method testReadEntriesOrWait.
@Test(timeOut = 10000)
void testReadEntriesOrWait() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
final int Consumers = 10;
final CountDownLatch counter = new CountDownLatch(Consumers);
for (int i = 0; i < Consumers; i++) {
ManagedCursor c = ledger.openCursor("c" + i);
c.asyncReadEntriesOrWait(1, new ReadEntriesCallback() {
public void readEntriesComplete(List<Entry> entries, Object ctx) {
assertEquals(entries.size(), 1);
entries.forEach(e -> e.release());
counter.countDown();
}
public void readEntriesFailed(ManagedLedgerException exception, Object ctx) {
log.error("Error reading", exception);
}
}, null);
}
ledger.addEntry("test".getBytes());
counter.await();
}
use of org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback in project pulsar by yahoo.
the class ManagedCursorTest method asyncReadWithInvalidParameter.
@Test(timeOut = 20000, expectedExceptions = IllegalArgumentException.class)
void asyncReadWithInvalidParameter() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ManagedCursor cursor = ledger.openCursor("c1");
ledger.addEntry("dummy-entry-1".getBytes(Encoding));
final CountDownLatch counter = new CountDownLatch(1);
stopBookKeeper();
cursor.asyncReadEntries(0, new ReadEntriesCallback() {
public void readEntriesComplete(List<Entry> entries, Object ctx) {
fail("async-call should have failed");
}
public void readEntriesFailed(ManagedLedgerException exception, Object ctx) {
counter.countDown();
}
}, null);
counter.await();
}
use of org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback in project pulsar by yahoo.
the class ManagedCursorImpl method replayEntries.
@Override
public List<Entry> replayEntries(Set<? extends Position> positions) throws InterruptedException, ManagedLedgerException {
final CountDownLatch counter = new CountDownLatch(1);
class Result {
ManagedLedgerException exception = null;
List<Entry> entries = null;
}
final Result result = new Result();
asyncReplayEntries(positions, new ReadEntriesCallback() {
@Override
public void readEntriesComplete(List<Entry> entries, Object ctx) {
result.entries = entries;
counter.countDown();
}
@Override
public void readEntriesFailed(ManagedLedgerException exception, Object ctx) {
result.exception = exception;
counter.countDown();
}
}, null);
counter.await();
if (result.exception != null)
throw result.exception;
return result.entries;
}
use of org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback in project pulsar by yahoo.
the class ManagedCursorImpl method readEntries.
@Override
public List<Entry> readEntries(int numberOfEntriesToRead) throws InterruptedException, ManagedLedgerException {
checkArgument(numberOfEntriesToRead > 0);
final CountDownLatch counter = new CountDownLatch(1);
class Result {
ManagedLedgerException exception = null;
List<Entry> entries = null;
}
final Result result = new Result();
asyncReadEntries(numberOfEntriesToRead, new ReadEntriesCallback() {
@Override
public void readEntriesComplete(List<Entry> entries, Object ctx) {
result.entries = entries;
counter.countDown();
}
@Override
public void readEntriesFailed(ManagedLedgerException exception, Object ctx) {
result.exception = exception;
counter.countDown();
}
}, null);
counter.await();
if (result.exception != null)
throw result.exception;
return result.entries;
}
use of org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback in project pulsar by yahoo.
the class ManagedCursorImpl method readEntriesOrWait.
@Override
public List<Entry> readEntriesOrWait(int numberOfEntriesToRead) throws InterruptedException, ManagedLedgerException {
checkArgument(numberOfEntriesToRead > 0);
final CountDownLatch counter = new CountDownLatch(1);
class Result {
ManagedLedgerException exception = null;
List<Entry> entries = null;
}
final Result result = new Result();
asyncReadEntriesOrWait(numberOfEntriesToRead, new ReadEntriesCallback() {
@Override
public void readEntriesComplete(List<Entry> entries, Object ctx) {
result.entries = entries;
counter.countDown();
}
@Override
public void readEntriesFailed(ManagedLedgerException exception, Object ctx) {
result.exception = exception;
counter.countDown();
}
}, null);
counter.await();
if (result.exception != null)
throw result.exception;
return result.entries;
}
Aggregations