use of com.alibaba.druid.mock.MockDriver in project druid by alibaba.
the class FilterChainImplTest3 method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setFilters("stat,log4j,wall,encoding");
dataSource.getProxyFilters().add(new FilterAdapter() {
});
dataSource.setDbType("mysql");
dataSource.setDriver(new MockDriver() {
public ResultSet executeQuery(MockStatementBase stmt, String sql) throws SQLException {
return null;
}
public MockStatement createMockStatement(MockConnection conn) {
return new MockStatement(conn) {
public ResultSet getResultSet() throws SQLException {
return null;
}
};
}
});
dataSource.init();
}
use of com.alibaba.druid.mock.MockDriver in project druid by alibaba.
the class CallableStatmentTest method setUp.
protected void setUp() throws Exception {
super.setUp();
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
dataSource.setPoolPreparedStatements(true);
dataSource.setMaxOpenPreparedStatements(100);
dataSource.setFilters("log4j");
dataSource.setDriver(new MockDriver() {
public MockCallableStatement createMockCallableStatement(MockConnection conn, String sql) {
return new MyMockCallableStatement(conn, sql);
}
});
}
use of com.alibaba.druid.mock.MockDriver in project druid by alibaba.
the class DruidDataSourceTest_exceptionSorter method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
dataSource.setRemoveAbandoned(true);
dataSource.setDriver(new MockDriver() {
public ResultSet executeQuery(MockStatementBase stmt, String sql) throws SQLException {
throw new SQLException();
}
});
dataSource.setExceptionSorter(new ExceptionSorter() {
@Override
public boolean isExceptionFatal(SQLException e) {
return true;
}
@Override
public void configFromProperties(Properties properties) {
}
});
}
use of com.alibaba.druid.mock.MockDriver in project druid by alibaba.
the class DruidDataSourceTest_getPooledConnection method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
dataSource.setRemoveAbandoned(true);
dataSource.setDriver(new MockDriver() {
public ResultSet executeQuery(MockStatementBase stmt, String sql) throws SQLException {
throw new SQLException();
}
});
}
use of com.alibaba.druid.mock.MockDriver in project druid by alibaba.
the class Case0 method test_0.
public void test_0() throws Exception {
final DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriver(new MockDriver() {
});
dataSource.setUrl("jdbc:mock:");
dataSource.setMinIdle(0);
dataSource.setMaxActive(2);
dataSource.setMaxIdle(2);
Connection conn1 = dataSource.getConnection();
Connection conn2 = dataSource.getConnection();
final CountDownLatch startLatch = new CountDownLatch(1);
final CountDownLatch completeLatch = new CountDownLatch(1);
final AtomicInteger waitCount = new AtomicInteger();
Thread t = new Thread() {
public void run() {
try {
startLatch.countDown();
waitCount.incrementAndGet();
Connection conn = dataSource.getConnection();
waitCount.decrementAndGet();
conn.close();
completeLatch.countDown();
} catch (Exception e) {
e.printStackTrace();
}
}
};
t.start();
startLatch.await();
Assert.assertFalse(completeLatch.await(1, TimeUnit.SECONDS));
conn1.close();
Assert.assertTrue(completeLatch.await(1, TimeUnit.SECONDS));
conn2.close();
Assert.assertTrue(completeLatch.await(1, TimeUnit.SECONDS));
dataSource.close();
}
Aggregations