Search in sources :

Example 11 with ManagedLedgerFactoryConfig

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

the class EntryCacheManagerTest method doubleInsert.

@Test
void doubleInsert() throws Exception {
    ManagedLedgerFactoryConfig config = new ManagedLedgerFactoryConfig();
    config.setMaxCacheSize(10);
    config.setCacheEvictionWatermark(0.8);
    factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle(), config);
    EntryCacheManager cacheManager = factory.getEntryCacheManager();
    EntryCache cache1 = cacheManager.getEntryCache(ml1);
    assertEquals(cache1.insert(new EntryImpl(1, 1, new byte[4])), true);
    assertEquals(cache1.insert(new EntryImpl(1, 0, new byte[3])), true);
    assertEquals(cache1.getSize(), 7);
    assertEquals(cacheManager.getSize(), 7);
    assertEquals(cache1.insert(new EntryImpl(1, 0, new byte[5])), false);
    assertEquals(cache1.getSize(), 7);
    assertEquals(cacheManager.getSize(), 7);
}
Also used : ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) Test(org.testng.annotations.Test)

Example 12 with ManagedLedgerFactoryConfig

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

the class EntryCacheManagerTest method cacheDisabled.

@Test
void cacheDisabled() throws Exception {
    ManagedLedgerFactoryConfig config = new ManagedLedgerFactoryConfig();
    config.setMaxCacheSize(0);
    config.setCacheEvictionWatermark(0.8);
    factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle(), config);
    EntryCacheManager cacheManager = factory.getEntryCacheManager();
    EntryCache cache1 = cacheManager.getEntryCache(ml1);
    EntryCache cache2 = cacheManager.getEntryCache(ml2);
    assertTrue(cache1 instanceof EntryCacheManager.EntryCacheDisabled);
    assertTrue(cache2 instanceof EntryCacheManager.EntryCacheDisabled);
    cache1.insert(new EntryImpl(1, 1, new byte[4]));
    cache1.insert(new EntryImpl(1, 0, new byte[3]));
    assertEquals(cache1.getSize(), 0);
    assertEquals(cacheManager.getSize(), 0);
    cacheManager.mlFactoryMBean.refreshStats(1, TimeUnit.SECONDS);
    assertEquals(cacheManager.mlFactoryMBean.getCacheMaxSize(), 0);
    assertEquals(cacheManager.mlFactoryMBean.getCacheUsedSize(), 0);
    assertEquals(cacheManager.mlFactoryMBean.getCacheHitsRate(), 0.0);
    assertEquals(cacheManager.mlFactoryMBean.getCacheMissesRate(), 0.0);
    assertEquals(cacheManager.mlFactoryMBean.getCacheHitsThroughput(), 0.0);
    assertEquals(cacheManager.mlFactoryMBean.getNumberOfCacheEvictions(), 0);
    cache2.insert(new EntryImpl(2, 0, new byte[1]));
    cache2.insert(new EntryImpl(2, 1, new byte[1]));
    cache2.insert(new EntryImpl(2, 2, new byte[1]));
    assertEquals(cache2.getSize(), 0);
    assertEquals(cacheManager.getSize(), 0);
}
Also used : ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) Test(org.testng.annotations.Test)

Example 13 with ManagedLedgerFactoryConfig

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

the class ManagedLedgerMBeanTest method simple.

