use of org.apache.bookkeeper.mledger.ManagedLedger in project pulsar by yahoo.
the class ManagedLedgerTest method fenceManagedLedger.
@Test(enabled = false)
public void fenceManagedLedger() throws Exception {
ManagedLedgerFactory factory1 = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ManagedLedger ledger1 = factory1.open("my_test_ledger");
ManagedCursor cursor1 = ledger1.openCursor("c1");
ledger1.addEntry("entry-1".getBytes(Encoding));
ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ManagedLedger ledger2 = factory2.open("my_test_ledger");
ManagedCursor cursor2 = ledger2.openCursor("c1");
// At this point ledger1 must have been fenced
try {
ledger1.addEntry("entry-1".getBytes(Encoding));
fail("Expecting exception");
} catch (ManagedLedgerFencedException e) {
}
try {
ledger1.addEntry("entry-2".getBytes(Encoding));
fail("Expecting exception");
} catch (ManagedLedgerFencedException e) {
}
try {
cursor1.readEntries(10);
fail("Expecting exception");
} catch (ManagedLedgerFencedException e) {
}
try {
ledger1.openCursor("new cursor");
fail("Expecting exception");
} catch (ManagedLedgerFencedException e) {
}
ledger2.addEntry("entry-2".getBytes(Encoding));
assertEquals(cursor2.getNumberOfEntries(), 2);
factory1.shutdown();
factory2.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedger in project pulsar by yahoo.
the class ManagedLedgerTest method triggerLedgerDeletion.
@Test(timeOut = 20000)
public void triggerLedgerDeletion() throws Exception {
ManagedLedgerConfig config = new ManagedLedgerConfig().setMaxEntriesPerLedger(1);
ManagedLedger ledger = factory.open("my_test_ledger", config);
ManagedCursor cursor = ledger.openCursor("test");
ledger.addEntry("entry-1".getBytes(Encoding));
ledger.addEntry("entry-2".getBytes(Encoding));
ledger.addEntry("entry-3".getBytes(Encoding));
assertEquals(cursor.hasMoreEntries(), true);
List<Entry> entries = cursor.readEntries(1);
assertEquals(entries.size(), 1);
assertEquals(ledger.getNumberOfEntries(), 3);
entries.forEach(e -> e.release());
assertEquals(cursor.hasMoreEntries(), true);
entries = cursor.readEntries(1);
assertEquals(cursor.hasMoreEntries(), true);
cursor.markDelete(entries.get(0).getPosition());
entries.forEach(e -> e.release());
}
use of org.apache.bookkeeper.mledger.ManagedLedger in project pulsar by yahoo.
the class ManagedLedgerTest method testEmptyManagedLedgerContent.
@Test(timeOut = 20000)
public void testEmptyManagedLedgerContent() throws Exception {
ZooKeeper zk = bkc.getZkHandle();
zk.create("/managed-ledger", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create("/managed-ledger/my_test_ledger", " ".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
ManagedLedger ledger = factory.open("my_test_ledger");
ledger.openCursor("test");
ledger.addEntry("entry-1".getBytes(Encoding));
assertEquals(ledger.getNumberOfEntries(), 1);
}
use of org.apache.bookkeeper.mledger.ManagedLedger in project pulsar by yahoo.
the class ManagedLedgerTest method acknowledge1.
@Test(timeOut = 20000)
public void acknowledge1() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ManagedCursor cursor = ledger.openCursor("c1");
ledger.addEntry("dummy-entry-1".getBytes(Encoding));
ledger.addEntry("dummy-entry-2".getBytes(Encoding));
assertEquals(cursor.hasMoreEntries(), true);
List<Entry> entries = cursor.readEntries(2);
assertEquals(entries.size(), 2);
entries.forEach(e -> e.release());
assertEquals(cursor.getNumberOfEntries(), 0);
assertEquals(cursor.getNumberOfEntriesInBacklog(), 2);
assertEquals(cursor.hasMoreEntries(), false);
assertEquals(ledger.getNumberOfEntries(), 2);
assertEquals(ledger.getNumberOfActiveEntries(), 2);
cursor.markDelete(entries.get(0).getPosition());
assertEquals(cursor.getNumberOfEntries(), 0);
assertEquals(cursor.getNumberOfEntriesInBacklog(), 1);
assertEquals(cursor.hasMoreEntries(), false);
assertEquals(ledger.getNumberOfActiveEntries(), 1);
ledger.close();
// / Reopen the same managed-ledger
ledger = factory.open("my_test_ledger");
cursor = ledger.openCursor("c1");
assertEquals(ledger.getNumberOfEntries(), 2);
assertEquals(ledger.getTotalSize(), "dummy-entry-1".getBytes(Encoding).length * 2);
assertEquals(cursor.getNumberOfEntries(), 1);
assertEquals(cursor.getNumberOfEntriesInBacklog(), 1);
assertEquals(cursor.hasMoreEntries(), true);
entries = cursor.readEntries(100);
assertEquals(entries.size(), 1);
entries.forEach(e -> e.release());
ledger.close();
}
use of org.apache.bookkeeper.mledger.ManagedLedger 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
}
}
Aggregations