Search in sources :

Example 26 with ManagedLedgerFactory

use of org.apache.bookkeeper.mledger.ManagedLedgerFactory in project pulsar by yahoo.

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.close();
    // sleep for trim
    Thread.sleep(100);
    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 27 with ManagedLedgerFactory

use of org.apache.bookkeeper.mledger.ManagedLedgerFactory in project pulsar by yahoo.

the class ManagedLedgerTest method testNoRetention.

@Test(enabled = true)
public void testNoRetention() throws Exception {
    ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
    ManagedLedgerConfig config = new ManagedLedgerConfig();
    config.setRetentionSizeInMB(0);
    config.setMaxEntriesPerLedger(1);
    // Default is no-retention
    ManagedLedgerImpl ml = (ManagedLedgerImpl) factory.open("noretention_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("noretention_test_ledger", config);
    c1 = ml.openCursor("c1noretention");
    ml.addEntry("shortmessage".getBytes());
    c1.skipEntries(1, IndividualDeletedEntries.Exclude);
    // sleep for trim
    Thread.sleep(1000);
    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