AthenzDataSource extends PoolingDataSource<PoolableConnection> implements PoolableDataSource { @Override synchronized public void clearPoolConnections() { ObjectPool<PoolableConnection> pool = getPool(); try { LOG.info("Clearing all active/idle ({}/{}) connections from the pool", pool.getNumActive(), pool.getNumIdle()); pool.clear(); } catch (Exception ex) { LOG.error("Unable to clear connections from the pool", ex); } } AthenzDataSource(ObjectPool<PoolableConnection> pool); @Override synchronized void clearPoolConnections(); @Override Connection getConnection(); static final String ATHENZ_PROP_DATASTORE_NETWORK_TIMEOUT; static final String ATHENZ_PROP_DATASTORE_TIMEOUT_THREADS; }
@Test public void testClearPoolConnectionsException() throws Exception { ObjectPool<PoolableConnection> pool = Mockito.mock(ObjectPool.class); Mockito.doThrow(new SQLException()).when(pool).clear(); AthenzDataSource dataSource = new AthenzDataSource(pool); dataSource.clearPoolConnections(); }
@Test public void testClearPoolConnections() { Properties props = new Properties(); props.setProperty("user", "user"); props.setProperty("password", "password"); PoolableDataSource src = DataSourceFactory.create("jdbc:mysql:localhost:3306/athenz", props); assertNotNull(src); src.clearPoolConnections(); }