use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class OracleExceptionSorterTest_rollback method test_connect.
public void test_connect() throws Exception {
String sql = "SELECT 1";
{
DruidPooledConnection conn = dataSource.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.execute();
pstmt.close();
conn.close();
Assert.assertEquals(0, dataSource.getActiveCount());
Assert.assertEquals(1, dataSource.getPoolingCount());
Assert.assertEquals(1, dataSource.getCreateCount());
}
DruidPooledConnection conn = dataSource.getConnection();
MockConnection mockConn = conn.unwrap(MockConnection.class);
Assert.assertNotNull(mockConn);
conn.setAutoCommit(false);
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.execute();
SQLException exception = new SQLException("xx", "xxx", 28);
mockConn.setError(exception);
Exception rollbackError = null;
try {
conn.rollback();
} catch (Exception ex) {
rollbackError = ex;
}
Assert.assertNotNull(rollbackError);
conn.close();
{
Connection conn2 = dataSource.getConnection();
conn2.close();
}
Assert.assertEquals(0, dataSource.getActiveCount());
Assert.assertEquals(1, dataSource.getPoolingCount());
Assert.assertEquals(2, dataSource.getCreateCount());
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class OracleExceptionSorterTest_setSavepoint method test_connect.
public void test_connect() throws Exception {
String sql = "SELECT 1";
{
DruidPooledConnection conn = dataSource.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.execute();
pstmt.close();
conn.close();
Assert.assertEquals(0, dataSource.getActiveCount());
Assert.assertEquals(1, dataSource.getPoolingCount());
Assert.assertEquals(1, dataSource.getCreateCount());
}
DruidPooledConnection conn = dataSource.getConnection();
MockConnection mockConn = conn.unwrap(MockConnection.class);
Assert.assertNotNull(mockConn);
SQLException exception = new SQLException("xx", "xxx", 28);
mockConn.setError(exception);
Exception setError = null;
try {
conn.setSavepoint();
} catch (Exception ex) {
setError = ex;
}
Assert.assertNotNull(setError);
conn.close();
{
Connection conn2 = dataSource.getConnection();
conn2.close();
}
Assert.assertEquals(0, dataSource.getActiveCount());
Assert.assertEquals(1, dataSource.getPoolingCount());
Assert.assertEquals(2, dataSource.getCreateCount());
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class ConnectionTest4 method test_addListenerError.
public void test_addListenerError() throws Exception {
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
conn.close();
{
Exception error = null;
try {
conn.addConnectionEventListener(null);
} catch (IllegalStateException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class DataSourceTest3 method test_error_1.
public void test_error_1() throws Exception {
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
conn.close();
dataSource.setPoolPreparedStatements(false);
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class DataSourceTest3 method test_change_connectProperties_2.
public void test_change_connectProperties_2() throws Exception {
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
conn.close();
dataSource.setConnectionProperties("x=12;;");
}
Aggregations