mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@527 b9813039-fb51-4c41-a8b9-e21c2acb5095
81 lines
2.9 KiB
Java
81 lines
2.9 KiB
Java
package com.alibaba.druid.pool;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.ResultSet;
|
|
import java.sql.Statement;
|
|
import java.util.TreeMap;
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
import com.alibaba.druid.pool.vendor.OracleExceptionSorter;
|
|
import com.alibaba.druid.stat.JdbcStatManager;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
|
public class TestOracle_DruidDataSource extends TestCase {
|
|
|
|
private String jdbcUrl;
|
|
private String user;
|
|
private String password;
|
|
|
|
public void setUp() throws Exception {
|
|
jdbcUrl = "jdbc:oracle:thin:@10.20.149.85:1521:ocnauto";
|
|
// jdbcUrl = "jdbc:oracle:thin:@20.20.149.85:1521:ocnauto"; // error url
|
|
user = "alibaba";
|
|
password = "ccbuauto";
|
|
}
|
|
|
|
public void test_0() throws Exception {
|
|
final String SQL = "SELECT SYSDATE FROM DUAL";
|
|
final DruidDataSource dataSource = new DruidDataSource();
|
|
dataSource.setUrl(jdbcUrl);
|
|
dataSource.setUsername(user);
|
|
dataSource.setPassword(password);
|
|
dataSource.setFilters("stat");
|
|
dataSource.setExceptionSoter(OracleExceptionSorter.class.getName());
|
|
|
|
final int COUNT = 100 * 100;
|
|
final int THREAD_COUNT = 10;
|
|
final CountDownLatch startLatch = new CountDownLatch(1);
|
|
final CountDownLatch endLatch = new CountDownLatch(THREAD_COUNT);
|
|
|
|
for (int i = 0; i < THREAD_COUNT; ++i) {
|
|
Thread thread = new Thread() {
|
|
|
|
public void run() {
|
|
try {
|
|
startLatch.await();
|
|
for (int i = 0; i < COUNT; ++i) {
|
|
Connection conn = dataSource.getConnection();
|
|
Statement stmt = conn.createStatement();
|
|
ResultSet rs = stmt.executeQuery(SQL);
|
|
rs.next();
|
|
rs.close();
|
|
stmt.close();
|
|
conn.close();
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
} finally {
|
|
endLatch.countDown();
|
|
}
|
|
}
|
|
};
|
|
thread.start();
|
|
}
|
|
startLatch.countDown();
|
|
endLatch.await();
|
|
|
|
for (Object item : JdbcStatManager.getInstance().getDataSourceList().values()) {
|
|
String text = JSON.toJSONString(item, SerializerFeature.UseISO8601DateFormat);
|
|
System.out.println(JSON.toJSONString(JSON.parseObject(text, TreeMap.class), true));
|
|
}
|
|
|
|
for (Object item : JdbcStatManager.getInstance().getSqlList().values()) {
|
|
String text = JSON.toJSONString(item, SerializerFeature.UseISO8601DateFormat);
|
|
System.out.println(JSON.toJSONString(JSON.parseObject(text, TreeMap.class), true));
|
|
}
|
|
}
|
|
}
|