public void testStopPoolResetsConnectionCount() { pool.checkout(); pool.checkout(); assertTrue(pool.connections > 0); pool.stopPool(); assertEquals(0, pool.connections); }
public void testGetInstanceCreatesNewPoolForNewApplication() { ConnectionPool def, defByName, other = null; try { def = ConnectionPool.getInstance(); defByName = ConnectionPool.getInstance(DEFAULT); other = ConnectionPool.getInstance(OTHER_APP_NAME); // default should still be defByName assertEquals(def, defByName); // others's should be different assertFalse(def == other); } finally { if (other != null) other.stopPool(); } }
public void testStopPoolClearsAvailableAndInUseConnections() { // create 1 in-use and 1 available connection Connection conn1 = pool.checkout(); pool.checkout(); pool.checkin(conn1); assertEquals(1, pool.inUse.size()); assertEquals(1, pool.available.size()); // invoke stopPool() pool.stopPool(); // check that both maps have been cleared assertEquals(0, pool.inUse.size()); assertEquals(0, pool.available.size()); }
@Override protected void tearDown() throws Exception { // stop pool pool.stopPool(); pool = null; // drop test databases DBUtils.dropDB(TEST_DB1_NAME); DBUtils.dropDB(TEST_DB2_NAME); // restore default database name otherDbUtils.setDbDatabaseName(null); defaultDbUtils.setDbDatabaseName(null); defaultDbUtils = otherDbUtils = null; super.tearDown(); }
public void testStopPoolClosesAvailableAndInUseConnections() throws SQLException { // create 1 in-use and 2 available connection Connection conn1 = pool.checkout(); Connection conn2 = pool.checkout(); Connection conn3 = pool.checkout(); pool.checkin(conn1); pool.checkin(conn2); assertFalse(conn1.isClosed()); assertFalse(conn2.isClosed()); assertFalse(conn3.isClosed()); // invoke stopPool() pool.stopPool(); // check that both connections are closed assertTrue(conn1.isClosed()); assertTrue(conn2.isClosed()); assertTrue(conn3.isClosed()); }
public void testMultipleConnectionPools() { // check the number of available connections in the pool assertEquals(0, pool.getNumberAvailableConnections()); // checkout a default db connection Connection conn = pool.checkout(); pool.checkin(conn); assertEquals(1, pool.getNumberAvailableConnections()); // checkout a tigerprawn db connection ConnectionPool tp = ConnectionPool.getInstance(OTHER_APP_NAME); try { assertNotSame(pool, tp); assertEquals(0, tp.getNumberAvailableConnections()); conn = tp.checkout(); tp.checkin(conn); assertEquals(1, pool.getNumberAvailableConnections()); assertEquals(1, tp.getNumberAvailableConnections()); } finally { if (tp != null) tp.stopPool(); } }