public static HFileBlockPair[] generateBlocksForPath(int blockSize, int numBlocks, Path path,
    boolean encoded) {
    HFileBlockPair[] returnedBlocks = new HFileBlockPair[numBlocks];
    Random rand = ThreadLocalRandom.current();
    HashSet<String> usedStrings = new HashSet<>();
    for (int i = 0; i < numBlocks; i++) {
      ByteBuffer cachedBuffer = ByteBuffer.allocate(blockSize);
      Bytes.random(cachedBuffer.array());
      cachedBuffer.rewind();
      int onDiskSizeWithoutHeader = blockSize;
      int uncompressedSizeWithoutHeader = blockSize;
      long prevBlockOffset = rand.nextLong();
      BlockType.DATA.write(cachedBuffer);
      cachedBuffer.putInt(onDiskSizeWithoutHeader);
      cachedBuffer.putInt(uncompressedSizeWithoutHeader);
      cachedBuffer.putLong(prevBlockOffset);
      cachedBuffer.rewind();
      HFileContext meta =
        new HFileContextBuilder().withHBaseCheckSum(false).withIncludesMvcc(includesMemstoreTS)
          .withIncludesTags(false).withCompression(Compression.Algorithm.NONE)
          .withDataBlockEncoding(DataBlockEncoding.FAST_DIFF).withBytesPerCheckSum(0)
          .withChecksumType(ChecksumType.NULL).build();
      HFileBlock generated = new HFileBlock(encoded ? BlockType.ENCODED_DATA : BlockType.DATA,
        onDiskSizeWithoutHeader, uncompressedSizeWithoutHeader, prevBlockOffset,
        ByteBuff.wrap(cachedBuffer), HFileBlock.DONT_FILL_HEADER, blockSize,
        onDiskSizeWithoutHeader + HConstants.HFILEBLOCK_HEADER_SIZE, -1, meta,
        ByteBuffAllocator.HEAP);
      String key = null;
      long offset = 0;
      if (path != null) {
        key = path.getName();
        offset = i * blockSize;
      } else {
        /* No conflicting keys */
        key = Long.toString(rand.nextLong());
        while (!usedStrings.add(key)) {
          key = Long.toString(rand.nextLong());
        }
      }
      returnedBlocks[i] = new HFileBlockPair();
      returnedBlocks[i].blockName =
        new BlockCacheKey(key, offset, true, encoded ? BlockType.ENCODED_DATA : BlockType.DATA);
      returnedBlocks[i].block = generated;
    }
    return returnedBlocks;
  }
Just checks if heapsize grows when something is cached, and gets smaller when the same object
is evicted
hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/CacheTestUtils.java