@Test
 public void testLruBlockCache()
     throws JsonGenerationException, JsonMappingException, IOException {
   CacheConfig cc = new CacheConfig(this.conf);
   assertTrue(cc.isBlockCacheEnabled());
   assertTrue(CacheConfig.DEFAULT_IN_MEMORY == cc.isInMemory());
   assertTrue(cc.getBlockCache() instanceof LruBlockCache);
   logPerBlock(cc.getBlockCache());
   addDataAndHits(cc.getBlockCache(), 3);
   // The below has no asserts.  It is just exercising toString and toJSON code.
   BlockCache bc = cc.getBlockCache();
   LOG.info(
       "count="
           + bc.getBlockCount()
           + ", currentSize="
           + bc.getCurrentSize()
           + ", freeSize="
           + bc.getFreeSize());
   LOG.info(cc.getBlockCache().getStats());
   BlockCacheUtil.CachedBlocksByFile cbsbf = logPerBlock(cc.getBlockCache());
   LOG.info(cbsbf);
   logPerFile(cbsbf);
   bucketCacheReport(cc.getBlockCache());
   LOG.info(BlockCacheUtil.toJSON(cbsbf));
 }
 private void logPerFile(final BlockCacheUtil.CachedBlocksByFile cbsbf)
     throws JsonGenerationException, JsonMappingException, IOException {
   for (Map.Entry<String, NavigableSet<CachedBlock>> e :
       cbsbf.getCachedBlockStatsByFile().entrySet()) {
     int count = 0;
     long size = 0;
     int countData = 0;
     long sizeData = 0;
     for (CachedBlock cb : e.getValue()) {
       count++;
       size += cb.getSize();
       BlockType bt = cb.getBlockType();
       if (bt != null && bt.isData()) {
         countData++;
         sizeData += cb.getSize();
       }
     }
     LOG.info(
         "filename="
             + e.getKey()
             + ", count="
             + count
             + ", countData="
             + countData
             + ", size="
             + size
             + ", sizeData="
             + sizeData);
     LOG.info(BlockCacheUtil.toJSON(e.getKey(), e.getValue()));
   }
 }
 private BlockCacheUtil.CachedBlocksByFile logPerBlock(final BlockCache bc)
     throws JsonGenerationException, JsonMappingException, IOException {
   BlockCacheUtil.CachedBlocksByFile cbsbf = new BlockCacheUtil.CachedBlocksByFile();
   for (CachedBlock cb : bc) {
     LOG.info(cb.toString());
     LOG.info(BlockCacheUtil.toJSON(bc));
     cbsbf.update(cb);
   }
   return cbsbf;
 }
 @Test
 public void testBucketCache() throws JsonGenerationException, JsonMappingException, IOException {
   this.conf.set(HConstants.BUCKET_CACHE_IOENGINE_KEY, "offheap");
   this.conf.setInt(HConstants.BUCKET_CACHE_SIZE_KEY, 100);
   CacheConfig cc = new CacheConfig(this.conf);
   assertTrue(cc.getBlockCache() instanceof CombinedBlockCache);
   logPerBlock(cc.getBlockCache());
   final int count = 3;
   addDataAndHits(cc.getBlockCache(), count);
   // The below has no asserts.  It is just exercising toString and toJSON code.
   LOG.info(cc.getBlockCache().getStats());
   BlockCacheUtil.CachedBlocksByFile cbsbf = logPerBlock(cc.getBlockCache());
   LOG.info(cbsbf);
   logPerFile(cbsbf);
   bucketCacheReport(cc.getBlockCache());
   LOG.info(BlockCacheUtil.toJSON(cbsbf));
 }