use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project pulsar by yahoo.
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 pulsar by yahoo.
the class ManagedLedgerTest method testGetNextValidPosition.
@Test
public void testGetNextValidPosition() throws Exception {
ManagedLedgerConfig conf = new ManagedLedgerConfig();
conf.setMaxEntriesPerLedger(1);
ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("testGetNextValidPosition", conf);
ManagedCursor c1 = ledger.openCursor("c1");
PositionImpl p1 = (PositionImpl) ledger.addEntry("entry1".getBytes());
PositionImpl p2 = (PositionImpl) ledger.addEntry("entry2".getBytes());
PositionImpl p3 = (PositionImpl) ledger.addEntry("entry3".getBytes());
assertEquals(ledger.getNextValidPosition((PositionImpl) c1.getMarkDeletedPosition()), p1);
assertEquals(ledger.getNextValidPosition(p1), p2);
assertEquals(ledger.getNextValidPosition(p3), PositionImpl.get(p3.getLedgerId(), p3.getEntryId() + 1));
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project pulsar by yahoo.
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);
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project pulsar by yahoo.
the class ManagedCursorTest method testFindNewestMatchingAllEntriesSingleLedger.
@Test(timeOut = 20000)
void testFindNewestMatchingAllEntriesSingleLedger() throws Exception {
final String ledgerAndCursorName = "testFindNewestMatchingAllEntriesSingleLedger";
ManagedLedgerConfig config = new ManagedLedgerConfig();
// needs to be changed if entries per ledger is changed
int expectedEntryId = 3;
int entriesPerLedger = config.getMaxEntriesPerLedger();
internalTestFindNewestMatchingAllEntries(ledgerAndCursorName, entriesPerLedger, expectedEntryId);
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project pulsar by yahoo.
the class ManagedCursorTest method seekPosition.
@Test(timeOut = 20000)
void seekPosition() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(10));
ManagedCursor cursor = ledger.openCursor("c1");
ledger.addEntry("dummy-entry-1".getBytes(Encoding));
ledger.addEntry("dummy-entry-2".getBytes(Encoding));
ledger.addEntry("dummy-entry-3".getBytes(Encoding));
PositionImpl lastPosition = (PositionImpl) ledger.addEntry("dummy-entry-4".getBytes(Encoding));
cursor.seek(new PositionImpl(lastPosition.getLedgerId(), lastPosition.getEntryId() - 1));
}
Aggregations