Search in sources :

Example 76 with ManagedLedgerConfig

use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.

the class ManagedLedgerTest method testReopenAndCleanup.

@Test(timeOut = 20000)
public void testReopenAndCleanup() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ledger.openCursor("c1");
    ledger.addEntry("data".getBytes(Encoding));
    ledger.close();
    Thread.sleep(100);
    assertEquals(bkc.getLedgers().size(), 1);
    factory.shutdown();
    factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
    ledger = factory.open("my_test_ledger");
    ledger.openCursor("c1");
    Thread.sleep(100);
    assertEquals(bkc.getLedgers().size(), 2);
    ledger.close();
    factory.open("my_test_ledger", new ManagedLedgerConfig()).delete();
    Thread.sleep(100);
    assertEquals(bkc.getLedgers().size(), 0);
    factory.shutdown();
}
Also used : ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Test(org.testng.annotations.Test)

Example 77 with ManagedLedgerConfig

use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.

the class ManagedLedgerTest method testDeletionAfterRetention.

@Test
public void testDeletionAfterRetention() throws Exception {
    ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
    ManagedLedgerConfig config = new ManagedLedgerConfig();
    config.setRetentionSizeInMB(0);
    config.setMaxEntriesPerLedger(1);
    config.setRetentionTime(1, TimeUnit.SECONDS);
    ManagedLedgerImpl ml = (ManagedLedgerImpl) factory.open("deletion_after_retention_test_ledger", config);
    ManagedCursor c1 = ml.openCursor("c1noretention");
    ml.addEntry("iamaverylongmessagethatshouldnotberetained".getBytes());
    c1.skipEntries(1, IndividualDeletedEntries.Exclude);
    ml.close();
    // reopen ml
    ml = (ManagedLedgerImpl) factory.open("deletion_after_retention_test_ledger", config);
    c1 = ml.openCursor("c1noretention");
    ml.addEntry("shortmessage".getBytes());
    c1.skipEntries(1, IndividualDeletedEntries.Exclude);
    // let retention expire
    Thread.sleep(1000);
    ml.internalTrimConsumedLedgers();
    assertTrue(ml.getLedgersInfoAsList().size() <= 1);
    assertTrue(ml.getTotalSize() <= "shortmessage".getBytes().length);
    ml.close();
}
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)

Example 78 with ManagedLedgerConfig

use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.

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)

Example 79 with ManagedLedgerConfig

use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.

the class ManagedLedgerTest method testBackwardCompatiblityForMeta.

@Test
public void testBackwardCompatiblityForMeta() throws Exception {
    final ManagedLedgerInfo[] storedMLInfo = new ManagedLedgerInfo[3];
    final Stat[] versions = new Stat[1];
    ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
    ManagedLedgerConfig conf = new ManagedLedgerConfig();
    conf.setMaxEntriesPerLedger(1);
    conf.setRetentionSizeInMB(10);
    conf.setRetentionTime(1, TimeUnit.HOURS);
    ManagedLedger ml = factory.open("backward_test_ledger", conf);
    ml.openCursor("c1");
    ml.addEntry("msg1".getBytes());
    ml.addEntry("msg2".getBytes());
    ml.close();
    MetaStore store = new MetaStoreImplZookeeper(zkc, executor);
    CountDownLatch l1 = new CountDownLatch(1);
    // obtain the ledger info
    store.getManagedLedgerInfo("backward_test_ledger", new MetaStoreCallback<ManagedLedgerInfo>() {

        @Override
        public void operationComplete(ManagedLedgerInfo result, Stat version) {
            storedMLInfo[0] = result;
            versions[0] = version;
            l1.countDown();
        }

        @Override
        public void operationFailed(MetaStoreException e) {
            fail("on get ManagedLedgerInfo backward_test_ledger");
        }
    });
    l1.await();
    ManagedLedgerInfo.Builder builder1 = ManagedLedgerInfo.newBuilder();
    // simulate test for old ledger with no timestampl
    for (LedgerInfo info : storedMLInfo[0].getLedgerInfoList()) {
        LedgerInfo noTimestamp = ManagedLedgerInfo.LedgerInfo.newBuilder().mergeFrom(info).clearTimestamp().build();
        assertFalse(noTimestamp.hasTimestamp(), "expected old version info with no timestamp");
        builder1.addLedgerInfo(noTimestamp);
    }
    storedMLInfo[1] = builder1.build();
    // test timestamp on new ledger
    CountDownLatch l2 = new CountDownLatch(1);
    store.asyncUpdateLedgerIds("backward_test_ledger", storedMLInfo[1], versions[0], new MetaStoreCallback<Void>() {

        @Override
        public void operationComplete(Void result, Stat version) {
            l2.countDown();
        }

        @Override
        public void operationFailed(MetaStoreException e) {
            fail("on asyncUpdateLedgerIds");
        }
    });
    // verify that after update ledgers have timestamp
    ManagedLedgerImpl newVersionLedger = (ManagedLedgerImpl) factory.open("backward_test_ledger", conf);
    List<LedgerInfo> mlInfo = newVersionLedger.getLedgersInfoAsList();
    assertTrue(mlInfo.stream().allMatch(new Predicate<LedgerInfo>() {

        @Override
        public boolean test(LedgerInfo ledgerInfo) {
            return ledgerInfo.hasTimestamp();
        }
    }));
}
Also used : ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) Predicate(java.util.function.Predicate) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) LedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo) MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) Stat(org.apache.bookkeeper.mledger.impl.MetaStore.Stat) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Test(org.testng.annotations.Test)

