bug fixed for create/destroy scheduler & add testcase

This commit is contained in:
wenshao
2014-08-22 11:21:44 +08:00
parent d619c0e195
commit 4ade284fee
4 changed files with 204 additions and 10 deletions
@@ -0,0 +1,52 @@
package com.alibaba.druid.bvt.pool;
import java.sql.Connection;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import junit.framework.TestCase;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.util.JdbcUtils;
public class Large10KTest extends TestCase {
private DruidDataSource[] dataSources = new DruidDataSource[10000];
private ScheduledExecutorService scheduler;
protected void setUp() throws Exception {
scheduler = Executors.newScheduledThreadPool(10);
for (int i = 0; i < dataSources.length; ++i) {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setCreateScheduler(scheduler);
dataSource.setDestroyScheduler(scheduler);
dataSource.setTestOnBorrow(false);
dataSource.setTestWhileIdle(false);
dataSources[i] = dataSource;
}
}
protected void tearDown() throws Exception {
for (int i = 0; i < dataSources.length; ++i) {
JdbcUtils.close(dataSources[i]);
}
scheduler.shutdown();
}
public void test_large() throws Exception {
Connection[] connections = new Connection[dataSources.length * 8];
for (int i = 0; i < dataSources.length; ++i) {
for (int j = 0; j < 8; ++j) {
connections[i * 8 + j] = dataSources[i].getConnection();
}
}
for (int i = 0; i < dataSources.length; ++i) {
for (int j = 0; j < 8; ++j) {
connections[i * 8 + j].close();
}
}
}
}