mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge pull request #112 from wenshao/master
add testcase & remove unused code
This commit is contained in:
@@ -24,7 +24,6 @@ import java.sql.SQLException;
|
||||
import java.sql.Savepoint;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import com.alibaba.druid.filter.Filter;
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
@@ -79,8 +78,6 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
private boolean connectionStackTraceEnable = false;
|
||||
|
||||
protected final AtomicLong resetCount = new AtomicLong();
|
||||
|
||||
// 3 seconds is slow sql
|
||||
protected long slowSqlMillis = 3 * 1000;
|
||||
|
||||
@@ -113,10 +110,6 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
this.connectionStackTraceEnable = connectionStackTraceEnable;
|
||||
}
|
||||
|
||||
public long getResetCount() {
|
||||
return resetCount.get();
|
||||
}
|
||||
|
||||
public boolean isMergeSql() {
|
||||
return mergeSql;
|
||||
}
|
||||
@@ -837,9 +830,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
clobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (ClobProxy) obj);
|
||||
}
|
||||
|
||||
if (obj instanceof Blob) {
|
||||
} else if (obj instanceof Blob) {
|
||||
blobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (Blob) obj);
|
||||
}
|
||||
|
||||
@@ -853,9 +844,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
clobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (ClobProxy) obj);
|
||||
}
|
||||
|
||||
if (obj instanceof Blob) {
|
||||
} else if (obj instanceof Blob) {
|
||||
blobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (Blob) obj);
|
||||
}
|
||||
|
||||
@@ -869,9 +858,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
clobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (ClobProxy) obj);
|
||||
}
|
||||
|
||||
if (obj instanceof Blob) {
|
||||
} else if (obj instanceof Blob) {
|
||||
blobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (Blob) obj);
|
||||
}
|
||||
|
||||
@@ -886,9 +873,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
clobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (ClobProxy) obj);
|
||||
}
|
||||
|
||||
if (obj instanceof Blob) {
|
||||
} else if (obj instanceof Blob) {
|
||||
blobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (Blob) obj);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.alibaba.druid.bvt.filter;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.filter.Filter;
|
||||
import com.alibaba.druid.filter.FilterAdapter;
|
||||
import com.alibaba.druid.filter.FilterManager;
|
||||
|
||||
public class FilterManagerTest extends TestCase {
|
||||
|
||||
public void test_instance() throws Exception {
|
||||
new FilterManager();
|
||||
}
|
||||
|
||||
public void test_loadFilter() throws Exception {
|
||||
Exception error = null;
|
||||
|
||||
try {
|
||||
FilterManager.loadFilter(new ArrayList<Filter>(), ErrorFilter.class.getName());
|
||||
} catch (SQLException e) {
|
||||
error = e;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
public void test_loadFilter_2() throws Exception {
|
||||
Exception error = null;
|
||||
|
||||
try {
|
||||
FilterManager.loadFilter(new ArrayList<Filter>(), ErrorFilter.class.getName());
|
||||
} catch (SQLException e) {
|
||||
error = e;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
public static class ErrorFilter extends FilterAdapter {
|
||||
|
||||
public ErrorFilter(){
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.alibaba.druid.bvt.proxy.filter;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.filter.stat.StatFilter;
|
||||
|
||||
public class StatFilterTest3 extends TestCase {
|
||||
public void test_dbType() throws Exception {
|
||||
StatFilter filter = new StatFilter();
|
||||
|
||||
Assert.assertFalse(filter.isMergeSql());
|
||||
|
||||
filter.setDbType("mysql");
|
||||
filter.setMergeSql(true);
|
||||
|
||||
Assert.assertTrue(filter.isMergeSql());
|
||||
Assert.assertEquals("mysql", filter.getDbType());
|
||||
|
||||
Assert.assertEquals("SELECT ?\nLIMIT ?" , filter.mergeSql("select 'x' limit 1"));
|
||||
}
|
||||
|
||||
public void test_dbType_error() throws Exception {
|
||||
StatFilter filter = new StatFilter();
|
||||
filter.setDbType("mysql");
|
||||
filter.setMergeSql(true);
|
||||
|
||||
Assert.assertEquals("mysql", filter.getDbType());
|
||||
|
||||
Assert.assertEquals("sdafawer asf " , filter.mergeSql("sdafawer asf "));
|
||||
}
|
||||
|
||||
public void test_merge() throws Exception {
|
||||
StatFilter filter = new StatFilter();
|
||||
filter.setDbType("mysql");
|
||||
filter.setMergeSql(false);
|
||||
|
||||
Assert.assertEquals("mysql", filter.getDbType());
|
||||
|
||||
Assert.assertEquals("select 'x' limit 1" , filter.mergeSql("select 'x' limit 1"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user