Search in sources :

Example 1 with NoLoggingImpl

use of com.alibaba.druid.support.logging.NoLoggingImpl in project druid by alibaba.

the class NoLoggingImplTest method test_0.

public void test_0() throws Exception {
    NoLoggingImpl impl = new NoLoggingImpl(DruidDataSource.class.getName());
    impl.isDebugEnabled();
    impl.isInfoEnabled();
    impl.isWarnEnabled();
    impl.debug("");
    impl.debug("", new Exception());
    impl.info("");
    impl.warn("");
    impl.warn("", new Exception());
    impl.error("");
    impl.error("", new Exception());
    Assert.assertEquals(1, impl.getInfoCount());
    Assert.assertEquals(2, impl.getErrorCount());
    Assert.assertEquals(2, impl.getWarnCount());
    Assert.assertEquals(1, impl.getInfoCount());
}
Also used : NoLoggingImpl(com.alibaba.druid.support.logging.NoLoggingImpl) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 2 with NoLoggingImpl

use of com.alibaba.druid.support.logging.NoLoggingImpl in project druid by alibaba.

the class AsyncCloseTest1 method setUp.

protected void setUp() throws Exception {
    Field logField = DruidDataSource.class.getDeclaredField("LOG");
    logField.setAccessible(true);
    Log dataSourceLog = (Log) logField.get(null);
    if (dataSourceLog instanceof Log4jImpl) {
        this.log4jLog = ((Log4jImpl) dataSourceLog).getLog();
        this.log4jOldLevel = this.log4jLog.getLevel();
        this.log4jLog.setLevel(Level.FATAL);
    } else if (dataSourceLog instanceof NoLoggingImpl) {
        noLoggingImpl = (NoLoggingImpl) dataSourceLog;
        noLoggingImpl.setErrorEnabled(false);
    }
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:");
    //        dataSource.setAsyncCloseConnectionEnable(true);
    dataSource.setTestOnBorrow(false);
    dataSource.setMaxActive(16);
    connExecutor = Executors.newFixedThreadPool(128);
    closeExecutor = Executors.newFixedThreadPool(128);
}
Also used : Field(java.lang.reflect.Field) Log4jImpl(com.alibaba.druid.support.logging.Log4jImpl) Log(com.alibaba.druid.support.logging.Log) NoLoggingImpl(com.alibaba.druid.support.logging.NoLoggingImpl) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 3 with NoLoggingImpl

use of com.alibaba.druid.support.logging.NoLoggingImpl in project druid by alibaba.

the class AsyncCloseTest2 method setUp.

protected void setUp() throws Exception {
    Field logField = DruidDataSource.class.getDeclaredField("LOG");
    logField.setAccessible(true);
    Log dataSourceLog = (Log) logField.get(null);
    if (dataSourceLog instanceof Log4jImpl) {
        this.log4jLog = ((Log4jImpl) dataSourceLog).getLog();
        this.log4jOldLevel = this.log4jLog.getLevel();
        this.log4jLog.setLevel(Level.FATAL);
    } else if (dataSourceLog instanceof NoLoggingImpl) {
        noLoggingImpl = (NoLoggingImpl) dataSourceLog;
        noLoggingImpl.setErrorEnabled(false);
    }
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:");
    dataSource.setAsyncCloseConnectionEnable(true);
    dataSource.setTestOnBorrow(false);
    dataSource.setMaxActive(16);
    dataSource.getProxyFilters().add(new FilterAdapter() {

        @Override
        public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql) throws SQLException {
            throw new SQLException();
        }
    });
    dataSource.setExceptionSorter(new MyExceptionSorter());
    dataSource.init();
    connExecutor = Executors.newFixedThreadPool(128);
    closeExecutor = Executors.newFixedThreadPool(128);
}
Also used : Field(java.lang.reflect.Field) Log4jImpl(com.alibaba.druid.support.logging.Log4jImpl) Log(com.alibaba.druid.support.logging.Log) SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) StatementProxy(com.alibaba.druid.proxy.jdbc.StatementProxy) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) NoLoggingImpl(com.alibaba.druid.support.logging.NoLoggingImpl) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 4 with NoLoggingImpl

use of com.alibaba.druid.support.logging.NoLoggingImpl in project druid by alibaba.

the class AsyncCloseTest3 method setUp.

protected void setUp() throws Exception {
    // m;
    xmx = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax() / (1000 * 1000);
    System.gc();
    Field logField = DruidDataSource.class.getDeclaredField("LOG");
    logField.setAccessible(true);
    Log dataSourceLog = (Log) logField.get(null);
    if (dataSourceLog instanceof Log4jImpl) {
        this.log4jLog = ((Log4jImpl) dataSourceLog).getLog();
        this.log4jOldLevel = this.log4jLog.getLevel();
        this.log4jLog.setLevel(Level.FATAL);
    } else if (dataSourceLog instanceof NoLoggingImpl) {
        noLoggingImpl = (NoLoggingImpl) dataSourceLog;
        noLoggingImpl.setErrorEnabled(false);
    }
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:");
    // dataSource.setAsyncCloseConnectionEnable(true);
    dataSource.setTestOnBorrow(false);
    dataSource.setMaxActive(16);
    dataSource.getProxyFilters().add(new FilterAdapter() {

        @Override
        public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql) throws SQLException {
            throw new SQLException();
        }
    });
    dataSource.setExceptionSorter(new MyExceptionSorter());
    dataSource.init();
    connExecutor = Executors.newFixedThreadPool(2);
    closeExecutor = Executors.newFixedThreadPool(2);
}
Also used : Field(java.lang.reflect.Field) Log4jImpl(com.alibaba.druid.support.logging.Log4jImpl) Log(com.alibaba.druid.support.logging.Log) SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) StatementProxy(com.alibaba.druid.proxy.jdbc.StatementProxy) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) NoLoggingImpl(com.alibaba.druid.support.logging.NoLoggingImpl) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Aggregations

DruidDataSource (com.alibaba.druid.pool.DruidDataSource)4 NoLoggingImpl (com.alibaba.druid.support.logging.NoLoggingImpl)4 Log (com.alibaba.druid.support.logging.Log)3 Log4jImpl (com.alibaba.druid.support.logging.Log4jImpl)3 Field (java.lang.reflect.Field)3 FilterAdapter (com.alibaba.druid.filter.FilterAdapter)2 FilterChain (com.alibaba.druid.filter.FilterChain)2 StatementProxy (com.alibaba.druid.proxy.jdbc.StatementProxy)2 SQLException (java.sql.SQLException)2