@Test
public void reuseDeadNewConnection() throws ConnectionException, InterruptedException, IOException {

  initPool(Integer.MAX_VALUE, // high keep-alive so it won't get in the way...
      1, //
      Integer.MAX_VALUE, //
      .95);
  TestConnection<ClusterManagementService.Iface> conn = (TestConnection<ClusterManagementService.Iface>) pool
      .reserveConnection(ClusterManagementService.Iface.class, ADDR1, null);
  int connId = conn.getId();
  Assert.assertEquals(conn.getServiceInfo().getServiceInterface(), ClusterManagementService.Iface.class,
      "Correct service expected");
  // adjust the morph of the connection to a KeepAliveService and make sure there is an exception thrown when the
  // "ping" method is called - this should be executed before re-using the connection above - marking the connection
  // above as dead.
  conFac.adjustMorphOfConn(connId, new Consumer<TestConnection<?>>() {
    @Override
    public void accept(TestConnection<?> t) {
      try {
        if (t.getServiceInfo().getServiceInterface().equals(KeepAliveService.Iface.class)) {
          // temp unpool to install our mock
          t.pooledCAS(true, false);
          Mockito.doThrow(TException.class).when(((KeepAliveService.Iface) t.getService())).ping();
          t.pooledCAS(false, true);
        }
      } catch (TException e) {
        throw new RuntimeException(e);
      }
    }
  });
  conn.close(); // release connection
  // request a connection to the same host (so it will get re-used), which should be blocked - the first connection
  // was released, but it is effectively still open until it is closed automatically by the timeout!
  TestConnection<ClusterManagementService.Iface> conn2 = (TestConnection<ClusterManagementService.Iface>) pool
      .reserveConnection(ClusterManagementService.Iface.class, ADDR1, null);
  conn2.close();
  // ensure that the "close" method on the first connection was called
  Mockito.verify(conn.getTransport()).close();
  Assert.assertNotEquals(conn2.getId(), connId, "Expected that connection was not re-used, as "
      + "first connection was tried to be re-used but appeared to have died");
  Assert.assertEquals(conn2.getServiceInfo().getServiceInterface(), ClusterManagementService.Iface.class,
      "Correct service expected");
}