Search in sources :

Example 1 with AbstractCacheStats

use of org.apache.jackrabbit.oak.cache.AbstractCacheStats in project jackrabbit-oak by apache.

the class CacheWeightsTest method testSegmentCache.

@Test
public void testSegmentCache() {
    final int count = 10000;
    final int cacheSizeMB = 100;
    final int bufferSize = 5 * 1024;
    Supplier<Entry<Object, Long[]>> factory = new Supplier<Entry<Object, Long[]>>() {

        @Override
        public Entry<Object, Long[]> get() {
            SegmentCache cache = new SegmentCache(cacheSizeMB);
            for (int i = 0; i < count; ++i) {
                Segment segment = randomSegment(bufferSize);
                cache.putSegment(segment);
            }
            AbstractCacheStats stats = cache.getCacheStats();
            long elements = stats.getElementCount();
            long weight = stats.estimateCurrentWeight();
            return new SimpleImmutableEntry<Object, Long[]>(cache, new Long[] { elements, weight });
        }
    };
    runTest(factory, "SegmentCache[x" + cacheSizeMB + "MB|" + bufferSize + "|Cache<SegmentId, Segment>]");
}
Also used : SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) Entry(java.util.Map.Entry) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) Supplier(com.google.common.base.Supplier) AbstractCacheStats(org.apache.jackrabbit.oak.cache.AbstractCacheStats) Test(org.junit.Test)

Example 2 with AbstractCacheStats

use of org.apache.jackrabbit.oak.cache.AbstractCacheStats in project jackrabbit-oak by apache.

the class SegmentCacheTest method statsTest.

@Test
public void statsTest() throws Exception {
    AbstractCacheStats stats = cache.getCacheStats();
    // empty cache
    assertEquals(0, stats.getElementCount());
    assertEquals(0, stats.getLoadCount());
    assertEquals(0, stats.getHitCount());
    assertEquals(0, stats.getMissCount());
    assertEquals(0, stats.getRequestCount());
    // load
    cache.getSegment(id1, () -> segment1);
    assertEquals(1, stats.getElementCount());
    assertEquals(1, stats.getLoadCount());
    assertEquals(0, stats.getHitCount());
    assertEquals(1, stats.getMissCount());
    assertEquals(1, stats.getRequestCount());
    // cache hit
    assertEquals(segment1, id1.getSegment());
    assertEquals(1, stats.getElementCount());
    assertEquals(1, stats.getLoadCount());
    assertEquals(1, stats.getHitCount());
    assertEquals(1, stats.getMissCount());
    assertEquals(2, stats.getRequestCount());
    cache.clear();
    assertEquals(0, stats.getElementCount());
    assertEquals(1, stats.getLoadCount());
    assertEquals(1, stats.getHitCount());
    assertEquals(1, stats.getMissCount());
    assertEquals(2, stats.getRequestCount());
    stats.resetStats();
    assertEquals(0, stats.getElementCount());
    assertEquals(0, stats.getLoadCount());
    assertEquals(0, stats.getHitCount());
    assertEquals(0, stats.getMissCount());
    assertEquals(0, stats.getRequestCount());
}
Also used : AbstractCacheStats(org.apache.jackrabbit.oak.cache.AbstractCacheStats) Test(org.junit.Test)

Aggregations

AbstractCacheStats (org.apache.jackrabbit.oak.cache.AbstractCacheStats)2 Test (org.junit.Test)2 Supplier (com.google.common.base.Supplier)1 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)1 Entry (java.util.Map.Entry)1