mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add testcase
This commit is contained in:
@@ -77,6 +77,10 @@ public class Histogram {
|
||||
return ranges;
|
||||
}
|
||||
|
||||
public long getValue(int index) {
|
||||
return rangeCounters[index].get();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append('[');
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.alibaba.druid.bvt.filter;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.util.Histogram;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class PoolStatFilterTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setFilters("stat");
|
||||
|
||||
dataSource.init();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
|
||||
public void test_stat() throws Exception {
|
||||
|
||||
Assert.assertTrue(dataSource.isInited());
|
||||
|
||||
Histogram histogram = dataSource.getDataSourceStat().getConnectionHoldHistogram();
|
||||
|
||||
Assert.assertEquals(0, histogram.getValue(0));
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(1, histogram.getValue(0));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user