Search in sources :

Example 21 with ManagedLedgerFactory

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

Example 22 with ManagedLedgerFactory

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();
}
Also used : Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) DeleteCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.DeleteCallback) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Test(org.testng.annotations.Test)

Example 23 with ManagedLedgerFactory

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();
}
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)

Example 24 with ManagedLedgerFactory

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

Example 25 with ManagedLedgerFactory

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

Aggregations

ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)27 Test (org.testng.annotations.Test)26 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)23 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)23 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)19 Position (org.apache.bookkeeper.mledger.Position)14 CountDownLatch (java.util.concurrent.CountDownLatch)5 Entry (org.apache.bookkeeper.mledger.Entry)5 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)5 ManagedLedgerFactoryConfig (org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig)5 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 Future (java.util.concurrent.Future)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 MarkDeleteCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.MarkDeleteCallback)2 ManagedLedgerInfo (org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo)2 LedgerInfo (org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo)2 Charsets (com.google.common.base.Charsets)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1