[Proxool-cvs] proxool/src/java-test/org/logicalcobwebs/proxool HouseKeeperTest.java,1.10,1.11
UNMAINTAINED!
Brought to you by:
billhorsman
From: <bil...@us...> - 2005-10-07 08:11:43
|
Update of /cvsroot/proxool/proxool/src/java-test/org/logicalcobwebs/proxool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13613/src/java-test/org/logicalcobwebs/proxool Modified Files: HouseKeeperTest.java Log Message: New test for reset failure Index: HouseKeeperTest.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java-test/org/logicalcobwebs/proxool/HouseKeeperTest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** HouseKeeperTest.java 2 Oct 2005 12:30:59 -0000 1.10 --- HouseKeeperTest.java 7 Oct 2005 08:11:34 -0000 1.11 *************** *** 19,25 **** * Test the house keeper in ConnectionPool * - * @version $Revision$, $Date$ * @author bill * @author $Author$ (current maintainer) * @since Proxool 0.8 */ --- 19,25 ---- * Test the house keeper in ConnectionPool * * @author bill * @author $Author$ (current maintainer) + * @version $Revision$, $Date$ * @since Proxool 0.8 */ *************** *** 38,41 **** --- 38,42 ---- public void testMaximumActiveTime() throws Exception { + ConnectionResetter.setTriggerResetException(true); String testName = "maximumActiveTime"; String alias = testName; *************** *** 56,59 **** --- 57,61 ---- final Connection connection = DriverManager.getConnection(url); + connection.setAutoCommit(false); connection.createStatement().executeQuery(TestConstants.HYPERSONIC_TEST_SQL); long start = System.currentTimeMillis(); *************** *** 102,105 **** --- 104,183 ---- /** + * Test that connections that remain active for longer than the configured + * time are closed (and destroyed) automatically. Also, it gets errors during + * reset. We don't want the connectionCount to be decremented twice. + */ + public void testMaximumActiveTimeWithResetFailure() throws Exception { + + try { + ConnectionResetter.setTriggerResetException(true); + String testName = "maximumActiveTime"; + String alias = testName; + + String url = TestHelper.buildProxoolUrl(alias, + TestConstants.HYPERSONIC_DRIVER, + TestConstants.HYPERSONIC_TEST_URL); + Properties info = new Properties(); + info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); + info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); + info.setProperty(ProxoolConstants.MAXIMUM_ACTIVE_TIME_PROPERTY, "1000"); + info.setProperty(ProxoolConstants.TRACE_PROPERTY, "true"); + info.setProperty(ProxoolConstants.HOUSE_KEEPING_SLEEP_TIME_PROPERTY, "1000"); + ProxoolFacade.registerConnectionPool(url, info); + + assertEquals("Shouldn't be any active connections yet", 0, ProxoolFacade.getSnapshot(alias, false).getServedCount()); + + final Connection connection = DriverManager.getConnection(url); + connection.setAutoCommit(false); + connection.createStatement().executeQuery(TestConstants.HYPERSONIC_TEST_SQL); + long start = System.currentTimeMillis(); + + assertEquals("We just opened 1 connection", 1, ProxoolFacade.getSnapshot(alias, false).getServedCount()); + + new ResultMonitor() { + public boolean check() throws Exception { + return connection.isClosed(); + } + }.getResult(); + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + LOG.debug("Awoken."); + } + + long elapsed = System.currentTimeMillis() - start; + assertTrue("Connection has not been closed after " + elapsed + " milliseconds as expected", connection.isClosed()); + assertEquals("Expected the connection to be inactive", 0, ProxoolFacade.getSnapshot(alias, false).getActiveConnectionCount()); + + try { + connection.createStatement().executeQuery(TestConstants.HYPERSONIC_TEST_SQL); + fail("Calling createStatement() on a closed connection should fail"); + } catch (Exception e) { + // s'okay. We expected this + LOG.debug("Ignoring expected exception: " + e.getMessage()); + } + + // Now close the connection ourselves. It's already been closed by the House Keeper but nothing bad should + // happen if we do it again now. + connection.close(); + + // Let's see if the prototyper builds another one + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + LOG.debug("Awoken."); + } + SnapshotIF snapshot = ProxoolFacade.getSnapshot(alias, false); + assertEquals("activeConnectionCount", 0, snapshot.getActiveConnectionCount()); + assertEquals("availableConnectionCount", 0, snapshot.getAvailableConnectionCount()); + assertEquals("connectionCount", 0, snapshot.getConnectionCount()); + } finally { + // Back to normal + ConnectionResetter.setTriggerResetException(false); + } + + } + + /** * Test that house keeper destroys connections that fail configured * the test sql *************** *** 247,284 **** } - /* ! Revision history: ! $Log$ ! Revision 1.10 2005/10/02 12:30:59 billhorsman ! Improved test by checking connectionCount ! Revision 1.9 2004/06/02 21:05:19 billhorsman ! Don't log worrying stack traces for expected exceptions. ! Revision 1.8 2003/09/30 18:40:16 billhorsman ! New tests for test-before-use and test-after-use ! Revision 1.7 2003/09/11 23:58:05 billhorsman ! New test for house-keeper-test-sql ! Revision 1.6 2003/03/04 10:24:40 billhorsman ! removed try blocks around each test ! Revision 1.5 2003/03/03 17:08:57 billhorsman ! all tests now extend AbstractProxoolTest ! Revision 1.4 2003/03/03 11:12:04 billhorsman ! fixed licence ! Revision 1.3 2003/03/02 00:53:49 billhorsman ! more robust wait ! Revision 1.2 2003/03/01 15:27:24 billhorsman ! checkstyle ! Revision 1.1 2003/02/27 18:01:48 billhorsman ! completely rethought the test structure. it's now ! more obvious. no new tests yet though. ! */ \ No newline at end of file --- 325,364 ---- } /* ! Revision history: ! $Log$ ! Revision 1.11 2005/10/07 08:11:34 billhorsman ! New test for reset failure ! Revision 1.10 2005/10/02 12:30:59 billhorsman ! Improved test by checking connectionCount ! Revision 1.9 2004/06/02 21:05:19 billhorsman ! Don't log worrying stack traces for expected exceptions. ! Revision 1.8 2003/09/30 18:40:16 billhorsman ! New tests for test-before-use and test-after-use ! Revision 1.7 2003/09/11 23:58:05 billhorsman ! New test for house-keeper-test-sql ! Revision 1.6 2003/03/04 10:24:40 billhorsman ! removed try blocks around each test ! Revision 1.5 2003/03/03 17:08:57 billhorsman ! all tests now extend AbstractProxoolTest ! Revision 1.4 2003/03/03 11:12:04 billhorsman ! fixed licence ! Revision 1.3 2003/03/02 00:53:49 billhorsman ! more robust wait ! Revision 1.2 2003/03/01 15:27:24 billhorsman ! checkstyle ! Revision 1.1 2003/02/27 18:01:48 billhorsman ! completely rethought the test structure. it's now ! more obvious. no new tests yet though. ! ! */ \ No newline at end of file |