use of org.apache.bookkeeper.mledger.ManagedLedgerFactory in project pulsar by yahoo.
the class ManagedLedgerBkTest method testSimple.
@Test
public void testSimple() throws Exception {
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, zkc);
ManagedLedgerConfig mlConfig = new ManagedLedgerConfig();
mlConfig.setEnsembleSize(1).setAckQuorumSize(1).setMetadataEnsembleSize(1);
// set the data ledger size
mlConfig.setMaxEntriesPerLedger(100);
// set the metadata ledger size to 1 to kick off many ledger switching cases
mlConfig.setMetadataMaxEntriesPerLedger(2);
ManagedLedger ledger = factory.open("ml-simple-ledger", mlConfig);
ledger.addEntry("test".getBytes());
factory.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedgerFactory in project pulsar by yahoo.
the class ManagedLedgerBkTest method asyncMarkDeleteAndClose.
@Test
public void asyncMarkDeleteAndClose() throws Exception {
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, zkc);
ManagedLedgerConfig config = new ManagedLedgerConfig().setEnsembleSize(1).setWriteQuorumSize(1).setAckQuorumSize(1).setMetadataEnsembleSize(1).setMetadataWriteQuorumSize(1).setMetadataAckQuorumSize(1);
ManagedLedger ledger = factory.open("my_test_ledger", config);
ManagedCursor cursor = ledger.openCursor("c1");
List<Position> positions = Lists.newArrayList();
for (int i = 0; i < 10; i++) {
Position p = ledger.addEntry("entry".getBytes());
positions.add(p);
}
final CountDownLatch counter = new CountDownLatch(positions.size());
final AtomicBoolean gotException = new AtomicBoolean(false);
for (Position p : positions) {
cursor.asyncDelete(p, new DeleteCallback() {
@Override
public void deleteComplete(Object ctx) {
// Ok
counter.countDown();
}
@Override
public void deleteFailed(ManagedLedgerException exception, Object ctx) {
exception.printStackTrace();
gotException.set(true);
counter.countDown();
}
}, null);
}
cursor.close();
ledger.close();
counter.await();
assertFalse(gotException.get());
factory.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedgerFactory in project pulsar by yahoo.
the class ManagedLedgerBkTest method testSimpleRead.
@Test
public void testSimpleRead() throws Exception {
ManagedLedgerFactoryConfig factoryConf = new ManagedLedgerFactoryConfig();
factoryConf.setMaxCacheSize(0);
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, zkc, factoryConf);
ManagedLedgerConfig config = new ManagedLedgerConfig();
config.setEnsembleSize(1).setWriteQuorumSize(1).setAckQuorumSize(1).setMetadataEnsembleSize(1).setMetadataAckQuorumSize(1);
ManagedLedger ledger = factory.open("my-ledger", config);
ManagedCursor cursor = ledger.openCursor("c1");
int N = 1;
for (int i = 0; i < N; i++) {
String entry = "entry-" + i;
ledger.addEntry(entry.getBytes());
}
List<Entry> entries = cursor.readEntries(N);
assertEquals(N, entries.size());
entries.forEach(e -> e.release());
factory.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedgerFactory in project pulsar by yahoo.
the class ManagedCursorTest method testNumberOfEntriesWithReopen.
@Test(timeOut = 20000)
void testNumberOfEntriesWithReopen() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(1));
ManagedCursor c1 = ledger.openCursor("c1");
ledger.addEntry("dummy-entry-1".getBytes(Encoding));
ManagedCursor c2 = ledger.openCursor("c2");
ledger.addEntry("dummy-entry-2".getBytes(Encoding));
ManagedCursor c3 = ledger.openCursor("c3");
ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ledger = factory2.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(1));
c1 = ledger.openCursor("c1");
c2 = ledger.openCursor("c2");
c3 = ledger.openCursor("c3");
assertEquals(c1.getNumberOfEntries(), 2);
assertEquals(c1.hasMoreEntries(), true);
assertEquals(c2.getNumberOfEntries(), 1);
assertEquals(c2.hasMoreEntries(), true);
assertEquals(c3.getNumberOfEntries(), 0);
assertEquals(c3.hasMoreEntries(), false);
factory2.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedgerFactory in project pulsar by yahoo.
the class ManagedLedgerTest method testRetention.
@Test
public void testRetention() throws Exception {
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ManagedLedgerConfig config = new ManagedLedgerConfig();
config.setRetentionSizeInMB(10);
config.setMaxEntriesPerLedger(1);
config.setRetentionTime(1, TimeUnit.HOURS);
ManagedLedgerImpl ml = (ManagedLedgerImpl) factory.open("retention_test_ledger", config);
ManagedCursor c1 = ml.openCursor("c1");
ml.addEntry("iamaverylongmessagethatshouldberetained".getBytes());
c1.skipEntries(1, IndividualDeletedEntries.Exclude);
ml.close();
// reopen ml
ml = (ManagedLedgerImpl) factory.open("retention_test_ledger", config);
c1 = ml.openCursor("c1");
ml.addEntry("shortmessage".getBytes());
c1.skipEntries(1, IndividualDeletedEntries.Exclude);
ml.close();
assertTrue(ml.getLedgersInfoAsList().size() > 1);
assertTrue(ml.getTotalSize() > "shortmessage".getBytes().length);
}
Aggregations