use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class DruidPooledConnectionTest method test_isDiable.
public void test_isDiable() throws Exception {
DruidPooledConnection conn = (DruidPooledConnection) dataSource.getConnection();
Assert.assertEquals(false, conn.isDisable());
conn.close();
Assert.assertEquals(true, conn.isDisable());
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class DruidPooledConnectionTest method test_disable.
public void test_disable() throws Exception {
Assert.assertEquals(0, dataSource.getPoolingCount());
Assert.assertEquals(0, dataSource.getActiveCount());
DruidPooledConnection conn = (DruidPooledConnection) dataSource.getConnection();
conn.disable();
Assert.assertEquals(true, conn.isDisable());
Assert.assertEquals(1, dataSource.getActiveCount());
conn.close();
Assert.assertEquals(0, dataSource.getPoolingCount());
Assert.assertEquals(1, dataSource.getActiveCount());
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class DruidPooledConnectionTest method test_getOwnerThread.
public void test_getOwnerThread() throws Exception {
DruidPooledConnection conn = (DruidPooledConnection) dataSource.getConnection();
Assert.assertEquals(Thread.currentThread(), conn.getOwnerThread());
conn.close();
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class DruidPooledConnectionTest method test_dupClose.
public void test_dupClose() throws Exception {
DruidPooledConnection conn = (DruidPooledConnection) dataSource.getConnection();
conn.close();
conn.close();
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class AsyncCloseTest3 method loop.
protected void loop() throws InterruptedException {
dataSource.shrink();
Assert.assertEquals(0, dataSource.getActiveCount());
Assert.assertEquals(0, dataSource.getPoolingCount());
final int COUNT;
if (xmx <= 256) {
COUNT = 1024 * 8;
} else if (xmx <= 512) {
COUNT = 1024 * 16;
} else if (xmx <= 1024) {
COUNT = 1024 * 32;
} else if (xmx <= 2048) {
COUNT = 1024 * 64;
} else {
COUNT = 1024 * 128;
}
final CountDownLatch closeLatch = new CountDownLatch(COUNT * 2);
final CountDownLatch execLatch = new CountDownLatch(COUNT);
Runnable connTask = new Runnable() {
@Override
public void run() {
try {
DruidPooledConnection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
CloseTask closeTask = new CloseTask(conn, closeLatch);
try {
stmt.execute("select 1");
} finally {
closeExecutor.submit(closeTask);
// dup close
closeExecutor.submit(closeTask);
stmt.close();
conn.close();
}
} catch (SQLException e) {
errorCount.incrementAndGet();
} finally {
execLatch.countDown();
}
}
};
for (int i = 0; i < COUNT; ++i) {
connExecutor.submit(connTask);
}
execLatch.await();
closeLatch.await();
Assert.assertEquals(0, dataSource.getActiveCount());
}
Aggregations