use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class DruidDataSourceTest_interrupt method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource() {
protected void createAndStartCreatorThread() {
return;
}
};
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
dataSource.setDefaultAutoCommit(true);
dataSource.setInitialSize(1);
}
use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class DruidDataSourceTest_lastCreateError method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
dataSource.getProxyFilters().add(new FilterAdapter() {
public ConnectionProxy connection_connect(FilterChain chain, Properties info) throws SQLException {
throw new SQLException();
}
});
}
use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class Case1 method test_f.
public void test_f() throws Exception {
final DruidDataSource dataSource = new DruidDataSource();
dataSource.setTimeBetweenConnectErrorMillis(100);
final long startTime = System.currentTimeMillis();
final long okTime = startTime + 1000 * 1;
dataSource.setDriver(new MockDriver() {
@Override
public Connection connect(String url, Properties info) throws SQLException {
if (System.currentTimeMillis() < okTime) {
throw new SQLException();
}
return super.connect(url, info);
}
});
dataSource.setUrl("jdbc:mock:");
dataSource.setMinIdle(0);
dataSource.setMaxActive(2);
dataSource.setMaxIdle(2);
Connection conn = dataSource.getConnection();
conn.close();
dataSource.close();
}
use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class Case2 method test_singleThread.
public void test_singleThread() throws Exception {
Class.forName("com.alibaba.druid.mock.MockDriver");
Properties properties = new Properties();
properties.put("maxActive", "100");
properties.put("maxIdle", "30");
properties.put("maxWait", "10000");
properties.put("url", "jdbc:mock:");
properties.put("filters", "stat");
properties.put("validationQuery", "SELECT 1");
DruidDataSource dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
JMXUtils.register("com.alibaba.druid:type=DruidDataSource", dataSource);
final int COUNT = 10;
Assert.assertEquals(0, dataSource.getCreateCount());
Assert.assertEquals(0, dataSource.getDestroyCount());
Assert.assertEquals(0, dataSource.getPoolingCount());
Connection[] connections = new Connection[COUNT];
for (int i = 0; i < COUNT; ++i) {
connections[i] = dataSource.getConnection();
}
for (int i = 0; i < COUNT; ++i) {
connections[i].close();
}
Assert.assertEquals(0, dataSource.getDestroyCount());
dataSource.close();
Assert.assertEquals(dataSource.getCreateCount(), dataSource.getDestroyCount());
}
use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class ClosedTest method test_close.
public void test_close() throws Exception {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
Connection conn = dataSource.getConnection();
conn.close();
dataSource.close();
DataSourceClosedException error = null;
try {
dataSource.getConnection();
} catch (DataSourceClosedException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
Aggregations