mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor logging
This commit is contained in:
+49
@@ -0,0 +1,49 @@
|
||||
package com.alibaba.druid.bvt.pool.dynamic;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidDataSourceStatLogger;
|
||||
import com.alibaba.druid.pool.DruidDataSourceStatLoggerImpl;
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
|
||||
public class DruidDataSourceStatLoggerImplTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
private Log statLog;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
Field logField = DruidDataSourceStatLoggerImpl.class.getDeclaredField("LOG");
|
||||
logField.setAccessible(true);
|
||||
statLog = (Log) logField.get(null);
|
||||
|
||||
statLog.resetStat();
|
||||
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.setConnectionProperties("a=3;b=4");
|
||||
dataSource.setFilters("stat");
|
||||
dataSource.init();
|
||||
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_connectPropertiesChange() throws Exception {
|
||||
Assert.assertTrue(dataSource.isWrapperFor(DruidDataSourceStatLogger.class));
|
||||
Assert.assertTrue(dataSource.isWrapperFor(DruidDataSourceStatLoggerImpl.class));
|
||||
DruidDataSourceStatLoggerImpl loggerImpl = dataSource.unwrap(DruidDataSourceStatLoggerImpl.class);
|
||||
Assert.assertSame(statLog, loggerImpl.getLogger());
|
||||
|
||||
dataSource.setConnectionProperties("druid.stat.loggerName=xxx");
|
||||
Assert.assertNotSame(statLog, loggerImpl.getLogger());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user