@Test
  public void testByteBufferPositionedReadableEOF() throws IOException {
    assumeTrue("Skip the test because ByteBufferPositionedReadable is not available",
      isByteBufferPositionedReadable());
    long position = 0;
    int necessaryLen = 10;
    int extraLen = 0;
    int totalLen = necessaryLen + extraLen;
    int firstReadLen = 9;
    ByteBuffer buf = ByteBuffer.allocate(totalLen);
    ByteBuff bb = new SingleByteBuff(buf);
    MyFSDataInputStream in = mock(MyFSDataInputStream.class);

    when(in.read(position, buf)).thenReturn(firstReadLen);
    when(in.read(position, buf)).thenReturn(-1);
    when(in.hasCapability(anyString())).thenReturn(true);
    exception.expect(IOException.class);
    exception.expectMessage("EOF");
    BlockIOUtils.preadWithExtra(bb, in, position, necessaryLen, extraLen);

    verify(in).read(position, buf);
    verify(in).read(firstReadLen, buf);
    verify(in).hasCapability(anyString());
    verifyNoMoreInteractions(in);
  }
Determine if ByteBufferPositionedReadable API is available .
@return true if FSDataInputStream implements ByteBufferPositionedReadable API.
hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestBlockIOUtils.java