Search in sources :

Example 41 with DruidPooledConnection

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());
}
Also used : DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection)

Example 42 with DruidPooledConnection

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());
}
Also used : DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection)

Example 43 with DruidPooledConnection

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();
}
Also used : DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection)

Example 44 with DruidPooledConnection

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();
}
Also used : DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection)

Example 45 with DruidPooledConnection

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());
}
Also used : SQLException(java.sql.SQLException) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) Statement(java.sql.Statement) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)152 SQLException (java.sql.SQLException)99 PreparedStatement (java.sql.PreparedStatement)61 MockConnection (com.alibaba.druid.mock.MockConnection)49 Statement (java.sql.Statement)46 Connection (java.sql.Connection)20 MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)10 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)7 DruidConnectionHolder (com.alibaba.druid.pool.DruidConnectionHolder)5 ResultSet (java.sql.ResultSet)5 DruidPooledPreparedStatement (com.alibaba.druid.pool.DruidPooledPreparedStatement)4 PreparedStatementHolder (com.alibaba.druid.pool.PreparedStatementHolder)4 Properties (java.util.Properties)4 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)3 EncodingConvertFilter (com.alibaba.druid.filter.encoding.EncodingConvertFilter)2 MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)2 MockResultSet (com.alibaba.druid.mock.MockResultSet)2 PreparedStatementKey (com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey)2 PreparedStatementPool (com.alibaba.druid.pool.PreparedStatementPool)2 CountDownLatch (java.util.concurrent.CountDownLatch)2