public CombinedBlockCache(LruBlockCache onHeapCache, BlockCache l2Cache) { this.onHeapCache = onHeapCache; this.l2Cache = l2Cache; this.combinedCacheStats = new CombinedCacheStats(onHeapCache.getStats(), l2Cache.getStats()); }
assertTrue("blockcache should contain blocks. disabledBlockCount=" + disabledBlockCount, disabledBlockCount > 0); long disabledEvictedCount = disabledBlockCache.getStats().getEvictedCount(); for (Map.Entry<BlockCacheKey, LruCachedBlock> e : disabledBlockCache.getMapForTests().entrySet()) { assertTrue("blockcache should contain blocks. enabledBlockCount=" + enabledBlockCount, enabledBlockCount > 0); long enabledEvictedCount = enabledBlockCache.getStats().getEvictedCount(); int candidatesFound = 0; for (Map.Entry<BlockCacheKey, LruCachedBlock> e :
assertEquals(0, cache.getStats().getEvictionCount()); assertEquals(1, cache.getStats().getEvictionCount()); assertEquals(1, cache.getStats().getEvictedCount()); assertEquals(2, cache.getStats().getEvictionCount()); assertEquals(2, cache.getStats().getEvictedCount()); assertEquals(3, cache.getStats().getEvictionCount()); assertEquals(3, cache.getStats().getEvictedCount()); assertEquals(4, cache.getStats().getEvictionCount()); assertEquals(6, cache.getStats().getEvictedCount()); assertEquals(5, cache.getStats().getEvictionCount()); assertEquals(9, cache.getStats().getEvictedCount()); assertEquals(6, cache.getStats().getEvictionCount()); assertEquals(12, cache.getStats().getEvictedCount());
expectedCacheSize += singleBlocks[4].cacheBlockHeapSize(); assertEquals(0, cache.getStats().getEvictionCount()); assertEquals(1, cache.getStats().getEvictionCount()); assertEquals(1, cache.getStats().getEvictedCount()); assertEquals(2, cache.getStats().getEvictionCount()); assertEquals(2, cache.getStats().getEvictedCount()); cache.cacheBlock(memoryBlocks[5].cacheKey, memoryBlocks[5], true); assertEquals(6, cache.getStats().getEvictionCount()); assertEquals(6, cache.getStats().getEvictedCount()); cache.cacheBlock(memoryBlocks[8].cacheKey, memoryBlocks[8], true); assertEquals(9, cache.getStats().getEvictionCount()); assertEquals(9, cache.getStats().getEvictedCount()); assertEquals(10, cache.getStats().getEvictionCount()); assertEquals(10, cache.getStats().getEvictedCount()); assertEquals(11, cache.getStats().getEvictionCount()); assertEquals(11, cache.getStats().getEvictedCount());
assertEquals(10, cache.getStats().getFailedInserts());
@Test public void testCacheEvictionSimple() throws Exception { long maxSize = 100000; long blockSize = calculateBlockSizeDefault(maxSize, 10); LruBlockCache cache = new LruBlockCache(maxSize,blockSize,false); CachedItem [] blocks = generateFixedBlocks(10, blockSize, "block"); long expectedCacheSize = cache.heapSize(); // Add all the blocks for (CachedItem block : blocks) { cache.cacheBlock(block.cacheKey, block); expectedCacheSize += block.cacheBlockHeapSize(); } // A single eviction run should have occurred assertEquals(1, cache.getStats().getEvictionCount()); // Our expected size overruns acceptable limit assertTrue(expectedCacheSize > (maxSize * LruBlockCache.DEFAULT_ACCEPTABLE_FACTOR)); // But the cache did not grow beyond max assertTrue(cache.heapSize() < maxSize); // And is still below the acceptable limit assertTrue(cache.heapSize() < (maxSize * LruBlockCache.DEFAULT_ACCEPTABLE_FACTOR)); // All blocks except block 0 should be in the cache assertTrue(cache.getBlock(blocks[0].cacheKey, true, false, true) == null); for(int i=1;i<blocks.length;i++) { assertEquals(cache.getBlock(blocks[i].cacheKey, true, false, true), blocks[i]); } }
assertEquals(0, cache.getStats().getEvictionCount()); Thread t = new LruBlockCache.StatisticsThread(cache); t.start();
public CombinedBlockCache(LruBlockCache lruCache, BlockCache l2Cache) { this.lruCache = lruCache; this.l2Cache = l2Cache; this.combinedCacheStats = new CombinedCacheStats(lruCache.getStats(), l2Cache.getStats()); }
expectedCacheSize += singleBlocks[4].cacheBlockHeapSize(); assertEquals(0, cache.getStats().getEvictionCount()); assertEquals(1, cache.getStats().getEvictionCount()); assertEquals(1, cache.getStats().getEvictedCount()); assertEquals(2, cache.getStats().getEvictionCount()); assertEquals(2, cache.getStats().getEvictedCount()); cache.cacheBlock(memoryBlocks[5].cacheKey, memoryBlocks[5], true); assertEquals(6, cache.getStats().getEvictionCount()); assertEquals(6, cache.getStats().getEvictedCount()); cache.cacheBlock(memoryBlocks[8].cacheKey, memoryBlocks[8], true); assertEquals(9, cache.getStats().getEvictionCount()); assertEquals(9, cache.getStats().getEvictedCount()); assertEquals(10, cache.getStats().getEvictionCount()); assertEquals(10, cache.getStats().getEvictedCount()); assertEquals(11, cache.getStats().getEvictionCount()); assertEquals(11, cache.getStats().getEvictedCount());
assertEquals(10, cache.getStats().getFailedInserts());
assertEquals(0, cache.getStats().getEvictionCount()); Thread t = new LruBlockCache.StatisticsThread(cache); t.start();
@Test public void testCacheEvictionSimple() throws Exception { long maxSize = 100000; long blockSize = calculateBlockSizeDefault(maxSize, 10); LruBlockCache cache = new LruBlockCache(maxSize,blockSize,false); CachedItem [] blocks = generateFixedBlocks(10, blockSize, "block"); long expectedCacheSize = cache.heapSize(); // Add all the blocks for (CachedItem block : blocks) { cache.cacheBlock(block.cacheKey, block); expectedCacheSize += block.cacheBlockHeapSize(); } // A single eviction run should have occurred assertEquals(1, cache.getStats().getEvictionCount()); // Our expected size overruns acceptable limit assertTrue(expectedCacheSize > (maxSize * LruBlockCache.DEFAULT_ACCEPTABLE_FACTOR)); // But the cache did not grow beyond max assertTrue(cache.heapSize() < maxSize); // And is still below the acceptable limit assertTrue(cache.heapSize() < (maxSize * LruBlockCache.DEFAULT_ACCEPTABLE_FACTOR)); // All blocks except block 0 should be in the cache assertTrue(cache.getBlock(blocks[0].cacheKey, true, false, true) == null); for(int i=1;i<blocks.length;i++) { assertEquals(cache.getBlock(blocks[i].cacheKey, true, false, true), blocks[i]); } }