use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class DruidPooledConnectionTest1 method test_dup_close.
public void test_dup_close() throws Exception {
DruidPooledConnection conn = (DruidPooledConnection) dataSource.getConnection();
conn.close();
conn.close();
Assert.assertEquals(1, dataSource.getRecycleCount());
Assert.assertEquals(1, dataSource.getCloseCount());
Assert.assertEquals(1, dataSource.getPoolingCount());
Assert.assertEquals(0, dataSource.getActiveCount());
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class DruidDataSourceTest_recycle2 method f_test_recycle_error_interrupt.
public void f_test_recycle_error_interrupt() throws Exception {
final AtomicReference<Exception> errorRef = new AtomicReference<Exception>();
final CountDownLatch closeBeforeLatch = new CountDownLatch(1);
final CountDownLatch lockLatch = new CountDownLatch(1);
final CountDownLatch endLatch = new CountDownLatch(1);
Thread thread = new Thread() {
public void run() {
try {
DruidPooledConnection conn = dataSource.getConnection();
conn.setAutoCommit(false);
conn.setReadOnly(false);
Statement stmt = conn.createStatement();
stmt.execute("select 1");
Assert.assertEquals(0, dataSource.getPoolingCount());
Assert.assertEquals(1, dataSource.getActiveCount());
closeBeforeLatch.countDown();
lockLatch.await();
conn.close();
} catch (Exception e) {
errorRef.set(e);
} finally {
endLatch.countDown();
}
}
};
thread.start();
Assert.assertTrue(closeBeforeLatch.await(1, TimeUnit.SECONDS));
dataSource.getLock().lock();
lockLatch.countDown();
Thread.sleep(10);
thread.interrupt();
Assert.assertTrue(endLatch.await(1, TimeUnit.MINUTES));
Exception error = errorRef.get();
Assert.assertNull(error);
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class DruidDataSourceTest_recycle2 method test_recycle_error.
public void test_recycle_error() throws Exception {
DruidPooledConnection conn = dataSource.getConnection();
conn.setAutoCommit(false);
conn.setReadOnly(false);
Statement stmt = conn.createStatement();
stmt.execute("select 1");
Assert.assertEquals(0, dataSource.getPoolingCount());
Assert.assertEquals(1, dataSource.getActiveCount());
Exception error = null;
try {
conn.close();
} catch (Exception e) {
error = e;
}
Assert.assertNull(error);
{
Connection conn2 = dataSource.getConnection();
conn2.close();
}
Assert.assertEquals(1, dataSource.getPoolingCount());
Assert.assertEquals(0, dataSource.getActiveCount());
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class DruidDataSourceTest_recycle method test_recycle.
public void test_recycle() throws Exception {
DruidPooledConnection conn = dataSource.getConnection();
conn.setAutoCommit(false);
conn.setReadOnly(false);
Statement stmt = conn.createStatement();
stmt.execute("select 1");
conn.close();
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class DruidDataSourceTest_tryGet method test_0.
public void test_0() throws Exception {
DruidPooledConnection conn1 = this.dataSource.tryGetConnection();
Assert.assertNotNull(conn1);
DruidPooledConnection conn2 = this.dataSource.tryGetConnection();
Assert.assertNull(conn2);
conn1.close();
}
Aggregations