Example 80 with ManagedLedgerConfig

use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.

the class NonDurableCursorTest method testNumberOfEntriesInBacklog.

@Test(timeOut = 20000)
void testNumberOfEntriesInBacklog() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2).setRetentionTime(1, TimeUnit.HOURS).setRetentionSizeInMB(1));
    ManagedCursor c1 = ledger.newNonDurableCursor(PositionImpl.latest);
    Position p1 = ledger.addEntry("dummy-entry-1".getBytes(Encoding));
    ManagedCursor c2 = ledger.newNonDurableCursor(PositionImpl.latest);
    ledger.addEntry("dummy-entry-2".getBytes(Encoding));
    ManagedCursor c3 = ledger.newNonDurableCursor(PositionImpl.latest);
    Position p3 = ledger.addEntry("dummy-entry-3".getBytes(Encoding));
    ManagedCursor c4 = ledger.newNonDurableCursor(PositionImpl.latest);
    Position p4 = ledger.addEntry("dummy-entry-4".getBytes(Encoding));
    ManagedCursor c5 = ledger.newNonDurableCursor(PositionImpl.latest);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 4);
    assertEquals(c2.getNumberOfEntriesInBacklog(), 3);
    assertEquals(c3.getNumberOfEntriesInBacklog(), 2);
    assertEquals(c4.getNumberOfEntriesInBacklog(), 1);
    assertEquals(c5.getNumberOfEntriesInBacklog(), 0);
    List<Entry> entries = c1.readEntries(2);
    assertEquals(entries.size(), 2);
    entries.forEach(e -> e.release());
    assertEquals(c1.getNumberOfEntries(), 2);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 4);
    c1.markDelete(p1);
    assertEquals(c1.getNumberOfEntries(), 2);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 3);
    c1.delete(p3);
    assertEquals(c1.getNumberOfEntries(), 1);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 2);
    c1.markDelete(p4);
    assertEquals(c1.getNumberOfEntries(), 0);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 0);
}
Also used : Entry(org.apache.bookkeeper.mledger.Entry) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Aggregations

ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)194 Test (org.testng.annotations.Test)182 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)159 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)147 Position (org.apache.bookkeeper.mledger.Position)85 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)77 Entry (org.apache.bookkeeper.mledger.Entry)63 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)54 CountDownLatch (java.util.concurrent.CountDownLatch)52 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)33 CyclicBarrier (java.util.concurrent.CyclicBarrier)20 ManagedLedgerFactoryConfig (org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig)19 AddEntryCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback)18 List (java.util.List)17 AtomicReference (java.util.concurrent.atomic.AtomicReference)16 LedgerEntry (org.apache.bookkeeper.client.LedgerEntry)16 TimeUnit (java.util.concurrent.TimeUnit)15 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)15 BKException (org.apache.bookkeeper.client.BKException)14 Lists (com.google.common.collect.Lists)13