@Test
public void testRequestNNAfterOneSuccess() throws Exception {

  final AtomicInteger goodCount = new AtomicInteger(0);
  final AtomicInteger badCount = new AtomicInteger(0);
  final ClientProtocol goodMock = mock(ClientProtocol.class);
  when(goodMock.getStats()).thenAnswer(new Answer<long[]>() {
    @Override
    public long[] answer(InvocationOnMock invocation) throws Throwable {
      goodCount.incrementAndGet();
      Thread.sleep(1000);
      return new long[]{1};
    }
  });
  final ClientProtocol badMock = mock(ClientProtocol.class);
  when(badMock.getStats()).thenAnswer(new Answer<long[]>() {
    @Override
    public long[] answer(InvocationOnMock invocation) throws Throwable {
      badCount.incrementAndGet();
      throw new IOException("Bad mock !!");
    }
  });
  RequestHedgingProxyProvider<ClientProtocol> provider =
      new RequestHedgingProxyProvider<>(conf, nnUri, ClientProtocol.class,
          createFactory(badMock, goodMock));
  ClientProtocol proxy = provider.getProxy().proxy;
  proxy.getStats();
  assertEquals(1, goodCount.get());
  assertEquals(1, badCount.get());
  // We will only use the successful proxy after a successful invocation.
  proxy.getStats();
  assertEquals(2, goodCount.get());
  assertEquals(1, badCount.get());
}