@Test
public void testHedgingWhenConnectException() throws Exception {

  ClientProtocol active = Mockito.mock(ClientProtocol.class);
  Mockito.when(active.getStats()).thenThrow(new ConnectException());
  ClientProtocol standby = Mockito.mock(ClientProtocol.class);
  Mockito.when(standby.getStats())
      .thenThrow(
          new RemoteException("org.apache.hadoop.ipc.StandbyException",
          "Standby NameNode"));
  RequestHedgingProxyProvider<ClientProtocol> provider =
      new RequestHedgingProxyProvider<>(conf, nnUri,
        ClientProtocol.class, createFactory(active, standby));
  try {
    provider.getProxy().proxy.getStats();
    Assert.fail("Should fail since the active namenode throws"
        + " ConnectException!");
  } catch (MultiException me) {
    for (Exception ex : me.getExceptions().values()) {
      if (ex instanceof RemoteException) {
        Exception rEx = ((RemoteException) ex)
            .unwrapRemoteException();
        Assert.assertTrue("Unexpected RemoteException: " + rEx.getMessage(),
            rEx instanceof StandbyException);
      } else {
        Assert.assertTrue(ex instanceof ConnectException);
      }
    }
  }
  Mockito.verify(active).getStats();
  Mockito.verify(standby).getStats();
}