增加BoneCP的测试

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@39 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-05-12 10:00:50 +00:00
parent 15b9475569
commit a796dfca34
3 changed files with 69 additions and 3 deletions
+18
View File
@@ -74,6 +74,18 @@
<version>1.2.16</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
<scope>provided</scope>
</dependency>
<!-- 用于针对Oracle、MySQL的参数设置优化 -->
<dependency>
@@ -109,6 +121,12 @@
<version>1.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jolbox</groupId>
<artifactId>bonecp</artifactId>
<version>0.7.1.RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
@@ -27,6 +27,7 @@ import org.apache.commons.dbcp.BasicDataSource;
import com.alibaba.druid.TestUtil;
import com.alibaba.druid.pool.DruidDataSource;
import com.jolbox.bonecp.BoneCPDataSource;
public class Case0 extends TestCase {
@@ -39,6 +40,8 @@ public class Case0 extends TestCase {
private int maxPoolSize = 2;
private int maxActive = 2;
private String validationQuery = null;
public final int LOOP_COUNT = 5;
protected void setUp() throws Exception {
jdbcUrl = "jdbc:fake:dragoon_v25masterdb";
@@ -63,7 +66,7 @@ public class Case0 extends TestCase {
dataSource.setValidationQuery(validationQuery);
dataSource.setTestOnBorrow(true);
for (int i = 0; i < 10; ++i) {
for (int i = 0; i < LOOP_COUNT; ++i) {
p0(dataSource, "druid");
}
System.out.println();
@@ -85,11 +88,33 @@ public class Case0 extends TestCase {
dataSource.setValidationQuery("SELECT 1");
dataSource.setTestOnBorrow(true);
for (int i = 0; i < 10; ++i) {
for (int i = 0; i < LOOP_COUNT; ++i) {
p0(dataSource, "dbcp");
}
System.out.println();
}
public void test_2() throws Exception {
BoneCPDataSource dataSource = new BoneCPDataSource();
// dataSource.(10);
// dataSource.setMaxActive(50);
dataSource.setMinConnectionsPerPartition(minPoolSize);
dataSource.setMaxConnectionsPerPartition(maxPoolSize);
dataSource.setDriverClass(driverClass);
dataSource.setJdbcUrl(jdbcUrl);
// dataSource.setPoolPreparedStatements(true);
// dataSource.setMaxOpenPreparedStatements(100);
dataSource.setUsername(user);
dataSource.setPassword(password);
dataSource.setConnectionTestStatement("SELECT 1");
dataSource.setPartitionCount(1);
for (int i = 0; i < LOOP_COUNT; ++i) {
p0(dataSource, "boneCP");
}
System.out.println();
}
private void p0(DataSource dataSource, String name) throws SQLException {
long startMillis = System.currentTimeMillis();
@@ -27,6 +27,7 @@ import org.apache.commons.dbcp.BasicDataSource;
import com.alibaba.druid.TestUtil;
import com.alibaba.druid.pool.DruidDataSource;
import com.jolbox.bonecp.BoneCPDataSource;
public class Case1 extends TestCase {
@@ -39,7 +40,7 @@ public class Case1 extends TestCase {
private int maxPoolSize = 2;
private int maxActive = 2;
private String validationQuery = "SELECT 1";
private int threadCount = 20;
private int threadCount = 2;
private int loopCount = 5;
protected void setUp() throws Exception {
@@ -92,6 +93,28 @@ public class Case1 extends TestCase {
}
System.out.println();
}
public void test_2() throws Exception {
BoneCPDataSource dataSource = new BoneCPDataSource();
// dataSource.(10);
// dataSource.setMaxActive(50);
dataSource.setMinConnectionsPerPartition(minPoolSize);
dataSource.setMaxConnectionsPerPartition(maxPoolSize);
dataSource.setDriverClass(driverClass);
dataSource.setJdbcUrl(jdbcUrl);
// dataSource.setPoolPreparedStatements(true);
// dataSource.setMaxOpenPreparedStatements(100);
dataSource.setUsername(user);
dataSource.setPassword(password);
dataSource.setConnectionTestStatement("SELECT 1");
dataSource.setPartitionCount(1);
for (int i = 0; i < loopCount; ++i) {
p0(dataSource, "boneCP", threadCount);
}
System.out.println();
}
private void p0(final DataSource dataSource, String name, int threadCount) throws Exception {