use of org.apache.bookkeeper.mledger.ManagedLedgerException in project pulsar by yahoo.
the class ManagedCursorTest method testReplayEntries.
@Test(timeOut = 20000)
void testReplayEntries() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ManagedCursorImpl c1 = (ManagedCursorImpl) ledger.openCursor("c1");
PositionImpl p1 = (PositionImpl) ledger.addEntry("entry1".getBytes(Encoding));
PositionImpl p2 = (PositionImpl) ledger.addEntry("entry2".getBytes(Encoding));
PositionImpl p3 = (PositionImpl) ledger.addEntry("entry3".getBytes(Encoding));
ledger.addEntry("entry4".getBytes(Encoding));
// 1. Replay empty position set should return empty entry set
Set<PositionImpl> positions = Sets.newHashSet();
assertTrue(c1.replayEntries(positions).isEmpty());
positions.add(p1);
positions.add(p3);
// 2. entries 1 and 3 should be returned, but they can be in any order
List<Entry> entries = c1.replayEntries(positions);
assertEquals(entries.size(), 2);
assertTrue((Arrays.equals(entries.get(0).getData(), "entry1".getBytes(Encoding)) && Arrays.equals(entries.get(1).getData(), "entry3".getBytes(Encoding))) || (Arrays.equals(entries.get(0).getData(), "entry3".getBytes(Encoding)) && Arrays.equals(entries.get(1).getData(), "entry1".getBytes(Encoding))));
entries.forEach(Entry::release);
// 3. Fail on reading non-existing position
PositionImpl invalidPosition = new PositionImpl(100, 100);
positions.add(invalidPosition);
try {
c1.replayEntries(positions);
fail("Should fail");
} catch (ManagedLedgerException e) {
// ok
}
positions.remove(invalidPosition);
// 4. Fail to attempt to read mark-deleted position (p1)
c1.markDelete(p2);
try {
// as mark-delete is at position: p2 it should read entry : p3
assertEquals(1, c1.replayEntries(positions).size());
} catch (ManagedLedgerException e) {
fail("Should have not failed");
}
}
use of org.apache.bookkeeper.mledger.ManagedLedgerException in project pulsar by yahoo.
the class ManagedLedgerTest method deleteWithErrors2.
@Test(timeOut = 20000)
public void deleteWithErrors2() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ledger.addEntry("dummy-entry-1".getBytes(Encoding));
stopZooKeeper();
try {
ledger.delete();
fail("should have failed");
} catch (ManagedLedgerException e) {
// ok
} catch (RejectedExecutionException e) {
// ok
}
}
use of org.apache.bookkeeper.mledger.ManagedLedgerException in project pulsar by yahoo.
the class ManagedLedgerErrorsTest method asyncClosingManagedLedger.
@Test
public void asyncClosingManagedLedger() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ledger.openCursor("c1");
bkc.failNow(BKException.Code.NoSuchLedgerExistsException);
final CountDownLatch latch = new CountDownLatch(1);
ledger.asyncClose(new CloseCallback() {
public void closeFailed(ManagedLedgerException exception, Object ctx) {
latch.countDown();
}
public void closeComplete(Object ctx) {
fail("should have failed");
}
}, null);
latch.await();
}
use of org.apache.bookkeeper.mledger.ManagedLedgerException in project pulsar by yahoo.
the class ManagedLedgerErrorsTest method removingCursor.
@Test
public void removingCursor() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ManagedCursor c1 = ledger.openCursor("c1");
assertEquals(zkc.exists("/managed-ledgers/my_test_ledger/c1", false) != null, true);
zkc.failNow(Code.BADVERSION);
try {
c1.close();
fail("should fail");
} catch (ManagedLedgerException e) {
// ok
}
bkc.failNow(BKException.Code.NoSuchLedgerExistsException);
// Cursor ledger deletion will fail, but that should not prevent the deleteCursor to fail
ledger.deleteCursor("c1");
assertEquals(zkc.exists("/managed-ledgers/my_test_ledger/c1", false) != null, false);
assertEquals(bkc.getLedgers().size(), 2);
}
use of org.apache.bookkeeper.mledger.ManagedLedgerException 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();
}
Aggregations