Search in sources :

Example 6 with JdbcStatContext

use of com.alibaba.druid.stat.JdbcStatContext in project druid by alibaba.

the class ConnectionTest4 method setUp.

protected void setUp() throws Exception {
    DruidDataSourceStatManager.clear();
    driver = new MockDriver();
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setDriver(driver);
    dataSource.setInitialSize(1);
    dataSource.setMaxActive(2);
    dataSource.setMaxIdle(2);
    dataSource.setMinIdle(1);
    // 300 / 10
    dataSource.setMinEvictableIdleTimeMillis(300 * 1000);
    // 180 / 10
    dataSource.setTimeBetweenEvictionRunsMillis(180 * 1000);
    dataSource.setTestWhileIdle(true);
    dataSource.setTestOnBorrow(false);
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setFilters("stat,trace");
    dataSource.setPoolPreparedStatements(true);
    JdbcStatContext context = new JdbcStatContext();
    context.setTraceEnable(true);
    JdbcStatManager.getInstance().setStatContext(context);
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) JdbcStatContext(com.alibaba.druid.stat.JdbcStatContext)

Example 7 with JdbcStatContext

use of com.alibaba.druid.stat.JdbcStatContext in project druid by alibaba.

the class ConnectionTest5 method setUp.

protected void setUp() throws Exception {
    DruidDataSourceStatManager.clear();
    driver = new MockDriver();
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setDriver(driver);
    dataSource.setInitialSize(1);
    dataSource.setMaxActive(2);
    dataSource.setMaxIdle(2);
    dataSource.setMinIdle(1);
    // 300 / 10
    dataSource.setMinEvictableIdleTimeMillis(300 * 1000);
    // 180 / 10
    dataSource.setTimeBetweenEvictionRunsMillis(180 * 1000);
    dataSource.setTestWhileIdle(true);
    dataSource.setTestOnBorrow(true);
    dataSource.setTestOnReturn(true);
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setFilters("stat,trace");
    JdbcStatContext context = new JdbcStatContext();
    context.setTraceEnable(true);
    JdbcStatManager.getInstance().setStatContext(context);
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) JdbcStatContext(com.alibaba.druid.stat.JdbcStatContext)

Example 8 with JdbcStatContext

use of com.alibaba.druid.stat.JdbcStatContext in project druid by alibaba.

the class DataSourceTest3 method setUp.

protected void setUp() throws Exception {
    DruidDataSourceStatManager.clear();
    driver = new MockDriver();
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setDriver(driver);
    dataSource.setInitialSize(1);
    dataSource.setMaxActive(2);
    dataSource.setMinIdle(1);
    // 300 / 10
    dataSource.setMinEvictableIdleTimeMillis(300 * 1000);
    // 180 / 10
    dataSource.setTimeBetweenEvictionRunsMillis(180 * 1000);
    dataSource.setTestWhileIdle(true);
    dataSource.setTestOnBorrow(true);
    dataSource.setTestOnReturn(true);
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setFilters("stat");
    JdbcStatContext context = new JdbcStatContext();
    context.setTraceEnable(true);
    JdbcStatManager.getInstance().setStatContext(context);
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) JdbcStatContext(com.alibaba.druid.stat.JdbcStatContext)

Example 9 with JdbcStatContext

use of com.alibaba.druid.stat.JdbcStatContext in project druid by alibaba.

the class PoolableStatementTest2 method setUp.

protected void setUp() throws Exception {
    DruidDataSourceStatManager.clear();
    driver = new MockDriver();
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setDriver(driver);
    dataSource.setInitialSize(1);
    dataSource.setMaxActive(2);
    dataSource.setMaxIdle(2);
    dataSource.setMinIdle(1);
    // 300 / 10
    dataSource.setMinEvictableIdleTimeMillis(300 * 1000);
    // 180 / 10
    dataSource.setTimeBetweenEvictionRunsMillis(180 * 1000);
    dataSource.setTestWhileIdle(true);
    dataSource.setTestOnBorrow(false);
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setFilters("stat,trace");
    dataSource.setRemoveAbandoned(true);
    dataSource.setExceptionSorterClassName(null);
    Assert.assertTrue(dataSource.getExceptionSorter() instanceof NullExceptionSorter);
    dataSource.setExceptionSorterClassName("");
    Assert.assertTrue(dataSource.getExceptionSorter() instanceof NullExceptionSorter);
    JdbcStatContext context = new JdbcStatContext();
    context.setTraceEnable(true);
    JdbcStatManager.getInstance().setStatContext(context);
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) NullExceptionSorter(com.alibaba.druid.pool.vendor.NullExceptionSorter) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) JdbcStatContext(com.alibaba.druid.stat.JdbcStatContext)

Aggregations

JdbcStatContext (com.alibaba.druid.stat.JdbcStatContext)9 MockDriver (com.alibaba.druid.mock.MockDriver)5 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)5 JdbcDataSourceStat (com.alibaba.druid.stat.JdbcDataSourceStat)3 NullExceptionSorter (com.alibaba.druid.pool.vendor.NullExceptionSorter)1 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)1 DataSourceProxy (com.alibaba.druid.proxy.jdbc.DataSourceProxy)1 JdbcConnectionStat (com.alibaba.druid.stat.JdbcConnectionStat)1 JdbcSqlStat (com.alibaba.druid.stat.JdbcSqlStat)1 SQLException (java.sql.SQLException)1