diff --git a/src/main/java/com/alibaba/druid/filter/stat/StatFilter.java b/src/main/java/com/alibaba/druid/filter/stat/StatFilter.java index 2ffd9e4e89..615097cdff 100644 --- a/src/main/java/com/alibaba/druid/filter/stat/StatFilter.java +++ b/src/main/java/com/alibaba/druid/filter/stat/StatFilter.java @@ -96,6 +96,10 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean { this.dbType = dbType; } + public long getSlowSqlMillis() { + return slowSqlMillis; + } + public boolean isConnectionStackTraceEnable() { return connectionStackTraceEnable; } @@ -406,7 +410,8 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean { } } - private final void internalAfterStatementExecute(StatementProxy statement, boolean firstResult, int... updateCountArray) { + private final void internalAfterStatementExecute(StatementProxy statement, boolean firstResult, + int... updateCountArray) { final JdbcStatementStat.Entry entry = getStatementInfo(statement); diff --git a/src/test/java/com/alibaba/druid/bvt/pool/SlowSqlMillisTest.java b/src/test/java/com/alibaba/druid/bvt/pool/SlowSqlMillisTest.java new file mode 100644 index 0000000000..e9674784eb --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/pool/SlowSqlMillisTest.java @@ -0,0 +1,32 @@ +package com.alibaba.druid.bvt.pool; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import com.alibaba.druid.filter.stat.StatFilter; +import com.alibaba.druid.pool.DruidDataSource; + + +public class SlowSqlMillisTest extends TestCase { + private DruidDataSource dataSource; + + protected void setUp() throws Exception { + dataSource = new DruidDataSource(); + dataSource.setUrl("jdbc:wrap-jdbc:jdbc:mock:xxx"); + dataSource.setTestOnBorrow(false); + dataSource.setTestOnReturn(false); + dataSource.setTestWhileIdle(false); + dataSource.setConnectionProperties("druid.stat.slowSqlMillis=500"); + dataSource.setFilters("stat"); + dataSource.init(); + } + + protected void tearDown() throws Exception { + dataSource.close(); + } + + public void test_connect() throws Exception { + StatFilter filter = (StatFilter) dataSource.getProxyFilters().get(0); + Assert.assertEquals(500, filter.getSlowSqlMillis()); + } +}