use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class ManagedLedgerTest method testAsyncAddEntryAndSyncClose.
@Test(timeOut = 20000)
public void testAsyncAddEntryAndSyncClose() throws Exception {
ManagedLedgerConfig config = new ManagedLedgerConfig().setMaxEntriesPerLedger(10);
ManagedLedger ledger = factory.open("my_test_ledger", config);
ledger.openCursor("c1");
assertEquals(ledger.getNumberOfEntries(), 0);
final CountDownLatch counter = new CountDownLatch(100);
for (int i = 0; i < 100; i++) {
String content = "entry-" + i;
ledger.asyncAddEntry(content.getBytes(Encoding), new AddEntryCallback() {
@Override
public void addComplete(Position position, Object ctx) {
counter.countDown();
}
@Override
public void addFailed(ManagedLedgerException exception, Object ctx) {
fail(exception.getMessage());
}
}, null);
}
counter.await();
assertEquals(ledger.getNumberOfEntries(), 100);
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class ManagedLedgerTest method testMinimumRolloverTime.
@Test
public void testMinimumRolloverTime() throws Exception {
ManagedLedgerConfig conf = new ManagedLedgerConfig();
conf.setMaxEntriesPerLedger(1);
conf.setMinimumRolloverTime(1, TimeUnit.SECONDS);
ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("my_test_ledger", conf);
ledger.openCursor("c1");
ledger.addEntry("data".getBytes());
ledger.addEntry("data".getBytes());
assertEquals(ledger.getLedgersInfoAsList().size(), 1);
Thread.sleep(1000);
ledger.addEntry("data".getBytes());
ledger.addEntry("data".getBytes());
assertEquals(ledger.getLedgersInfoAsList().size(), 2);
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class ManagedLedgerTest method previousPosition.
@Test
public void previousPosition() throws Exception {
ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2));
ManagedCursor cursor = ledger.openCursor("my_cursor");
Position p0 = cursor.getMarkDeletedPosition();
// This is expected because p0 is already an "invalid" position (since no entry has been mark-deleted yet)
assertEquals(ledger.getPreviousPosition((PositionImpl) p0), p0);
// Force to close an empty ledger
ledger.close();
ledger = (ManagedLedgerImpl) factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2));
// again
ledger.close();
ledger = (ManagedLedgerImpl) factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2));
PositionImpl pBeforeWriting = ledger.getLastPosition();
PositionImpl p1 = (PositionImpl) ledger.addEntry("entry".getBytes());
ledger.close();
ledger = (ManagedLedgerImpl) factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2));
Position p2 = ledger.addEntry("entry".getBytes());
Position p3 = ledger.addEntry("entry".getBytes());
Position p4 = ledger.addEntry("entry".getBytes());
assertEquals(ledger.getPreviousPosition(p1), pBeforeWriting);
assertEquals(ledger.getPreviousPosition((PositionImpl) p2), p1);
assertEquals(ledger.getPreviousPosition((PositionImpl) p3), p2);
assertEquals(ledger.getPreviousPosition((PositionImpl) p4), p3);
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class ManagedLedgerTest method forceCloseLedgers.
@Test
public void forceCloseLedgers() throws Exception {
ManagedLedger ledger1 = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(1));
ledger1.openCursor("c1");
ManagedCursor c2 = ledger1.openCursor("c2");
ledger1.addEntry("entry-1".getBytes(Encoding));
ledger1.addEntry("entry-2".getBytes(Encoding));
ledger1.addEntry("entry-3".getBytes(Encoding));
c2.readEntries(1).forEach(e -> e.release());
c2.readEntries(1).forEach(e -> e.release());
c2.readEntries(1).forEach(e -> e.release());
ledger1.close();
try {
ledger1.addEntry("entry-3".getBytes(Encoding));
fail("should not have reached this point");
} catch (ManagedLedgerException e) {
// ok
}
try {
ledger1.openCursor("new-cursor");
fail("should not have reached this point");
} catch (ManagedLedgerException e) {
// ok
}
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class ManagedLedgerTest method testTimestampOnWorkingLedger.
@Test
public void testTimestampOnWorkingLedger() throws Exception {
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ManagedLedgerConfig conf = new ManagedLedgerConfig();
conf.setMaxEntriesPerLedger(1);
conf.setRetentionSizeInMB(10);
conf.setRetentionTime(1, TimeUnit.HOURS);
ManagedLedgerImpl ml = (ManagedLedgerImpl) factory.open("my_test_ledger", conf);
ml.openCursor("c1");
ml.addEntry("msg1".getBytes());
Iterator<LedgerInfo> iter = ml.getLedgersInfoAsList().iterator();
long ts = -1;
while (iter.hasNext()) {
LedgerInfo i = iter.next();
if (iter.hasNext()) {
assertTrue(ts <= i.getTimestamp(), i.toString());
ts = i.getTimestamp();
} else {
// the last timestamp can be
// 0 if it is still opened
// >0 if it is closed after the addEntry see OpAddEntry#addComplete()
assertTrue(i.getTimestamp() == 0 || ts <= i.getTimestamp(), i.toString());
}
}
ml.addEntry("msg02".getBytes());
ml.close();
// Thread.sleep(1000);
iter = ml.getLedgersInfoAsList().iterator();
ts = -1;
while (iter.hasNext()) {
LedgerInfo i = iter.next();
if (iter.hasNext()) {
assertTrue(ts <= i.getTimestamp(), i.toString());
ts = i.getTimestamp();
} else {
assertTrue(i.getTimestamp() > 0, "well closed LedgerInfo should set a timestamp > 0");
}
}
}
Aggregations