use of org.apache.bookkeeper.mledger.ManagedLedgerException in project pulsar by yahoo.
the class ManagedLedgerTest method readWithErrors1.
@Test(timeOut = 20000)
public void readWithErrors1() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(1));
ManagedCursor cursor = ledger.openCursor("c1");
ledger.addEntry("dummy-entry-1".getBytes(Encoding));
ledger.addEntry("dummy-entry-2".getBytes(Encoding));
stopZooKeeper();
stopBookKeeper();
try {
cursor.readEntries(10);
fail("should have failed");
} catch (ManagedLedgerException e) {
// ok
}
try {
ledger.addEntry("dummy-entry-3".getBytes(Encoding));
fail("should have failed");
} catch (ManagedLedgerException e) {
// ok
}
}
use of org.apache.bookkeeper.mledger.ManagedLedgerException in project pulsar by yahoo.
the class ManagedLedgerTest method testConcurrentOpenCursor.
@Test
public void testConcurrentOpenCursor() throws Exception {
ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("testConcurrentOpenCursor");
final AtomicReference<ManagedCursor> cursor1 = new AtomicReference<>(null);
final AtomicReference<ManagedCursor> cursor2 = new AtomicReference<>(null);
final CyclicBarrier barrier = new CyclicBarrier(2);
final CountDownLatch latch = new CountDownLatch(2);
cachedExecutor.execute(() -> {
try {
barrier.await();
} catch (Exception e) {
}
ledger.asyncOpenCursor("c1", new OpenCursorCallback() {
@Override
public void openCursorFailed(ManagedLedgerException exception, Object ctx) {
latch.countDown();
}
@Override
public void openCursorComplete(ManagedCursor cursor, Object ctx) {
cursor1.set(cursor);
latch.countDown();
}
}, null);
});
cachedExecutor.execute(() -> {
try {
barrier.await();
} catch (Exception e) {
}
ledger.asyncOpenCursor("c1", new OpenCursorCallback() {
@Override
public void openCursorFailed(ManagedLedgerException exception, Object ctx) {
latch.countDown();
}
@Override
public void openCursorComplete(ManagedCursor cursor, Object ctx) {
cursor2.set(cursor);
latch.countDown();
}
}, null);
});
latch.await();
assertNotNull(cursor1.get());
assertNotNull(cursor2.get());
assertEquals(cursor1.get(), cursor2.get());
ledger.close();
}
use of org.apache.bookkeeper.mledger.ManagedLedgerException in project pulsar by yahoo.
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.ManagedLedgerException in project pulsar by yahoo.
the class ManagedLedgerTest method asyncCloseWithoutError.
@Test(timeOut = 20000)
public void asyncCloseWithoutError() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ledger.openCursor("test-cursor");
ledger.addEntry("dummy-entry-1".getBytes(Encoding));
final CountDownLatch counter = new CountDownLatch(1);
ledger.asyncClose(new CloseCallback() {
@Override
public void closeComplete(Object ctx) {
assertNull(ctx);
counter.countDown();
}
@Override
public void closeFailed(ManagedLedgerException exception, Object ctx) {
fail(exception.getMessage());
}
}, null);
counter.await();
}
use of org.apache.bookkeeper.mledger.ManagedLedgerException in project pulsar by yahoo.
the class ManagedLedgerTest method closeLedgerWithError.
@Test
public void closeLedgerWithError() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ledger.addEntry("entry-1".getBytes(Encoding));
stopZooKeeper();
stopBookKeeper();
try {
ledger.close();
// fail("should have thrown exception");
} catch (ManagedLedgerException e) {
// Ok
}
}
Aggregations