配置和apache dbcp一致

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@5 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-05-11 02:48:31 +00:00
parent 14862fef39
commit 03bee022af
12 changed files with 89 additions and 32 deletions
@@ -10,6 +10,7 @@ import junit.framework.TestCase;
import org.apache.commons.dbcp.BasicDataSource;
import com.alibaba.druid.TestUtil;
import com.alibaba.druid.pool.DruidDataSource;
public class Case0 extends TestCase {
@@ -38,15 +39,16 @@ public class Case0 extends TestCase {
dataSource.setMinIdle(minPoolSize);
dataSource.setMaxIdle(maxPoolSize);
dataSource.setPoolPreparedStatements(true);
dataSource.setDriverClass(driverClass);
dataSource.setDriverClassName(driverClass);
dataSource.setUrl(jdbcUrl);
dataSource.setPoolPreparedStatements(true);
dataSource.setUser(user);
dataSource.setUsername(user);
dataSource.setPassword(password);
for (int i = 0; i < 10; ++i) {
p0(dataSource);
p0(dataSource, "druid");
}
System.out.println();
}
public void test_1() throws Exception {
@@ -64,18 +66,25 @@ public class Case0 extends TestCase {
dataSource.setPassword(password);
for (int i = 0; i < 10; ++i) {
p0(dataSource);
p0(dataSource, "dbcp");
}
System.out.println();
}
private void p0(DataSource dataSource) throws SQLException {
private void p0(DataSource dataSource, String name) throws SQLException {
long startMillis = System.currentTimeMillis();
long startYGC = TestUtil.getYoungGC();
long startFullGC = TestUtil.getFullGC();
final int COUNT = 1000 * 1000;
for (int i = 0; i < COUNT; ++i) {
Connection conn = dataSource.getConnection();
conn.close();
}
long millis = System.currentTimeMillis() - startMillis;
System.out.println(dataSource.getClass().getName() + " millis : " + NumberFormat.getInstance().format(millis));
long ygc = TestUtil.getYoungGC() - startYGC;
long fullGC = TestUtil.getFullGC() - startFullGC;
System.out.println(name + " millis : " + NumberFormat.getInstance().format(millis) + ", YGC " + ygc + " FGC " + fullGC);
}
}