Search in sources :

Example 1 with Log

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

the class ConfigErrorTestMysql method test_warn.

public void test_warn() throws Exception {
    dataSource.setTestWhileIdle(false);
    Field field = DruidDataSource.class.getDeclaredField("LOG");
    field.setAccessible(true);
    Log LOG = (Log) field.get(null);
    LOG.resetStat();
    Assert.assertEquals(0, LOG.getWarnCount());
    dataSource.init();
    Assert.assertEquals(0, LOG.getWarnCount());
}
Also used : Field(java.lang.reflect.Field) Log(com.alibaba.druid.support.logging.Log)

Example 2 with Log

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

the class ConfigErrorTest method test_connect.

public void test_connect() throws Exception {
    Field field = DruidDataSource.class.getDeclaredField("LOG");
    field.setAccessible(true);
    Log LOG = (Log) field.get(null);
    LOG.resetStat();
    Assert.assertEquals(0, LOG.getErrorCount());
    Connection conn = dataSource.getConnection();
    conn.close();
    Assert.assertEquals(1, LOG.getErrorCount());
}
Also used : Field(java.lang.reflect.Field) Log(com.alibaba.druid.support.logging.Log) Connection(java.sql.Connection)

Example 3 with Log

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

the class ConfigErrorTest2 method test_connect.

public void test_connect() throws Exception {
    Field field = DruidDataSource.class.getDeclaredField("LOG");
    field.setAccessible(true);
    Log LOG = (Log) field.get(null);
    LOG.resetStat();
    Assert.assertEquals(0, LOG.getErrorCount());
    Connection conn = dataSource.getConnection();
    conn.close();
    Assert.assertEquals(1, LOG.getErrorCount());
}
Also used : Field(java.lang.reflect.Field) Log(com.alibaba.druid.support.logging.Log) Connection(java.sql.Connection)

Example 4 with Log

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

the class ConfigErrorTest3 method test_connect.

public void test_connect() throws Exception {
    Field field = DruidDataSource.class.getDeclaredField("LOG");
    field.setAccessible(true);
    Log LOG = (Log) field.get(null);
    LOG.resetStat();
    Assert.assertEquals(0, LOG.getErrorCount());
    dataSource.init();
    Assert.assertEquals(0, LOG.getErrorCount());
}
Also used : Field(java.lang.reflect.Field) Log(com.alibaba.druid.support.logging.Log)

Example 5 with Log

use of com.alibaba.druid.support.logging.Log 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)

Aggregations

Log (com.alibaba.druid.support.logging.Log)10 Field (java.lang.reflect.Field)10 Connection (java.sql.Connection)4 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)3 Log4jImpl (com.alibaba.druid.support.logging.Log4jImpl)3 NoLoggingImpl (com.alibaba.druid.support.logging.NoLoggingImpl)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