use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class DruidDataSourceFactoryTest1 method test_integer.
public void test_integer() throws Exception {
Properties properties = new Properties();
properties.put(DruidDataSourceFactory.PROP_URL, "jdbc:mock:xxx");
properties.put(DruidDataSourceFactory.PROP_DEFAULTTRANSACTIONISOLATION, Integer.toString(Connection.TRANSACTION_SERIALIZABLE));
DruidDataSource dataSource = null;
try {
dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
Assert.assertEquals("jdbc:mock:xxx", dataSource.getUrl());
Assert.assertEquals(Connection.TRANSACTION_SERIALIZABLE, dataSource.getDefaultTransactionIsolation().intValue());
} finally {
JdbcUtils.close(dataSource);
}
}
use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class DruidDataSourceFactoryTest1 method test_SERIALIZABLE.
public void test_SERIALIZABLE() throws Exception {
Properties properties = new Properties();
properties.put(DruidDataSourceFactory.PROP_URL, "jdbc:mock:xxx");
properties.put(DruidDataSourceFactory.PROP_DEFAULTTRANSACTIONISOLATION, "SERIALIZABLE");
DruidDataSource dataSource = null;
try {
dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
Assert.assertEquals("jdbc:mock:xxx", dataSource.getUrl());
Assert.assertEquals(Connection.TRANSACTION_SERIALIZABLE, dataSource.getDefaultTransactionIsolation().intValue());
} finally {
JdbcUtils.close(dataSource);
}
}
use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class DruidDataSourceFilterTest method test_filter.
public void test_filter() throws Exception {
System.out.println(System.nanoTime() / (1000 * 1000));
DruidDataSource dataSource = new DruidDataSource();
Assert.assertEquals(0, dataSource.getProxyFilters().size());
dataSource.setFilters("stat");
Assert.assertEquals(1, dataSource.getProxyFilters().size());
dataSource.close();
}
use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class DruidDataSourceFilterTest method test_filter_3.
public void test_filter_3() throws Exception {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:");
Assert.assertEquals(0, dataSource.getProxyFilters().size());
dataSource.setFilters("stat");
JdbcStatManager.getInstance().reset();
dataSource.init();
JdbcDataSourceStat dataSourceStat = dataSource.getDataSourceStat();
// Assert.assertEquals(1, JdbcStatManager.getInstance().getDataSources().size());
// JdbcDataSourceStat dataSourceStat = JdbcStatManager.getInstance().getDataSources().values().iterator().next();
Assert.assertEquals(0, dataSourceStat.getConnectionStat().getConnectCount());
Assert.assertEquals(1, dataSource.getProxyFilters().size());
for (int i = 0; i < 2; ++i) {
Connection conn = dataSource.getConnection();
Assert.assertEquals(1, dataSourceStat.getConnectionStat().getConnectCount());
Assert.assertEquals(0, dataSourceStat.getConnectionStat().getCloseCount());
conn.close();
Assert.assertEquals(1, dataSourceStat.getConnectionStat().getConnectCount());
// logic
Assert.assertEquals(0, dataSourceStat.getConnectionStat().getCloseCount());
// close不会导致计数器+1
}
Assert.assertEquals(1, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
dataSource.close();
Assert.assertEquals(1, dataSourceStat.getConnectionStat().getConnectCount());
Assert.assertEquals(1, dataSourceStat.getConnectionStat().getCloseCount());
}
use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.
the class DruidDataSourceTest3 method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
dataSource.setInitialSize(1);
dataSource.getProxyFilters().add(new FilterAdapter() {
public ConnectionProxy connection_connect(FilterChain chain, Properties info) throws SQLException {
try {
Thread.sleep(Long.MAX_VALUE);
} catch (InterruptedException e) {
// skip
}
return null;
}
});
}
Aggregations