use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class ManagedLedgerTest method testProducerAndNoConsumer.
@Test(timeOut = 20000)
public void testProducerAndNoConsumer() throws Exception {
ManagedLedgerConfig config = new ManagedLedgerConfig().setMaxEntriesPerLedger(1);
ManagedLedger ledger = factory.open("my_test_ledger", config);
assertEquals(ledger.getNumberOfEntries(), 0);
ledger.addEntry("entry-1".getBytes(Encoding));
assertEquals(ledger.getNumberOfEntries(), 1);
// Since there are no consumers, older ledger will be deleted
// in a short time (in a background thread)
ledger.addEntry("entry-2".getBytes(Encoding));
while (ledger.getNumberOfEntries() > 1) {
log.debug("entries={}", ledger.getNumberOfEntries());
Thread.sleep(100);
}
ledger.addEntry("entry-3".getBytes(Encoding));
while (ledger.getNumberOfEntries() > 1) {
log.debug("entries={}", ledger.getNumberOfEntries());
Thread.sleep(100);
}
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class ManagedLedgerTest method totalSizeTest.
@Test
public void totalSizeTest() throws Exception {
ManagedLedgerConfig conf = new ManagedLedgerConfig();
conf.setMaxEntriesPerLedger(1);
ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("my_test_ledger", conf);
ManagedCursor c1 = ledger.openCursor("c1");
ledger.addEntry(new byte[10], 1, 8);
assertEquals(ledger.getTotalSize(), 8);
PositionImpl p2 = (PositionImpl) ledger.addEntry(new byte[12], 2, 5);
assertEquals(ledger.getTotalSize(), 13);
c1.markDelete(new PositionImpl(p2.getLedgerId(), -1));
// Wait for background trimming
Thread.sleep(400);
assertEquals(ledger.getTotalSize(), 5);
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class ManagedLedgerTest method moveCursorToNextLedger.
@Test(timeOut = 20000)
public void moveCursorToNextLedger() 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));
log.debug("Added 1st message");
List<Entry> entries = cursor.readEntries(1);
log.debug("read message ok");
assertEquals(entries.size(), 1);
entries.forEach(e -> e.release());
ledger.addEntry("entry-2".getBytes(Encoding));
log.debug("Added 2nd message");
ledger.addEntry("entry-3".getBytes(Encoding));
log.debug("Added 3nd message");
assertEquals(cursor.hasMoreEntries(), true);
assertEquals(cursor.getNumberOfEntries(), 2);
entries = cursor.readEntries(2);
assertEquals(entries.size(), 2);
entries.forEach(e -> e.release());
entries = cursor.readEntries(2);
assertEquals(entries.size(), 0);
entries = cursor.readEntries(2);
assertEquals(entries.size(), 0);
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class ManagedLedgerTest method readFromOlderLedgers.
@Test(timeOut = 20000)
public void readFromOlderLedgers() 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);
cursor.readEntries(1).forEach(e -> e.release());
assertEquals(cursor.hasMoreEntries(), true);
cursor.readEntries(1).forEach(e -> e.release());
assertEquals(cursor.hasMoreEntries(), true);
cursor.readEntries(1).forEach(e -> e.release());
assertEquals(cursor.hasMoreEntries(), false);
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class ManagedLedgerTest method testMaximumRolloverTime.
@Test
public void testMaximumRolloverTime() throws Exception {
ManagedLedgerConfig conf = new ManagedLedgerConfig();
conf.setMaxEntriesPerLedger(5);
conf.setMinimumRolloverTime(1, TimeUnit.SECONDS);
conf.setMaximumRolloverTime(1, TimeUnit.SECONDS);
ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("my_test_maxtime_ledger", conf);
ledger.openCursor("c1");
ledger.addEntry("data".getBytes());
ledger.addEntry("data".getBytes());
assertEquals(ledger.getLedgersInfoAsList().size(), 1);
Thread.sleep(2000);
ledger.addEntry("data".getBytes());
ledger.addEntry("data".getBytes());
assertEquals(ledger.getLedgersInfoAsList().size(), 2);
}
Aggregations