@Test
  public void testCacheBlocks() throws IOException {
    // Set index block size to be the same as normal block size.
    TEST_UTIL.getConfiguration().setInt(HFileBlockIndex.MAX_CHUNK_SIZE_KEY, BLOCK_SIZE);
    BlockCache blockCache = BlockCacheFactory.createBlockCache(TEST_UTIL.getConfiguration());
    ColumnFamilyDescriptor cfd =
      ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(CF)).setMaxVersions(MAX_VERSIONS)
        .setCompressionType(COMPRESSION_ALGORITHM).setBloomFilterType(BLOOM_TYPE)
        .setBlocksize(BLOCK_SIZE).setBlockCacheEnabled(cfCacheEnabled).build();
    HRegion region = TEST_UTIL.createTestRegion(TABLE, cfd, blockCache);
    CacheStats stats = blockCache.getStats();
    writeTestData(region);
    assertEquals(0, stats.getHitCount());
    assertEquals(0, HFile.DATABLOCK_READ_COUNT.sum());
    // Do a single get, take count of caches. If we are NOT caching DATA blocks, the miss
    // count should go up. Otherwise, all should be cached and the miss count should not rise.
    region.get(new Get(Bytes.toBytes("row" + 0)));
    assertTrue(stats.getHitCount() > 0);
    assertTrue(HFile.DATABLOCK_READ_COUNT.sum() > 0);
    long missCount = stats.getMissCount();
    region.get(new Get(Bytes.toBytes("row" + 0)));
    if (this.cfCacheEnabled) assertEquals(missCount, stats.getMissCount());
    else assertTrue(stats.getMissCount() > missCount);
  }
Extremely small block size, so that we can get some index blocks
hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestForceCacheImportantBlocks.java