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