Search in sources :

Example 26 with JdbcDataSourceStat

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());
}
Also used : FilterChainImpl(com.alibaba.druid.filter.FilterChainImpl) DataSourceProxyConfig(com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig) DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) StatFilter(com.alibaba.druid.filter.stat.StatFilter) JdbcDataSourceStat(com.alibaba.druid.stat.JdbcDataSourceStat) Properties(java.util.Properties) SQLException(java.sql.SQLException)

Aggregations

JdbcDataSourceStat (com.alibaba.druid.stat.JdbcDataSourceStat)26 JdbcSqlStat (com.alibaba.druid.stat.JdbcSqlStat)6 SQLException (java.sql.SQLException)5 JdbcConnectionStat (com.alibaba.druid.stat.JdbcConnectionStat)4 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)3 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)3 JdbcStatContext (com.alibaba.druid.stat.JdbcStatContext)3 Connection (java.sql.Connection)3 Properties (java.util.Properties)3 DbType (com.alibaba.druid.DbType)2 Savepoint (java.sql.Savepoint)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)2 Filter (com.alibaba.druid.filter.Filter)1 FilterChain (com.alibaba.druid.filter.FilterChain)1 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)1 StatFilter (com.alibaba.druid.filter.stat.StatFilter)1 DataSourceProxy (com.alibaba.druid.proxy.jdbc.DataSourceProxy)1 DataSourceProxyConfig (com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig)1