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