@Test
public void testReconnect() throws Exception {

    pool = new SimpleAsyncConnectionPoolImpl<TestClient>(TestHost, connFactory, config, cpMonitor);
    pool.primeConnections();
    int nThreads = 3;
    TestControl control = new TestControl(3);
    BasicResult total = new BasicResult();
    for (int i = 0; i < nThreads; i++) {
        threadPool.submit(new BasicWorker(total, control));
    }
    Thread.sleep(500);
    Assert.assertFalse("Total: " + total, total.failureCount.get() > 0);
    Assert.assertTrue("Total: " + total, total.lastSuccess.get());
    pool.markAsDown(new FatalConnectionException("mark pool as down"));
    Thread.sleep(200);
    control.stop();
    control.waitOnFinish();
    Assert.assertTrue("Total: " + total, total.failureCount.get() > 0);
    Assert.assertFalse("Total: " + total, total.lastSuccess.get());
    Assert.assertEquals("Total: " + total, total.opCount.get(), (total.successCount.get() + total.failureCount.get()));
    pool.reconnect();
    Thread.sleep(100);
    control = new TestControl(3);
    total = new BasicResult();
    for (int i = 0; i < nThreads; i++) {
        threadPool.submit(new BasicWorker(total, control));
    }
    Thread.sleep(500);
    control.stop();
    control.waitOnFinish();
    Assert.assertEquals("Total: " + total, total.opCount.get(), total.successCount.get());
    Assert.assertEquals("Total: " + total, 0, total.failureCount.get());
    Assert.assertTrue("Total: " + total, total.lastSuccess.get());
    pool.shutdown();
    Assert.assertEquals("Conns returned: " + cpMonitor.getConnectionReturnedCount(), cpMonitor.getConnectionBorrowedCount(), cpMonitor.getConnectionReturnedCount());
    Assert.assertEquals("Conns created: " + cpMonitor.getConnectionCreatedCount(), 2 * config.getMaxConnsPerHost(), cpMonitor.getConnectionCreatedCount());
    Assert.assertEquals("Conns closed: " + cpMonitor.getConnectionClosedCount(), cpMonitor.getConnectionCreatedCount(), cpMonitor.getConnectionClosedCount());
    Assert.assertEquals("Conns create failed: " + cpMonitor.getConnectionCreateFailedCount(), 0, cpMonitor.getConnectionCreateFailedCount());
}