public void test_activeTrace() throws Exception { for (int i = 0; i < 1000 * 1000; ++i) { dataSource.shrink(); Connection conn = dataSource.getConnection(); conn.close(); // Assert.assertEquals(1, dataSource.getPoolingCount()); dataSource.shrink(); Assert.assertEquals( "createCount : " + dataSource.getCreateCount(), 0, dataSource.getPoolingCount()); Assert.assertEquals(0, dataSource.getActiveConnections().size()); } }
public void test_stmtCache() throws Exception { for (int j = 0; j < 10; ++j) { for (int i = 0; i < 10; ++i) { Connection conn = dataSource.getConnection(); String sql = "SELECT" + i; PreparedStatement stmt = conn.prepareStatement(sql); stmt.execute(); stmt.close(); conn.close(); } } dataSource.setPoolPreparedStatements(true); for (int j = 0; j < 10; ++j) { for (int i = 0; i < 10; ++i) { Connection conn = dataSource.getConnection(); String sql = "SELECT" + i; PreparedStatement stmt = conn.prepareStatement(sql); stmt.execute(); stmt.close(); conn.close(); } } for (int i = 0; i < 1000 * 1; ++i) { Connection conn = dataSource.getConnection(); PreparedStatement stmt = conn.prepareStatement("SELECT " + i); stmt.execute(); stmt.close(); conn.close(); } Connection conn = dataSource.getConnection(); DruidPooledConnection poolableConn = conn.unwrap(DruidPooledConnection.class); Assert.assertNotNull(poolableConn); Assert.assertEquals( dataSource.getMaxPoolPreparedStatementPerConnectionSize(), poolableConn.getConnectionHolder().getStatementPool().getMap().size()); conn.close(); Assert.assertEquals(0, dataSource.getActiveCount()); Assert.assertEquals(1, dataSource.getPoolingCount()); }