增强监控

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@553 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-09-01 08:49:52 +00:00
parent 61feb05e25
commit 32a93bad5b
5 changed files with 95 additions and 17 deletions
@@ -38,11 +38,14 @@ public class TestIdel2 extends TestCase {
conn.close();
Assert.assertEquals(0, dataSource.getDestroyCount());
Assert.assertEquals(2, driver.getConnections().size());
Assert.assertEquals(2, dataSource.getCreateCount());
Assert.assertEquals(true, driver.getConnections().size() == 2 || driver.getConnections().size() == 1);
Assert.assertEquals(true, dataSource.getCreateCount() == 2 || dataSource.getCreateCount() == 1);
Assert.assertEquals(0, dataSource.getActiveCount());
}
String text = dataSource.toString();
System.out.println(text);
{
int count = 14;
Connection[] connections = new Connection[count];
@@ -70,7 +73,7 @@ public class TestIdel2 extends TestCase {
Thread.sleep(1);
conn.close();
}
Assert.assertEquals(2, dataSource.getPoolingCount());
Assert.assertEquals(true, dataSource.getPoolingCount() == 2 || dataSource.getPoolingCount() == 1);
dataSource.close();
}
@@ -26,14 +26,14 @@ public class TestIdle3_Concurrent extends TestCase {
dataSource.setMaxActive(14);
dataSource.setMaxIdle(14);
dataSource.setMinIdle(1);
dataSource.setMinEvictableIdleTimeMillis(30 * 100); // 300 / 10
dataSource.setTimeBetweenEvictionRunsMillis(18 * 100); // 180 / 10
dataSource.setMinEvictableIdleTimeMillis(30 * 10); // 300 / 10
dataSource.setTimeBetweenEvictionRunsMillis(18 * 10); // 180 / 10
dataSource.setTestWhileIdle(true);
dataSource.setTestOnBorrow(false);
dataSource.setValidationQuery("SELECT 1");
dataSource.setFilters("stat");
ManagementFactory.getPlatformMBeanServer().registerMBean(dataSource, new ObjectName("com.alibaba:type=DataSource"));
// ManagementFactory.getPlatformMBeanServer().registerMBean(dataSource, new ObjectName("com.alibaba:type=DataSource"));
// 第一次创建连接
{
@@ -66,7 +66,8 @@ public class TestIdle3_Concurrent extends TestCase {
Assert.assertEquals(1, dataSource.getActiveCount());
conn.close();
}
Assert.assertEquals(2, dataSource.getPoolingCount());
Thread.sleep(1000);
Assert.assertEquals(1, dataSource.getPoolingCount());
dataSource.close();
}
@@ -86,11 +87,11 @@ public class TestIdle3_Concurrent extends TestCase {
Connection conn = dataSource.getConnection();
{
AtomicInteger c = new AtomicInteger();
for (int j = 0; j < 1000 * 100; ++j) {
for (int j = 0; j < 1000 * 1; ++j) {
c.incrementAndGet();
}
c.set(0);
Thread.sleep(5);
Thread.sleep(1);
}
conn.close();
}