Search in sources :

Example 6 with ManagedLedgerFactoryConfig

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);
}
Also used : ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) OrderedSafeExecutor(org.apache.bookkeeper.util.OrderedSafeExecutor) ManagedLedgerFactoryImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with ManagedLedgerFactoryConfig

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());
}
Also used : Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 8 with ManagedLedgerFactoryConfig

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();
}
Also used : ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) Position(org.apache.bookkeeper.mledger.Position) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 9 with ManagedLedgerFactoryConfig

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();
}
Also used : ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) Position(org.apache.bookkeeper.mledger.Position) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 10 with ManagedLedgerFactoryConfig

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();
}
Also used : Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Aggregations

ManagedLedgerFactoryConfig (org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig)13 Test (org.testng.annotations.Test)12 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)7 Entry (org.apache.bookkeeper.mledger.Entry)6 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)6 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)5 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)4 Position (org.apache.bookkeeper.mledger.Position)4 PersistentOfflineTopicStats (com.yahoo.pulsar.common.policies.data.PersistentOfflineTopicStats)2 Charsets (com.google.common.base.Charsets)1 Lists (com.google.common.collect.Lists)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 DigestType (org.apache.bookkeeper.client.BookKeeper.DigestType)1 BookKeeperTestClient (org.apache.bookkeeper.client.BookKeeperTestClient)1 DeleteCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.DeleteCallback)1