@Test
  public void testByteBufferIOEngine() throws Exception {
    int capacity = 32 * 1024 * 1024; // 32 MB
    int testNum = 100;
    int maxBlockSize = 64 * 1024;
    ByteBufferIOEngine ioEngine = new ByteBufferIOEngine(capacity);
    int testOffsetAtStartNum = testNum / 10;
    int testOffsetAtEndNum = testNum / 10;
    for (int i = 0; i < testNum; i++) {
      byte val = (byte) (Math.random() * 255);
      int blockSize = (int) (Math.random() * maxBlockSize);
      if (blockSize == 0) {
        blockSize = 1;
      }

      ByteBuff src = createByteBuffer(blockSize, val, i % 2 == 0);
      int pos = src.position(), lim = src.limit();
      int offset;
      if (testOffsetAtStartNum > 0) {
        testOffsetAtStartNum--;
        offset = 0;
      } else if (testOffsetAtEndNum > 0) {
        testOffsetAtEndNum--;
        offset = capacity - blockSize;
      } else {
        offset = (int) (Math.random() * (capacity - maxBlockSize));
      }
      ioEngine.write(src, offset);
      src.position(pos).limit(lim);

      BucketEntry be = createBucketEntry(offset, blockSize);
      ioEngine.read(be);
      ByteBuff dst = getByteBuff(be);
      Assert.assertEquals(src.remaining(), blockSize);
      Assert.assertEquals(dst.remaining(), blockSize);
      Assert.assertEquals(0, ByteBuff.compareTo(src, src.position(), src.remaining(), dst,
        dst.position(), dst.remaining()));
    }
    assert testOffsetAtStartNum == 0;
    assert testOffsetAtEndNum == 0;
  }
Override the {@link BucketEntry} so that we can set an arbitrary offset.
hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestByteBufferIOEngine.java