mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
change version & test
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user