@Test
  public void testRetryOpenDuringRecovery() throws Exception {
    FileSystem spiedFs = Mockito.spy(fs);
    // The "Cannot obtain block length", "Could not obtain the last block",
    // and "Blocklist for [^ ]* has changed.*" part is very important,
    // that's how it comes out of HDFS. If HDFS changes the exception
    // message, this test needs to be adjusted accordingly.
    //
    // When DFSClient tries to open a file, HDFS needs to locate
    // the last block of the file and get its length. However, if the
    // last block is under recovery, HDFS may have problem to obtain
    // the block length, in which case, retry may help.
    Mockito.doAnswer(new Answer<FSDataInputStream>() {
      private final String[] errors = new String[] { "Cannot obtain block length",
        "Could not obtain the last block", "Blocklist for " + OLDLOGDIR + " has changed" };
      private int count = 0;

      @Override
      public FSDataInputStream answer(InvocationOnMock invocation) throws Throwable {
        if (count < 3) {
          throw new IOException(errors[count++]);
        }
        return (FSDataInputStream) invocation.callRealMethod();
      }
    }).when(spiedFs).open(Mockito.<Path> any(), Mockito.anyInt());
    retryOverHdfsProblem(spiedFs);
  }
@param spiedFs should be instrumented for failure.
hbase-server/src/test/java/org/apache/hadoop/hbase/wal/TestWALSplit.java