improved DruidDataSource for profile

This commit is contained in:
高铁
2016-02-02 16:04:42 +08:00
parent cdeec1f73c
commit 1dfe8112a7
8 changed files with 142 additions and 22 deletions
@@ -49,7 +49,7 @@ public class PoolableCallableStatementTest extends TestCase {
protected void setUp() throws Exception {
MockConnection mockConn = new MockConnection();
DruidConnectionHolder connHolder = new DruidConnectionHolder(dataSource, mockConn);
DruidConnectionHolder connHolder = new DruidConnectionHolder(dataSource, mockConn, 0);
conn = new DruidPooledConnection(connHolder);
raw = new MockCallableStatement(null, null);
stmt = new DruidPooledCallableStatement(conn, new PreparedStatementHolder(new PreparedStatementKey("", null,
@@ -45,7 +45,7 @@ public class PoolablePreparedStatementTest extends TestCase {
protected void setUp() throws Exception {
DruidDataSource dataSource = new DruidDataSource();
MockConnection mockConn = new MockConnection();
DruidConnectionHolder connHolder = new DruidConnectionHolder(dataSource, mockConn);
DruidConnectionHolder connHolder = new DruidConnectionHolder(dataSource, mockConn, 0);
DruidPooledConnection conn = new DruidPooledConnection(connHolder);
raw = new MockPreparedStatement(null, null);
@@ -162,7 +162,7 @@ public class PreparedStatementKeyTest extends TestCase {
MockConnection conn = new MockConnection();
PreparedStatementKey k1 = new PreparedStatementKey("x1", "c1", MethodType.M1);
PreparedStatementPool pool = new PreparedStatementPool(new DruidConnectionHolder(dataSource, conn));
PreparedStatementPool pool = new PreparedStatementPool(new DruidConnectionHolder(dataSource, conn, 0));
MockPreparedStatement raw = new MockPreparedStatement(null, null);
pool.put(new PreparedStatementHolder(k1, raw));
@@ -0,0 +1,32 @@
package com.alibaba.druid.bvt.pool.profile;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import junit.framework.TestCase;
public class ProfileEnableTest extends TestCase {
private DruidDataSource dataSource;
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setMaxWait(1000);
}
protected void tearDown() throws Exception {
dataSource.close();
}
public void testDefault() throws Exception {
for (int i = 0; i < 10; ++i) {
DruidPooledConnection conn = dataSource.getConnection();
System.out.println("physicalConnectNanoSpan : " + conn.getPhysicalConnectNanoSpan());
System.out.println("physicalConnectionUsedCount : " + conn.getPhysicalConnectionUsedCount());
System.out.println("connectNotEmptyWaitNanos : " + conn.getConnectNotEmptyWaitNanos());
conn.close();
}
}
}