SimpleAsyncConnectionPoolImpl implements HostConnectionPool<CL> { @Override public void reconnect() { if (active.get()) { Logger.info("Pool already active, ignoring reconnect connections request"); return; } if (reconnecting.get()) { Logger.info("Pool already reconnecting, ignoring reconnect connections request"); return; } if (!(reconnecting.compareAndSet(false, true))) { Logger.info("Pool already reconnecting, ignoring reconnect connections request"); return; } try { shutdown(); primeConnections(); } finally { reconnecting.set(false); } } SimpleAsyncConnectionPoolImpl(Host host, ConnectionFactory<CL> cFactory,
                                         ConnectionPoolConfiguration config, ConnectionPoolMonitor monitor); @Override Connection<CL> borrowConnection(int duration, TimeUnit unit); @Override boolean returnConnection(Connection<CL> connection); @Override boolean closeConnection(Connection<CL> connection); @Override void recycleConnection(Connection<CL> connection); @Override void markAsDown(DynoException reason); @Override void reconnect(); @Override void shutdown(); @Override int primeConnections(); @Override Collection<Connection<CL>> getAllConnections(); @Override int getConnectionTimeout(); @Override int getSocketTimeout(); @Override Host getHost(); @Override boolean isActive(); @Override boolean isShutdown(); @Override int size();  }
@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()); }