use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class TestPoolPreparedStatement2 method test_stmtCache.
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 < 10 * 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());
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class TestRemoveAbandoned2 method test_removeAbandoned.
public void test_removeAbandoned() throws Exception {
{
Connection conn = dataSource.getConnection();
conn.close();
}
Assert.assertEquals(0, dataSource.getActiveCount());
Thread abandonThread = new Thread("abandoned") {
public void run() {
for (; ; ) {
dataSource.removeAbandoned();
if (Thread.interrupted()) {
break;
}
}
}
};
abandonThread.start();
for (int i = 0; i < 1000 * 100; ++i) {
DruidPooledConnection conn = dataSource.getConnection();
conn.close();
}
Assert.assertEquals(0, dataSource.getActiveCount());
abandonThread.interrupt();
System.out.println("removeAbandondedCount : " + dataSource.getRemoveAbandonedCount());
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class UrlNotSetTest method test_wait.
public void test_wait() throws Exception {
Exception error = null;
try {
DruidPooledConnection conn = dataSource.getConnection();
conn.close();
} catch (SQLException ex) {
error = ex;
}
assertEquals("url not set", error.getMessage());
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class InitExceptionThrowTest method test_pool.
public void test_pool() throws Exception {
DruidPooledConnection conn = dataSource.getConnection();
conn.close();
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class MaxWaitTest method test_wait.
public void test_wait() throws Exception {
Exception error = null;
try {
DruidPooledConnection conn = dataSource.getConnection();
conn.close();
} catch (SQLException ex) {
error = ex;
}
assertTrue(error.getMessage().contains("createElapseMillis "));
}
Aggregations