fixed testcase

This commit is contained in:
高铁
2016-03-29 16:50:34 +08:00
parent 4661b4097c
commit d2a397de89
3 changed files with 56 additions and 21 deletions
@@ -1,5 +1,6 @@
package com.alibaba.druid.bvt.pool;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.concurrent.CountDownLatch;
@@ -7,15 +8,16 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import junit.framework.TestCase;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Assert;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.Log4jImpl;
import com.alibaba.druid.support.logging.LogFactory;
import com.alibaba.druid.support.logging.NoLoggingImpl;
import junit.framework.TestCase;
public class AsyncCloseTest1 extends TestCase {
@@ -25,13 +27,23 @@ public class AsyncCloseTest1 extends TestCase {
final AtomicInteger errorCount = new AtomicInteger();
private Logger log;
private Level oldLevel;
private Logger log4jLog;
private Level log4jOldLevel;
private NoLoggingImpl noLoggingImpl;
protected void setUp() throws Exception {
log = ((Log4jImpl) LogFactory.getLog(DruidDataSource.class)).getLog();
oldLevel = log.getLevel();
log.setLevel(Level.FATAL);
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:");
@@ -46,7 +58,11 @@ public class AsyncCloseTest1 extends TestCase {
protected void tearDown() throws Exception {
dataSource.close();
log.setLevel(oldLevel);
if (log4jLog != null) {
log4jLog.setLevel(log4jOldLevel);
} else if (noLoggingImpl != null) {
noLoggingImpl.setErrorEnabled(true);
}
}
public void test_0() throws Exception {
@@ -1,5 +1,6 @@
package com.alibaba.druid.bvt.pool;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
@@ -8,8 +9,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import junit.framework.TestCase;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Assert;
@@ -19,8 +18,11 @@ import com.alibaba.druid.filter.FilterChain;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.vendor.MockExceptionSorter;
import com.alibaba.druid.proxy.jdbc.StatementProxy;
import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.Log4jImpl;
import com.alibaba.druid.support.logging.LogFactory;
import com.alibaba.druid.support.logging.NoLoggingImpl;
import junit.framework.TestCase;
public class AsyncCloseTest2 extends TestCase {
@@ -30,14 +32,25 @@ public class AsyncCloseTest2 extends TestCase {
final AtomicInteger errorCount = new AtomicInteger();
private Logger log;
private Level oldLevel;
private Logger log4jLog;
private Level log4jOldLevel;
private NoLoggingImpl noLoggingImpl;
protected void setUp() throws Exception {
log = ((Log4jImpl) LogFactory.getLog(DruidDataSource.class)).getLog();
oldLevel = log.getLevel();
log.setLevel(Level.FATAL);
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);
@@ -63,7 +76,11 @@ public class AsyncCloseTest2 extends TestCase {
protected void tearDown() throws Exception {
dataSource.close();
log.setLevel(oldLevel);
if (log4jLog != null) {
log4jLog.setLevel(log4jOldLevel);
} else if (noLoggingImpl != null) {
noLoggingImpl.setErrorEnabled(true);
}
}
public void test_0() throws Exception {
@@ -32,12 +32,14 @@ import com.alibaba.druid.stat.DruidDataSourceStatManager;
public class ClobTest extends TestCase {
protected int dataSourceListSize;
protected void setUp() throws Exception {
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
dataSourceListSize = DruidDataSourceStatManager.getInstance().getDataSourceList().size();
}
protected void tearDown() throws Exception {
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
Assert.assertEquals(dataSourceListSize, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
}
public void test_clob() throws Exception {