mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
support logStats
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class TimeBetweenLogStatsMillisTest2 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
System.setProperty("druid.timeBetweenLogStatsMillis", "1000");
|
||||
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
System.clearProperty("druid.timeBetweenLogStatsMillis");
|
||||
}
|
||||
|
||||
public void test_0() throws Exception {
|
||||
dataSource.init();
|
||||
Assert.assertEquals(1000, dataSource.getTimeBetweenLogStatsMillis());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class TimeBetweenLogStatsMillisTest3 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
System.setProperty("druid.timeBetweenLogStatsMillis", "10");
|
||||
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setFilters("stat");
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
System.clearProperty("druid.timeBetweenLogStatsMillis");
|
||||
}
|
||||
|
||||
public void test_0() throws Exception {
|
||||
dataSource.init();
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement("select ?");
|
||||
stmt.setString(1, "aaa");
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
|
||||
Thread.sleep(10);
|
||||
}
|
||||
Assert.assertEquals(10, dataSource.getTimeBetweenLogStatsMillis());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user