change version & test

This commit is contained in:
温少
2012-03-20 12:27:32 +08:00
parent bf98dcad6c
commit c97a268052
2 changed files with 24 additions and 8 deletions
@@ -2,6 +2,7 @@ package com.alibaba.druid.pool;
import java.sql.Connection;
import java.sql.Statement;
import java.util.concurrent.CountDownLatch;
import junit.framework.TestCase;
@@ -16,24 +17,39 @@ public class TestMockPerf extends TestCase {
dataSource.setMinIdle(3);
dataSource.setMaxActive(20);
dataSource.setDbType("mysql");
dataSource.setFilters("wall");
dataSource.setFilters("stat");
dataSource.init();
}
public void test_perf() throws Exception {
final CountDownLatch latch = new CountDownLatch(10);
for (int i = 0; i < 10; ++i) {
long startMillis = System.currentTimeMillis();
perf();
long millis = System.currentTimeMillis() - startMillis;
System.out.println("millis : " + millis);
Thread thread = new Thread() {
public void run() {
try {
long startMillis = System.currentTimeMillis();
perf();
long millis = System.currentTimeMillis() - startMillis;
System.out.println("millis : " + millis);
} catch (Exception e) {
e.printStackTrace();
} finally {
latch.countDown();
}
}
};
thread.start();
}
latch.await();
}
public void perf() throws Exception {
for (int i = 0; i < 1000 * 1000; ++i) {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("SELECT 1");
stmt.execute("SELECT " + i % 1000);
stmt.close();
conn.close();
}