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);
}
use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class ConfigErrorTestMysql method setUp.
protected void setUp() throws Exception {
super.setUp();
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mysql:xxx");
dataSource.setTestOnBorrow(false);
dataSource.setInitialSize(0);
}
use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class ConfigErrorTest3 method setUp.
protected void setUp() throws Exception {
super.setUp();
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mysql:xxx");
dataSource.setTestOnBorrow(false);
dataSource.setTestOnReturn(false);
dataSource.setTestWhileIdle(false);
dataSource.setInitialSize(0);
dataSource.setPoolPreparedStatements(true);
}
use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class MaxEvictableIdleTimeMillisTest2 method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
dataSource.setMaxActive(50);
dataSource.setMinIdle(5);
}
Aggregations