List of usage examples for org.apache.commons.configuration ConfigurationException printStackTrace
public void printStackTrace()
From source file:jdbc.pool.JDBCPoolMySQLTest.java
/** * Test case for FIFO Algorithm with Maximum JDBC Usage parameter. *///from ww w. j a v a 2s . c o m public void testFIFOAlgorithm() { testGetInstanceNull(); logger.debug("testFIFOAlgorithm with Maximum Usage Counter Start."); try { CConnectionPoolManager manager = create(); Connection realCon = null; Connection con = manager.getConnection("FIFO"); //It has 3 iniital connections. if (con instanceof ConnectionWrapper) { ConnectionWrapper wrapper = (ConnectionWrapper) con; realCon = wrapper.realConnection(); } else { fail("Connection returned is not an instance of ConnectionWrapper"); } con.close(); for (int i = 2; i <= (3 * 4) - 3; i++) { // 3 (no. of con) * 4 (max jdbc usage) - 2 (to bring the original on top.) con = manager.getConnection("FIFO"); con.close(); assertFalse("Connection must be active #" + i, realCon.isClosed()); } con = manager.getConnection("FIFO"); con.close(); assertTrue("Connection must be active", realCon.isClosed()); manager.destroy(true); } catch (ConfigurationException e) { e.printStackTrace(); fail("Caught ConfigurationException"); } catch (ParseException e) { e.printStackTrace(); fail("Caught ParseException"); } catch (IOException e) { e.printStackTrace(); fail("Caught IOException"); } catch (SQLException e) { e.printStackTrace(); fail("Caught SQLException"); } catch (ClassNotFoundException e) { e.printStackTrace(); fail("Caught ClassNotFoundException"); } logger.debug("testFIFOAlgorithm with Maximum Usage Counter End."); }
From source file:jdbc.pool.JDBCPoolMySQLTest.java
/** * Test case for LIFO Algorithm with Maximum JDBC Usage parameter. *//*from w w w .jav a 2 s.c o m*/ public void testLIFOAlgorithm() { testGetInstanceNull(); logger.debug("testLIFOAlgorithm with Maximum Usage Counter Start."); try { CConnectionPoolManager manager = create(); Connection realCon = null; Connection con = manager.getConnection("LIFO"); //It has 3 iniital connections. if (con instanceof ConnectionWrapper) { ConnectionWrapper wrapper = (ConnectionWrapper) con; realCon = wrapper.realConnection(); } else { fail("Connection returned is not an instance of ConnectionWrapper"); } con.close(); con = manager.getConnection("LIFO"); con.close(); assertFalse("Connection must be active", realCon.isClosed()); con = manager.getConnection("LIFO"); con.close(); assertFalse("Connection must be active", realCon.isClosed()); con = manager.getConnection("LIFO"); con.close(); assertTrue("Connection must be active", realCon.isClosed()); manager.destroy(true); } catch (ConfigurationException e) { e.printStackTrace(); fail("Caught ConfigurationException"); } catch (ParseException e) { e.printStackTrace(); fail("Caught ParseException"); } catch (IOException e) { e.printStackTrace(); fail("Caught IOException"); } catch (SQLException e) { e.printStackTrace(); fail("Caught SQLException"); } catch (ClassNotFoundException e) { e.printStackTrace(); fail("Caught ClassNotFoundException"); } logger.debug("testLIFOAlgorithm with Maximum Usage Counter End."); }
From source file:jdbc.pool.JDBCPoolMySQLTest.java
public void testGetAllPoolStatistics() { testGetInstanceNull();/*from www.j a va2 s . c om*/ try { CConnectionPoolManager manager = null; manager = create(); Connection con = manager.getConnection("MYSQL2"); CPoolStatisticsBean beanOracle = manager.getPoolStatistics("MYSQL2"); assertEquals("pool name", "MYSQL2", beanOracle.getPoolName()); assertEquals("Bad Connections Count", 0, beanOracle.getBadConnectionCount()); assertEquals("Connections High Count", 1, beanOracle.getConnectionsHighCount()); assertEquals("Current Free Connections", 0, beanOracle.getCurrentFreeConnectionCount()); assertEquals("Current Used Connection count", 1, beanOracle.getCurrentUsedConnectionCount()); assertEquals("Leaked Connection Count", 0, beanOracle.getLeakedConnectionCount()); assertEquals("Leaked Statement Count", 0, beanOracle.getLeakedStatementCount()); assertEquals("Leaked ResultSet Count", 0, beanOracle.getLeakedResultSetCount()); // CPoolStatisticsBean beanMySQL = manager.getPoolStatistics("MYSQL"); assertEquals("pool name", "MYSQL", beanMySQL.getPoolName()); assertEquals("Bad Connections Count", 0, beanMySQL.getBadConnectionCount()); assertEquals("Connections High Count", 0, beanMySQL.getConnectionsHighCount()); assertEquals("Current Free Connections", 3, beanMySQL.getCurrentFreeConnectionCount()); assertEquals("Current Used Connection count", 0, beanMySQL.getCurrentUsedConnectionCount()); assertEquals("Leaked Connection Count", 0, beanMySQL.getLeakedConnectionCount()); assertEquals("Leaked Statement Count", 0, beanMySQL.getLeakedStatementCount()); assertEquals("Leaked ResultSet Count", 0, beanMySQL.getLeakedResultSetCount()); con.close(); manager.destroy(true); } catch (ConfigurationException e) { e.printStackTrace(); fail("Caught ConfigurationException"); } catch (ParseException e) { e.printStackTrace(); fail("Caught ParseException"); } catch (IOException e) { e.printStackTrace(); fail("Caught IOException"); } catch (SQLException e) { e.printStackTrace(); fail("Caught SQLException"); } catch (ClassNotFoundException e) { e.printStackTrace(); fail("Caught ClassNotFoundException"); } }
From source file:jdbc.pool.JDBCPoolMySQLTest.java
@Test public void testParameterPrints() { testGetInstanceNull();//from w w w . j ava 2 s . co m logger.debug("testParameterPrints Start."); CConnectionPoolManager manager = null; Connection con = null; //It has 3 iniital connections. PreparedStatement st; try { manager = create(); con = manager.getConnection("MYSQL"); st = con.prepareStatement("SELECT * from process_request where req_id = ?"); st.setLong(1, 1); ResultSet rs = st.executeQuery(); while (rs.next()) { //do nothing } st.close(); } catch (ConfigurationException e) { e.printStackTrace(); fail("Caught ConfigurationException"); } catch (ParseException e) { e.printStackTrace(); fail("Caught ParseException"); } catch (IOException e) { e.printStackTrace(); fail("Caught IOException"); } catch (SQLException e) { e.printStackTrace(); fail("Caught SQLException"); } catch (ClassNotFoundException e) { e.printStackTrace(); fail("Caught ClassNotFoundException"); } finally { if (con != null) { try { con.close(); } catch (SQLException e) { e.printStackTrace(); } } if (manager != null) { manager.destroy(true); } } logger.debug("testParameterPrints End."); }
From source file:jdbc.pool.JDBCPoolMySQLTest.java
/** * Test if JDBC connection is getting closed after crossing the maximum * usage per JDBC connection.//from w ww .j av a2 s. c o m * */ public void testMaxUsagePerJDBCConnection() { testGetInstanceNull(); logger.debug("testMaxUsagePerJDBCConnection start."); CConnectionPoolManager manager = null; try { manager = create(); Connection realCon = null; Connection con = manager.getConnection("MYSQL2"); if (con instanceof ConnectionWrapper) { ConnectionWrapper wrapper = (ConnectionWrapper) con; realCon = wrapper.realConnection(); } else { fail("Connection returned is not an instance of ConnectionWrapper"); } con.close(); assertFalse("Connection must be active", realCon.isClosed()); // 2 con = manager.getConnection("MYSQL2"); con.close(); assertFalse("Connection must be active", realCon.isClosed()); // 3 con = manager.getConnection("MYSQL2"); assertFalse("Connection must be active", realCon.isClosed()); con.close(); assertFalse("Connection must be active", realCon.isClosed()); // 4 con = manager.getConnection("MYSQL2"); con.close(); assertTrue("Connection must be closed", realCon.isClosed()); } catch (ConfigurationException e) { e.printStackTrace(); fail("Caught ConfigurationException"); } catch (ParseException e) { e.printStackTrace(); fail("Caught ParseException"); } catch (IOException e) { e.printStackTrace(); fail("Caught IOException"); } catch (SQLException e) { e.printStackTrace(); fail("Caught SQLException"); } catch (ClassNotFoundException e) { e.printStackTrace(); fail("Caught ClassNotFoundException"); } finally { if (manager != null) { manager.destroy(true); } } logger.debug("testMaxUsagePerJDBCConnection end."); }
From source file:jdbc.pool.JDBCPoolMySQLTest.java
/** * Tests Inactive time out closing of the JDBC Connection. * //from w ww .java2 s . c om * Check whether the connection returns back to the pool. */ public void testInactiveTimeout() { testGetInstanceNull(); logger.debug("testInactiveTimeout Start."); CConnectionPoolManager manager = null; try { manager = create(); Connection conOra1 = manager.getConnection("MYSQL2"); Connection realCon = null; Connection conOra2 = manager.getConnection("MYSQL2"); if (conOra2 instanceof ConnectionWrapper) { ConnectionWrapper wrapper = (ConnectionWrapper) conOra2; realCon = wrapper.realConnection(); } else { fail("Connection returned is not an instance of ConnectionWrapper"); } conOra2.close(); try { // 4 = 1 + 3 + (1) As the maximum time in which the con will be // closed is 4 have an additional 1 minute extra Thread.sleep(5 * 60 * 1000, 999999); // Shrink Pool Interval 1 minute + Inactive timeout 3 mins. } catch (InterruptedException e1) { e1.printStackTrace(); } assertTrue("Real Connection is closed", realCon.isClosed()); conOra1.close(); CPoolStatisticsBean bean = manager.getPoolStatistics("MYSQL2"); assertEquals("Pool Name", "MYSQL2", bean.getPoolName()); logger.debug("********************************************************"); ArrayList<CPoolStatisticsBean> al = manager.getPoolStatisticsHistory("MYSQL2"); assertTrue("Statistics History Count", 5 >= al.size()); for (CPoolStatisticsBean element : al) { logger.debug(element.toString()); } logger.debug("********************************************************"); } catch (ConfigurationException e) { e.printStackTrace(); fail("Caught ConfigurationException"); } catch (ParseException e) { e.printStackTrace(); fail("Caught ParseException"); } catch (IOException e) { e.printStackTrace(); fail("Caught IOException"); } catch (SQLException e) { e.printStackTrace(); fail("Caught SQLException"); } catch (ClassNotFoundException e) { e.printStackTrace(); fail("Caught ClassNotFoundException"); } finally { manager.destroy(true); } logger.debug("testInactiveTimeout end."); }
From source file:jdbc.pool.JDBCPoolMySQLTest.java
/** * Tests the get methods of CPoolAttribute for pools MYSQL2 and MYSQL. * *//*from ww w . ja va 2 s . co m*/ public void testCPoolAttributeGET() { testGetInstanceNull(); CConnectionPoolManager manager = null; try { manager = create(); CPoolAttribute attribOraclePool = CConnectionPoolManager.getInstance().getPoolAttributes("MYSQL2"); CPoolAttribute attribMySqlPool = CConnectionPoolManager.getInstance().getPoolAttributes("MYSQL"); assertEquals("Capacity Increament", 1, attribOraclePool.getCapacityIncreament()); assertEquals("Capacity Increament", 2, attribMySqlPool.getCapacityIncreament()); assertEquals("Connection Idle Timeout", 3, attribOraclePool.getConnectionIdleTimeout()); assertEquals("Connection Idle Timeout", 5, attribMySqlPool.getConnectionIdleTimeout()); // assertEquals("Driver", "oracle.jdbc.driver.OracleDriver", attribOraclePool.getDriver()); assertEquals("Driver", "com.mysql.jdbc.Driver", attribMySqlPool.getDriver()); assertEquals("Initial Pool Size", 1, attribOraclePool.getInitialPoolSize()); assertEquals("Initial Pool Size", 3, attribMySqlPool.getInitialPoolSize()); assertEquals("Maximum Capacity", 5, attribOraclePool.getMaximumCapacity()); assertEquals("Maximum Capacity", 50, attribMySqlPool.getMaximumCapacity()); assertNotNull("Password not null", attribOraclePool.getPassword()); assertNotNull("Password not null", attribMySqlPool.getPassword()); assertEquals("Pool Name", "MYSQL2", attribOraclePool.getPoolName()); assertEquals("Pool Name", "MYSQL", attribMySqlPool.getPoolName()); assertEquals("Shrink Pool Interval", 1, attribOraclePool.getShrinkPoolInterval()); assertEquals("Shrink Pool Interval", 1, attribMySqlPool.getShrinkPoolInterval()); // assertEquals("URL", "jdbc:MYSQL2:thin:@192.100.192.114:1521:SUN2DB1", attribOraclePool.getURL()); assertEquals("URL", "jdbc:mysql://localhost/pre", attribMySqlPool.getURL()); // assertEquals("USER", "rendev", attribOraclePool.getUser()); assertEquals("USER", "root", attribOraclePool.getUser()); assertEquals("USER", "root", attribMySqlPool.getUser()); assertEquals("VENDOR", "MYSQL2", attribOraclePool.getVendor()); assertEquals("VENDOR", "MySQL", attribMySqlPool.getVendor()); assertEquals("Critical Operation Time Limit", 1000, attribOraclePool.getCriticalOperationTimeLimit()); assertEquals("Critical Operation Time Limit", 10000, attribMySqlPool.getCriticalOperationTimeLimit()); assertEquals("In Use Wait Time", 7, attribOraclePool.getInUseWaitTime()); assertEquals("In Use Wait Time", 10, attribMySqlPool.getInUseWaitTime()); assertEquals("Load On Startup", false, attribOraclePool.isLoadOnStartup()); assertEquals("Load On Startup", true, attribMySqlPool.isLoadOnStartup()); assertEquals("Maximum Capacity", 4, attribOraclePool.getMaxUsagePerJDBCConnection()); assertEquals("Maximum Capacity", -1, attribMySqlPool.getMaxUsagePerJDBCConnection()); } catch (ConfigurationException e) { e.printStackTrace(); fail("Caught ConfigurationException"); } catch (ParseException e) { e.printStackTrace(); fail("Caught ParseException"); } catch (IOException e) { e.printStackTrace(); fail("Caught IOException"); } catch (SQLException e) { e.printStackTrace(); fail("Caught SQLException"); } catch (ClassNotFoundException e) { e.printStackTrace(); fail("Caught ClassNotFoundException"); } finally { manager.destroy(true); } }
From source file:jdbc.pool.JDBCPoolMySQLTest.java
/** * Test case for Statement Caching./*from w ww . j ava 2s . co m*/ */ public void testStatementCaching() { testGetInstanceNull(); logger.debug("testStatementCaching Start."); CConnectionPoolManager manager = null; Connection con = null; //It has 3 iniital connections. PreparedStatement st; PreparedStatement st1; try { manager = create(); con = manager.getConnection("MYSQL2"); st = con.prepareStatement("SELECT count(*) FROM DUAL"); PreparedStatement realPsm = null; if (st instanceof PreparedStatementWrapper) { PreparedStatementWrapper wrapper = (PreparedStatementWrapper) st; realPsm = (PreparedStatement) wrapper.realStatement(); } else { fail("Instanceof failed"); } st.execute(); st1 = con.prepareStatement("SELECT count(*) FROM DUAL"); if (st1 instanceof PreparedStatementWrapper) { PreparedStatementWrapper wrapper = (PreparedStatementWrapper) st1; realPsm = (PreparedStatement) wrapper.realStatement(); assertEquals("Statement Cache", realPsm, (PreparedStatement) wrapper.realStatement()); } else { con.close(); fail("Instanceof failed"); } } catch (ConfigurationException e) { e.printStackTrace(); fail("Caught ConfigurationException"); } catch (ParseException e) { e.printStackTrace(); fail("Caught ParseException"); } catch (IOException e) { e.printStackTrace(); fail("Caught IOException"); } catch (SQLException e) { e.printStackTrace(); fail("Caught SQLException"); } catch (ClassNotFoundException e) { e.printStackTrace(); fail("Caught ClassNotFoundException"); } finally { if (con != null) { try { con.close(); } catch (SQLException e) { e.printStackTrace(); } } if (manager != null) { manager.destroy(true); } } logger.debug("testStatementCaching End."); }
From source file:jdbc.pool.JDBCPoolMySQLTest.java
/** * Tests Inactive Timeout for -1 or 0 value. * This pool has different set of parameters as compared to MYSQL pool and this forces the behaviour changes * in the pool. The connections will not be pooled and therefore the connections will be closed upon release. *//* w w w.j av a 2s.c o m*/ public void testTIT() { testGetInstanceNull(); logger.debug("testTIT Start."); CConnectionPoolManager manager = null; try { manager = create(); CPoolAttribute attrib = manager.getPoolAttributes("TIT"); assertEquals("Driver", "com.mysql.jdbc.Driver", attrib.getDriver()); assertEquals("Vendor", "MySQL", attrib.getVendor()); assertEquals("URL", "jdbc:mysql://localhost/pre", attrib.getURL()); assertEquals("User", "root", attrib.getUser()); // assertEquals("Password", "=?UTF-8?B?cm9vdA==?=", attrib.getPassword()); assertEquals("Initial Pool Size", 3, attrib.getInitialPoolSize()); assertEquals("Capacity Increament", 2, attrib.getCapacityIncreament()); assertEquals("Maximum Capacity", 50, attrib.getMaximumCapacity()); assertEquals("Connection Idle Timeout", -1, attrib.getConnectionIdleTimeout()); assertEquals("Shrink Pool Interval", 1, attrib.getShrinkPoolInterval()); assertEquals("Critical Operation Timelimit", 10000, attrib.getCriticalOperationTimeLimit()); assertEquals("In Use wait time", 10, attrib.getInUseWaitTime()); assertFalse("load-on-startup", attrib.isLoadOnStartup()); Connection conOra1 = manager.getConnection("TIT"); Connection realCon = null; if (conOra1 instanceof ConnectionWrapper) { ConnectionWrapper wrapper = (ConnectionWrapper) conOra1; realCon = wrapper.realConnection(); } else { fail("Connection returned is not an instance of ConnectionWrapper"); } conOra1.close(); assertTrue("Connection must get closed as the inactive-time-out <= 0", realCon.isClosed()); attrib = manager.getPoolAttributes("TIT"); assertEquals("Driver", "com.mysql.jdbc.Driver", attrib.getDriver()); assertEquals("Vendor", "MySQL", attrib.getVendor()); assertEquals("URL", "jdbc:mysql://localhost/pre", attrib.getURL()); assertEquals("User", "root", attrib.getUser()); // assertEquals("Password", "gPa8lK4P+Bk=", attrib.getPassword()); assertEquals("Initial Pool Size", 0, attrib.getInitialPoolSize()); assertEquals("Capacity Increament", 1, attrib.getCapacityIncreament()); assertEquals("Maximum Capacity", 50, attrib.getMaximumCapacity()); assertEquals("Connection Idle Timeout", -1, attrib.getConnectionIdleTimeout()); assertEquals("Shrink Pool Interval", -1, attrib.getShrinkPoolInterval()); assertEquals("Critical Operation Timelimit", 10000, attrib.getCriticalOperationTimeLimit()); assertEquals("In Use wait time", 10, attrib.getInUseWaitTime()); assertFalse("load-on-startup", attrib.isLoadOnStartup()); } catch (ConfigurationException e) { e.printStackTrace(); fail("Caught ConfigurationException"); } catch (ParseException e) { e.printStackTrace(); fail("Caught ParseException"); } catch (IOException e) { e.printStackTrace(); fail("Caught IOException"); } catch (SQLException e) { e.printStackTrace(); fail("Caught SQLException"); } catch (ClassNotFoundException e) { e.printStackTrace(); fail("Caught ClassNotFoundException"); } finally { manager.destroy(true); } logger.debug("testTIT end."); }
From source file:jdbc.pool.JDBCPoolMySQLTest.java
/** * Test case for ResultSet leak./* w ww.j a v a 2s . c o m*/ */ public void testResultSetLeak() { testGetInstanceNull(); logger.debug("testResultSetLeak Start."); CConnectionPoolManager manager = null; Connection con = null; //It has 3 iniital connections. PreparedStatement st; try { manager = create(); con = manager.getConnection("MYSQL2"); st = con.prepareStatement("SELECT 'A' FROM DUAL UNION SELECT 'B' FROM DUAL"); ResultSet rs = st.executeQuery(); while (rs.next()) { //do nothing } st.close(); CPoolStatisticsBean bean = manager.getPoolStatistics("MYSQL2"); assertEquals("Pool Name", "MYSQL2", bean.getPoolName()); assertEquals("Bad Connections Count", 0, bean.getBadConnectionCount()); assertEquals("Connections High Count", 1, bean.getConnectionsHighCount()); assertEquals("Current Free Connections", 0, bean.getCurrentFreeConnectionCount()); assertEquals("Current Used Connection count", 1, bean.getCurrentUsedConnectionCount()); assertEquals("Leaked Connection Count", 0, bean.getLeakedConnectionCount()); assertEquals("Leaked Statement Count", 0, bean.getLeakedStatementCount()); assertEquals("Leaked ResultSet Count", 1, bean.getLeakedResultSetCount()); st = con.prepareStatement("SELECT 'A' FROM DUAL UNION SELECT 'B' FROM DUAL"); rs = st.executeQuery(); while (rs.next()) { //do nothing } st.close(); bean = manager.getPoolStatistics("MYSQL2"); assertEquals("Pool Name", "MYSQL2", bean.getPoolName()); assertEquals("Bad Connections Count", 0, bean.getBadConnectionCount()); assertEquals("Connections High Count", 1, bean.getConnectionsHighCount()); assertEquals("Current Free Connections", 0, bean.getCurrentFreeConnectionCount()); assertEquals("Current Used Connection count", 1, bean.getCurrentUsedConnectionCount()); assertEquals("Leaked Connection Count", 0, bean.getLeakedConnectionCount()); assertEquals("Leaked Statement Count", 0, bean.getLeakedStatementCount()); assertEquals("Leaked ResultSet Count", 2, bean.getLeakedResultSetCount()); } catch (ConfigurationException e) { e.printStackTrace(); fail("Caught ConfigurationException"); } catch (ParseException e) { e.printStackTrace(); fail("Caught ParseException"); } catch (IOException e) { e.printStackTrace(); fail("Caught IOException"); } catch (SQLException e) { e.printStackTrace(); fail("Caught SQLException"); } catch (ClassNotFoundException e) { e.printStackTrace(); fail("Caught ClassNotFoundException"); } finally { if (con != null) { try { con.close(); } catch (SQLException e) { e.printStackTrace(); } } if (manager != null) { manager.destroy(true); } } logger.debug("testStatementCaching End."); }