use of com.alibaba.druid.mock.MockConnection in project druid by alibaba.
the class TestGetUpdateCount method setUp.
protected void setUp() throws Exception {
driver = new MockDriver() {
@Override
public MockPreparedStatement createMockPreparedStatement(MockConnection conn, String sql) {
return new MyPreparedStatement(conn, sql);
}
};
// /////////////////////////////
dataSource = new DruidDataSource();
dataSource.setDriver(driver);
dataSource.setUrl("jdbc:mock:xx");
dataSource.setFilters("stat");
dataSource.setMaxOpenPreparedStatements(30);
}
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 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_2 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);
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 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);
}
Aggregations