[Proxool-cvs] proxool/src/java-test/org/logicalcobwebs/proxool HouseKeeperTest.java,1.7,1.8
UNMAINTAINED!
Brought to you by:
billhorsman
From: <bil...@us...> - 2003-09-30 18:40:20
|
Update of /cvsroot/proxool/proxool/src/java-test/org/logicalcobwebs/proxool In directory sc8-pr-cvs1:/tmp/cvs-serv30555 Modified Files: HouseKeeperTest.java Log Message: New tests for test-before-use and test-after-use Index: HouseKeeperTest.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java-test/org/logicalcobwebs/proxool/HouseKeeperTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** HouseKeeperTest.java 11 Sep 2003 23:58:05 -0000 1.7 --- HouseKeeperTest.java 30 Sep 2003 18:40:16 -0000 1.8 *************** *** 11,14 **** --- 11,16 ---- import java.sql.Connection; import java.sql.DriverManager; + import java.sql.Statement; + import java.sql.SQLException; import java.util.Properties; *************** *** 104,107 **** --- 106,222 ---- } + /** + * Test that house keeper destroys connections that fail configured + * the test sql + */ + public void testInvalidBeforeUse() throws Exception { + + String testName = "invalidBeforeUse"; + 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.HOUSE_KEEPING_TEST_SQL_PROPERTY, "Invalid test"); + info.setProperty(ProxoolConstants.TEST_BEFORE_USE_PROPERTY, Boolean.TRUE.toString()); + info.setProperty(ProxoolConstants.VERBOSE_PROPERTY, Boolean.TRUE.toString()); + info.setProperty(ProxoolConstants.TRACE_PROPERTY, Boolean.TRUE.toString()); + ProxoolFacade.registerConnectionPool(url, info); + + // This should trigger a test followed the actual executed command. Because we've + // deliberately made the test invalid, we should get an exception when getting a + // connection + Connection connection = null; + Statement s = null; + try { + connection = DriverManager.getConnection(url); + s = connection.createStatement(); + s.execute(TestConstants.HYPERSONIC_TEST_SQL); + fail("Expected to get an exception because the test failed"); + } catch (SQLException e) { + LOG.debug("Expected exception.", e); + } + + } + + /** + * Test that house keeper destroys connections that fail configured + * the test sql + */ + public void testInvalidAfterUse() throws Exception { + + String testName = "invalidAfterUse"; + 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.HOUSE_KEEPING_TEST_SQL_PROPERTY, "Invalid test"); + info.setProperty(ProxoolConstants.TEST_AFTER_USE_PROPERTY, Boolean.TRUE.toString()); + info.setProperty(ProxoolConstants.VERBOSE_PROPERTY, Boolean.TRUE.toString()); + info.setProperty(ProxoolConstants.TRACE_PROPERTY, Boolean.TRUE.toString()); + ProxoolFacade.registerConnectionPool(url, info); + + // This should trigger a test as soon as we close the connection. Because we've + // deliberately made the test invalid then it should get thrown away + Connection connection = null; + Statement s = null; + try { + connection = DriverManager.getConnection(url); + s = connection.createStatement(); + s.execute(TestConstants.HYPERSONIC_TEST_SQL); + } finally { + if (connection != null) { + connection.close(); + } + } + + // There should be no available connections. We don't have a minimum setup and the one we + // just created on demand got thrown away because it failed its test + assertEquals("Available connections", 0, ProxoolFacade.getSnapshot(alias).getAvailableConnectionCount()); + + } + + public void testBeforeAndAfterUse() throws Exception { + + String testName = "beforeAndAfterUse"; + 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.HOUSE_KEEPING_TEST_SQL_PROPERTY, TestConstants.HYPERSONIC_TEST_SQL); + info.setProperty(ProxoolConstants.TEST_BEFORE_USE_PROPERTY, Boolean.TRUE.toString()); + info.setProperty(ProxoolConstants.TEST_AFTER_USE_PROPERTY, Boolean.TRUE.toString()); + info.setProperty(ProxoolConstants.VERBOSE_PROPERTY, Boolean.TRUE.toString()); + info.setProperty(ProxoolConstants.TRACE_PROPERTY, Boolean.TRUE.toString()); + ProxoolFacade.registerConnectionPool(url, info); + + Connection connection = null; + Statement s = null; + try { + connection = DriverManager.getConnection(url); + s = connection.createStatement(); + s.execute(TestConstants.HYPERSONIC_TEST_SQL); + } finally { + if (connection != null) { + connection.close(); + } + } + + // There should be one available connection. + assertEquals("Available connections", 1, ProxoolFacade.getSnapshot(alias).getAvailableConnectionCount()); + + } + } *************** *** 110,113 **** --- 225,231 ---- Revision history: $Log$ + 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 |