use of com.alibaba.druid.mock.MockConnection in project druid by alibaba.
the class PoolableCallableStatementTest method setUp.
protected void setUp() throws Exception {
MockConnection mockConn = new MockConnection();
DruidConnectionHolder connHolder = new DruidConnectionHolder(dataSource, mockConn, 0);
conn = new DruidPooledConnection(connHolder);
raw = new MockCallableStatement(null, null);
stmt = new DruidPooledCallableStatement(conn, new PreparedStatementHolder(new PreparedStatementKey("", null, null, 0, 0, 0), raw)) {
protected SQLException checkException(Throwable error) throws SQLException {
if (error instanceof SQLException) {
return (SQLException) error;
}
return new SQLException(error);
}
};
Assert.assertEquals(0, raw.getOutParameters().size());
stmt.registerOutParameter(1, Types.INTEGER);
Assert.assertEquals(1, raw.getOutParameters().size());
stmt.registerOutParameter(2, Types.DECIMAL, 10);
Assert.assertEquals(2, raw.getOutParameters().size());
}
use of com.alibaba.druid.mock.MockConnection in project druid by alibaba.
the class PreparedStatementKeyTest method test_contains.
public void test_contains() throws Exception {
DruidDataSource dataSource = new DruidDataSource();
MockConnection conn = new MockConnection();
PreparedStatementKey k1 = new PreparedStatementKey("x1", "c1", MethodType.M1);
PreparedStatementPool pool = new PreparedStatementPool(new DruidConnectionHolder(dataSource, conn, 0));
MockPreparedStatement raw = new MockPreparedStatement(null, null);
pool.put(new PreparedStatementHolder(k1, raw));
Assert.assertTrue(pool.get(k1) != null);
Assert.assertTrue(pool.get(k1) != null);
}
use of com.alibaba.druid.mock.MockConnection in project druid by alibaba.
the class OracleExceptionSorterTest_closeConn_1 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.prepareStatement(sql);
SQLException exception = new SQLException("xx", "xxx", 28);
mockConn.setError(exception);
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.mock.MockConnection in project druid by alibaba.
the class OracleExceptionSorterTest_closeConn_3 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);
conn.setReadOnly(false);
SQLException exception = new SQLException("xx", "xxx", 28);
mockConn.setError(exception);
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.mock.MockConnection in project druid by alibaba.
the class OracleExceptionSorterTest_commit 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);
conn.prepareStatement(sql);
SQLException exception = new SQLException("xx", "xxx", 28);
mockConn.setError(exception);
Exception commitError = null;
try {
conn.commit();
} catch (Exception ex) {
commitError = ex;
}
Assert.assertNotNull(commitError);
conn.close();
{
Connection conn2 = dataSource.getConnection();
conn2.close();
}
Assert.assertEquals(0, dataSource.getActiveCount());
Assert.assertEquals(1, dataSource.getPoolingCount());
Assert.assertEquals(2, dataSource.getCreateCount());
}
Aggregations