@Test
public void testFailedReadAhead() throws Exception {

  AbfsClient client = getMockAbfsClient();
  AbfsRestOperation successOp = getMockRestOp();
  // Stub :
  // Read request leads to 3 readahead calls: Fail all 3 readahead-client.read()
  // Actual read request fails with the failure in readahead thread
  doThrow(new TimeoutException("Internal Server error for RAH-Thread-X"))
      .doThrow(new TimeoutException("Internal Server error for RAH-Thread-Y"))
      .doThrow(new TimeoutException("Internal Server error RAH-Thread-Z"))
      .doReturn(successOp) // Any extra calls to read, pass it.
      .when(client)
      .read(any(String.class), any(Long.class), any(byte[].class),
          any(Integer.class), any(Integer.class), any(String.class),
          any(String.class));
  AbfsInputStream inputStream = getAbfsInputStream(client, "testFailedReadAhead.txt");
  // Scenario: ReadAhead triggered from current active read call failed
  // Before the change to return exception from readahead buffer,
  // AbfsInputStream would have triggered an extra readremote on noticing
  // data absent in readahead buffers
  // In this test, a read should trigger 3 client.read() calls as file is 3 KB
  // and readahead buffer size set in AbfsInputStream is 1 KB
  // There should only be a total of 3 client.read() in this test.
  intercept(IOException.class,
      () -> inputStream.read(new byte[ONE_KB]));
  // Only the 3 readAhead threads should have triggered client.read
  verifyReadCallCount(client, 3);
  // Stub returns success for the 4th read request, if ReadBuffers still
  // persisted, ReadAheadManager getBlock would have returned exception.
  checkEvictedStatus(inputStream, 0, false);
}