mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
testcase
This commit is contained in:
@@ -1,81 +1,81 @@
|
||||
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.setInitialSize(1);
|
||||
dataSource.setUrl(jdbcUrl);
|
||||
dataSource.setUsername(user);
|
||||
dataSource.setPassword(password);
|
||||
dataSource.setFilters("stat");
|
||||
dataSource.setExceptionSorter(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));
|
||||
}
|
||||
}
|
||||
}
|
||||
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.setInitialSize(1);
|
||||
dataSource.setUrl(jdbcUrl);
|
||||
dataSource.setUsername(user);
|
||||
dataSource.setPassword(password);
|
||||
dataSource.setFilters("stat");
|
||||
dataSource.setExceptionSorter(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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user