@Test
public void testOlderReadAheadFailure() throws Exception {

  AbfsClient client = getMockAbfsClient();
  AbfsRestOperation successOp = getMockRestOp();
  // Stub :
  // First Read request leads to 3 readahead calls: Fail all 3 readahead-client.read()
  // A second read request will see that readahead had failed for data in
  // the requested offset range and also that its is an older readahead request.
  // So attempt a new read only for the requested range.
  doThrow(new TimeoutException("Internal Server error for RAH-X"))
      .doThrow(new TimeoutException("Internal Server error for RAH-Y"))
      .doThrow(new TimeoutException("Internal Server error for RAH-Z"))
      .doReturn(successOp) // pass the read for second read request
      .doReturn(successOp) // pass success for post eviction test
      .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, "testOlderReadAheadFailure.txt");
  // First read request that fails as the readahead triggered from this request failed.
  intercept(IOException.class,
      () -> inputStream.read(new byte[ONE_KB]));
  // Only the 3 readAhead threads should have triggered client.read
  verifyReadCallCount(client, 3);
  // Sleep for thresholdAgeMs so that the read ahead buffer qualifies for being old.
  Thread.sleep(ReadBufferManager.getBufferManager().getThresholdAgeMilliseconds());
  // Second read request should retry the read (and not issue any new readaheads)
  inputStream.read(ONE_KB, new byte[ONE_KB], 0, ONE_KB);
  // Once created, mock will remember all interactions. So total number of read
  // calls will be one more from earlier (there is a reset mock which will reset the
  // count, but the mock stub is erased as well which needs AbsInputStream to be recreated,
  // which beats the purpose)
  verifyReadCallCount(client, 4);
  // Stub returns success for the 5th read request, if ReadBuffers still
  // persisted request would have failed for position 0.
  checkEvictedStatus(inputStream, 0, false);
}