@Test
public void testReadAheadManagerForOlderReadAheadFailure() 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 but also that its is an older readahead request.
  // System issue could have resolved by now, 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-X"))
      .doThrow(new TimeoutException("Internal Server error for RAH-X"))
      .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, "testReadAheadManagerForOlderReadAheadFailure.txt");
  queueReadAheads(inputStream);
  // AbfsInputStream Read would have waited for the read-ahead for the requested offset
  // as we are testing from ReadAheadManager directly, sleep for thresholdAgeMilliseconds so that
  // read buffer qualifies for to be an old buffer
  Thread.sleep(ReadBufferManager.getBufferManager().getThresholdAgeMilliseconds());
  // Only the 3 readAhead threads should have triggered client.read
  verifyReadCallCount(client, 3);
  // getBlock from a new read request should return 0 if there is a failure
  // 30 sec before in read ahead buffer for respective offset.
  int bytesRead = ReadBufferManager.getBufferManager().getBlock(
      inputStream,
      ONE_KB,
      ONE_KB,
      new byte[ONE_KB]);
  Assert.assertEquals("bytesRead should be zero when previously read "
      + "ahead buffer had failed", 0, bytesRead);
  // Stub returns success for the 5th read request, if ReadBuffers still
  // persisted request would have failed for position 0.
  checkEvictedStatus(inputStream, 0, false);
}