use of org.apache.bookkeeper.mledger.ReadOnlyCursor in project incubator-pulsar by apache.
the class ManagedLedgerFactoryShutdownTest method openEncounteredShutdown.
@Test(timeOut = 5000)
public void openEncounteredShutdown() throws Exception {
ManagedLedgerFactoryImpl factory = new ManagedLedgerFactoryImpl(metadataStore, bookKeeper);
CountDownLatch callbackInvoked = new CountDownLatch(2);
factory.asyncOpen(ledgerName, new AsyncCallbacks.OpenLedgerCallback() {
@Override
public void openLedgerComplete(ManagedLedger ledger, Object ctx) {
callbackInvoked.countDown();
}
@Override
public void openLedgerFailed(ManagedLedgerException exception, Object ctx) {
callbackInvoked.countDown();
}
}, null);
factory.asyncOpenReadOnlyCursor(ledgerName, PositionImpl.EARLIEST, new ManagedLedgerConfig(), new AsyncCallbacks.OpenReadOnlyCursorCallback() {
@Override
public void openReadOnlyCursorComplete(ReadOnlyCursor cursor, Object ctx) {
callbackInvoked.countDown();
}
@Override
public void openReadOnlyCursorFailed(ManagedLedgerException exception, Object ctx) {
log.info("openReadOnlyCursorFailed");
callbackInvoked.countDown();
}
}, null);
log.info("Shutdown factory...");
factory.shutdownAsync().get();
// make zk returned after factory shutdown
slowZk.countDown();
//
Assert.assertTrue(callbackInvoked.await(5, TimeUnit.SECONDS));
// ManagedLedgerFactoryClosedException should be thrown after factory is shutdown
Assert.assertThrows(ManagedLedgerException.ManagedLedgerFactoryClosedException.class, () -> factory.open(ledgerName));
Assert.assertThrows(ManagedLedgerException.ManagedLedgerFactoryClosedException.class, () -> factory.openReadOnlyCursor(ledgerName, PositionImpl.EARLIEST, new ManagedLedgerConfig()));
}
use of org.apache.bookkeeper.mledger.ReadOnlyCursor in project incubator-pulsar by apache.
the class ReadOnlyCursorTest method skipMultiple.
@Test
void skipMultiple() throws Exception {
ManagedLedger ledger = factory.open("skip", new ManagedLedgerConfig().setMaxEntriesPerLedger(7).setRetentionTime(1, TimeUnit.HOURS).setRetentionSizeInMB(-1));
int N = 30;
for (int i = 0; i < N; i++) {
ledger.addEntry(("entry-" + i).getBytes());
}
ReadOnlyCursor cursor = factory.openReadOnlyCursor("skip", PositionImpl.EARLIEST, new ManagedLedgerConfig());
assertEquals(cursor.getNumberOfEntries(), N);
assertTrue(cursor.hasMoreEntries());
cursor.skipEntries(25);
assertEquals(cursor.getNumberOfEntries(), 5);
assertTrue(cursor.hasMoreEntries());
cursor.skipEntries(5);
assertEquals(cursor.getNumberOfEntries(), 0);
assertFalse(cursor.hasMoreEntries());
cursor.close();
}
use of org.apache.bookkeeper.mledger.ReadOnlyCursor in project incubator-pulsar by apache.
the class ReadOnlyCursorTest method skip.
@Test
void skip() throws Exception {
ManagedLedger ledger = factory.open("skip", new ManagedLedgerConfig().setMaxEntriesPerLedger(2).setRetentionTime(1, TimeUnit.HOURS).setRetentionSizeInMB(-1));
int N = 10;
for (int i = 0; i < N; i++) {
ledger.addEntry(("entry-" + i).getBytes());
}
ReadOnlyCursor cursor = factory.openReadOnlyCursor("skip", PositionImpl.EARLIEST, new ManagedLedgerConfig());
assertEquals(cursor.getNumberOfEntries(), N);
assertTrue(cursor.hasMoreEntries());
cursor.skipEntries(5);
assertEquals(cursor.getNumberOfEntries(), N - 5);
assertTrue(cursor.hasMoreEntries());
cursor.close();
}
use of org.apache.bookkeeper.mledger.ReadOnlyCursor in project pulsar by yahoo.
the class ManagedLedgerFactoryImpl method openReadOnlyCursor.
@Override
public ReadOnlyCursor openReadOnlyCursor(String managedLedgerName, Position startPosition, ManagedLedgerConfig config) throws InterruptedException, ManagedLedgerException {
class Result {
ReadOnlyCursor c = null;
ManagedLedgerException e = null;
}
final Result r = new Result();
final CountDownLatch latch = new CountDownLatch(1);
asyncOpenReadOnlyCursor(managedLedgerName, startPosition, config, new OpenReadOnlyCursorCallback() {
@Override
public void openReadOnlyCursorComplete(ReadOnlyCursor cursor, Object ctx) {
r.c = cursor;
latch.countDown();
}
@Override
public void openReadOnlyCursorFailed(ManagedLedgerException exception, Object ctx) {
r.e = exception;
latch.countDown();
}
}, null);
latch.await();
if (r.e != null) {
throw r.e;
}
return r.c;
}
use of org.apache.bookkeeper.mledger.ReadOnlyCursor in project pulsar by yahoo.
the class ReadOnlyCursorTest method skipMultiple.
@Test
void skipMultiple() throws Exception {
ManagedLedger ledger = factory.open("skip", new ManagedLedgerConfig().setMaxEntriesPerLedger(7).setRetentionTime(1, TimeUnit.HOURS).setRetentionSizeInMB(-1));
int N = 30;
for (int i = 0; i < N; i++) {
ledger.addEntry(("entry-" + i).getBytes());
}
ReadOnlyCursor cursor = factory.openReadOnlyCursor("skip", PositionImpl.EARLIEST, new ManagedLedgerConfig());
assertEquals(cursor.getNumberOfEntries(), N);
assertTrue(cursor.hasMoreEntries());
cursor.skipEntries(25);
assertEquals(cursor.getNumberOfEntries(), 5);
assertTrue(cursor.hasMoreEntries());
cursor.skipEntries(5);
assertEquals(cursor.getNumberOfEntries(), 0);
assertFalse(cursor.hasMoreEntries());
cursor.close();
}
Aggregations