use of com.alibaba.druid.stat.JdbcDataSourceStat in project druid by alibaba.
the class CounterFilterTest method test_countFilter.
public void test_countFilter() throws Exception {
DataSourceProxyConfig config = new DataSourceProxyConfig();
config.setUrl("");
DataSourceProxyImpl dataSource = new DataSourceProxyImpl(null, config);
JdbcDataSourceStat dataSourceStat = dataSource.getDataSourceStat();
StatFilter filter = new StatFilter();
filter.init(dataSource);
dataSourceStat.reset();
Assert.assertNull(StatFilter.getStatFilter(dataSource));
Assert.assertNull(dataSourceStat.getSqlStat(Integer.MAX_VALUE));
Assert.assertNull(dataSourceStat.getConnectionStat().getConnectLastTime());
FilterChain chain = new FilterChainImpl(dataSource) {
public ConnectionProxy connection_connect(Properties info) throws SQLException {
throw new SQLException();
}
};
Exception error = null;
try {
filter.connection_connect(chain, new Properties());
} catch (SQLException ex) {
error = ex;
}
Assert.assertNotNull(error);
Assert.assertEquals(1, dataSourceStat.getConnectionStat().getConnectErrorCount());
Assert.assertNotNull(dataSourceStat.getConnectionStat().getConnectLastTime());
}
Aggregations