use of org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig in project pulsar by yahoo.
the class MockedBookKeeperTestCase method setUp.
@BeforeMethod
public void setUp(Method method) throws Exception {
LOG.info(">>>>>> starting {}", method);
try {
// start bookkeeper service
startBookKeeper();
} catch (Exception e) {
LOG.error("Error setting up", e);
throw e;
}
executor = new OrderedSafeExecutor(2, "test");
cachedExecutor = Executors.newCachedThreadPool();
ManagedLedgerFactoryConfig conf = new ManagedLedgerFactoryConfig();
conf.setUseProtobufBinaryFormatInZK(protobufFormat == ZNodeProtobufFormat.Binary);
factory = new ManagedLedgerFactoryImpl(bkc, zkc, conf);
}
use of org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig in project pulsar by yahoo.
the class ManagedCursorTest method readWithCacheDisabled.
@Test(timeOut = 20000)
void readWithCacheDisabled() throws Exception {
ManagedLedgerFactoryConfig config = new ManagedLedgerFactoryConfig();
config.setMaxCacheSize(0);
factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle(), config);
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(1));
ManagedCursor c1 = ledger.openCursor("c1");
ManagedCursor c2 = ledger.openCursor("c2");
ledger.addEntry("entry-1".getBytes(Encoding));
ledger.addEntry("entry-2".getBytes(Encoding));
List<Entry> entries = c1.readEntries(2);
assertEquals(entries.size(), 2);
assertEquals(new String(entries.get(0).getData(), Encoding), "entry-1");
assertEquals(new String(entries.get(1).getData(), Encoding), "entry-2");
entries.forEach(e -> e.release());
entries = c1.readEntries(2);
assertEquals(entries.size(), 0);
entries.forEach(e -> e.release());
entries = c2.readEntries(2);
assertEquals(entries.size(), 2);
entries.forEach(e -> e.release());
entries = c2.readEntries(2);
assertEquals(entries.size(), 0);
entries.forEach(e -> e.release());
}
use of org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig in project pulsar by yahoo.
the class ManagedLedgerBinaryFormatConversion method textToBinary.
@Test(timeOut = 20000, dataProvider = "gracefulClose")
void textToBinary(boolean gracefulClose) throws Exception {
ManagedLedgerFactoryConfig textConf = new ManagedLedgerFactoryConfig();
textConf.setUseProtobufBinaryFormatInZK(false);
ManagedLedgerFactory textFactory = new ManagedLedgerFactoryImpl(bkc, zkc, textConf);
ManagedLedger ledger = textFactory.open("my_test_ledger");
ManagedCursor c1 = ledger.openCursor("c1");
ledger.addEntry("test-0".getBytes(Encoding));
Position p1 = ledger.addEntry("test-1".getBytes(Encoding));
ledger.addEntry("test-2".getBytes(Encoding));
c1.delete(p1);
if (gracefulClose) {
ledger.close();
}
// Reopen with binary format
ManagedLedgerFactoryConfig binaryConf = new ManagedLedgerFactoryConfig();
binaryConf.setUseProtobufBinaryFormatInZK(true);
ManagedLedgerFactory binaryFactory = new ManagedLedgerFactoryImpl(bkc, zkc, binaryConf);
ledger = binaryFactory.open("my_test_ledger");
c1 = ledger.openCursor("c1");
// The 'p1' entry was already deleted
assertEquals(c1.getNumberOfEntriesInBacklog(), 2);
textFactory.shutdown();
binaryFactory.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig in project pulsar by yahoo.
the class ManagedLedgerBinaryFormatConversion method binaryToText.
@Test(timeOut = 20000, dataProvider = "gracefulClose")
void binaryToText(boolean gracefulClose) throws Exception {
ManagedLedgerFactoryConfig binaryConf = new ManagedLedgerFactoryConfig();
binaryConf.setUseProtobufBinaryFormatInZK(true);
ManagedLedgerFactory binaryFactory = new ManagedLedgerFactoryImpl(bkc, zkc, binaryConf);
ManagedLedger ledger = binaryFactory.open("my_test_ledger");
ManagedCursor c1 = ledger.openCursor("c1");
ledger.addEntry("test-0".getBytes(Encoding));
Position p1 = ledger.addEntry("test-1".getBytes(Encoding));
ledger.addEntry("test-2".getBytes(Encoding));
c1.delete(p1);
if (gracefulClose) {
ledger.close();
}
// Reopen with binary format
ManagedLedgerFactoryConfig textConf = new ManagedLedgerFactoryConfig();
textConf.setUseProtobufBinaryFormatInZK(false);
ManagedLedgerFactory textFactory = new ManagedLedgerFactoryImpl(bkc, zkc, textConf);
ledger = textFactory.open("my_test_ledger");
c1 = ledger.openCursor("c1");
// The 'p1' entry was already deleted
assertEquals(c1.getNumberOfEntriesInBacklog(), 2);
textFactory.shutdown();
binaryFactory.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig 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();
}
Aggregations