@Test
public void simple() throws Exception {
    ManagedLedgerFactoryConfig config = new ManagedLedgerFactoryConfig();
    config.setMaxCacheSize(0);
    ManagedLedgerFactoryImpl factory = new ManagedLedgerFactoryImpl(bkc, zkc, config);
    ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("my_test_ledger");
    ManagedCursor cursor = ledger.openCursor("c1");
    ManagedLedgerMBeanImpl mbean = ledger.mbean;
    assertEquals(mbean.getName(), "my_test_ledger");
    assertEquals(mbean.getStoredMessagesSize(), 0);
    assertEquals(mbean.getNumberOfMessagesInBacklog(), 0);
    waitForRefresh(mbean);
    mbean.addAddEntryLatencySample(1, TimeUnit.MILLISECONDS);
    mbean.addAddEntryLatencySample(10, TimeUnit.MILLISECONDS);
    mbean.addAddEntryLatencySample(1, TimeUnit.SECONDS);
    mbean.addLedgerSwitchLatencySample(1, TimeUnit.MILLISECONDS);
    mbean.addLedgerSwitchLatencySample(10, TimeUnit.MILLISECONDS);
    mbean.addLedgerSwitchLatencySample(1, TimeUnit.SECONDS);
    // Simulate stats getting update from different thread
    factory.executor.submit(() -> {
        mbean.refreshStats(1, TimeUnit.SECONDS);
    }).get();
    assertEquals(mbean.getAddEntryBytesRate(), 0.0);
    assertEquals(mbean.getAddEntryMessagesRate(), 0.0);
    assertEquals(mbean.getAddEntrySucceed(), 0);
    assertEquals(mbean.getAddEntryErrors(), 0);
    assertEquals(mbean.getReadEntriesBytesRate(), 0.0);
    assertEquals(mbean.getReadEntriesRate(), 0.0);
    assertEquals(mbean.getReadEntriesSucceeded(), 0);
    assertEquals(mbean.getReadEntriesErrors(), 0);
    assertEquals(mbean.getMarkDeleteRate(), 0.0);
    assertEquals(mbean.getAddEntryLatencyBuckets(), new long[] { 0, 1, 0, 1, 0, 0, 0, 0, 1, 0 });
    assertEquals(mbean.getAddEntryLatencyAverageUsec(), 337_000.0);
    assertEquals(mbean.getEntrySizeBuckets(), new long[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 });
    assertEquals(mbean.getLedgerSwitchLatencyBuckets(), new long[] { 0, 1, 0, 1, 0, 0, 0, 0, 1, 0 });
    assertEquals(mbean.getLedgerSwitchLatencyAverageUsec(), 337_000.0);
    Position p1 = ledger.addEntry(new byte[200]);
    ledger.addEntry(new byte[600]);
    cursor.markDelete(p1);
    factory.executor.submit(() -> {
        mbean.refreshStats(1, TimeUnit.SECONDS);
    }).get();
    assertEquals(mbean.getAddEntryBytesRate(), 800.0);
    assertEquals(mbean.getAddEntryMessagesRate(), 2.0);
    assertEquals(mbean.getAddEntrySucceed(), 2);
    assertEquals(mbean.getAddEntryErrors(), 0);
    assertEquals(mbean.getReadEntriesBytesRate(), 0.0);
    assertEquals(mbean.getReadEntriesRate(), 0.0);
    assertEquals(mbean.getReadEntriesSucceeded(), 0);
    assertEquals(mbean.getReadEntriesErrors(), 0);
    assertTrue(mbean.getMarkDeleteRate() > 0.0);
    assertEquals(mbean.getEntrySizeBuckets(), new long[] { 0, 1, 1, 0, 0, 0, 0, 0, 0 });
    mbean.recordAddEntryError();
    mbean.recordReadEntriesError();
    factory.executor.submit(() -> {
        mbean.refreshStats(1, TimeUnit.SECONDS);
    }).get();
    assertEquals(mbean.getAddEntryErrors(), 1);
    assertEquals(mbean.getReadEntriesErrors(), 1);
    List<Entry> entries = cursor.readEntries(100);
    assertEquals(entries.size(), 1);
    factory.executor.submit(() -> {
        mbean.refreshStats(1, TimeUnit.SECONDS);
    }).get();
    assertEquals(mbean.getReadEntriesBytesRate(), 600.0);
    assertEquals(mbean.getReadEntriesRate(), 1.0);
    assertEquals(mbean.getReadEntriesSucceeded(), 1);
    assertEquals(mbean.getReadEntriesErrors(), 0);
    assertEquals(mbean.getNumberOfMessagesInBacklog(), 1);
    assertEquals(mbean.getMarkDeleteRate(), 0.0);
    factory.shutdown();
}
Also used : Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) Position(org.apache.bookkeeper.mledger.Position) 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