mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add test resource.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package com.alibaba.druid.oracle;
|
||||
|
||||
import com.alibaba.druid.DbTestCase;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
import com.alibaba.druid.support.logging.LogFactory;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
import junit.framework.TestCase;
|
||||
import oracle.jdbc.driver.OracleConnection;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class OracleKillSessionTest extends DbTestCase {
|
||||
private final static Log LOG = LogFactory.getLog(OracleKillSessionTest.class);
|
||||
|
||||
private ScheduledExecutorService scheduler;
|
||||
|
||||
public OracleKillSessionTest() {
|
||||
super("pool_config/oracle_db_sonar.properties");
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
scheduler = Executors.newScheduledThreadPool(10);
|
||||
}
|
||||
|
||||
public void test_connect() throws Exception {
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
runSql();
|
||||
}
|
||||
//
|
||||
// for (int i = 0; i < 5; ++i) {
|
||||
// Task task = new Task();
|
||||
// scheduler.scheduleWithFixedDelay(task, 0, 30, TimeUnit.SECONDS);
|
||||
// }
|
||||
//
|
||||
Thread.sleep(1000 * 1000);
|
||||
}
|
||||
|
||||
public void runSql() throws Exception {
|
||||
Connection conn = null;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = getConnection();
|
||||
OracleConnection unwrapped = (OracleConnection) conn.unwrap(Connection.class);
|
||||
|
||||
pstmt = conn.prepareStatement("select 1 from dual");
|
||||
rs = pstmt.executeQuery();
|
||||
JdbcUtils.printResultSet(rs);
|
||||
} finally {
|
||||
JdbcUtils.close(rs);
|
||||
JdbcUtils.close(pstmt);
|
||||
JdbcUtils.close(conn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Task implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Connection conn = getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement("select 1 from dual");
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
JdbcUtils.printResultSet(rs);
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
conn.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.alibaba.druid.oracle;
|
||||
|
||||
import com.alibaba.druid.DbTestCase;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 23/07/2017.
|
||||
*/
|
||||
public class Oracle_PSCacheTest extends DbTestCase {
|
||||
public Oracle_PSCacheTest() {
|
||||
super("pool_config/oracle_db_sonar.properties");
|
||||
}
|
||||
|
||||
public void test_oracle() throws Exception {
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
System.out.println(i + " : -----------------------------");
|
||||
Connection conn = null;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = getConnection();
|
||||
pstmt = conn.prepareStatement("select * from t1 where f0 = ?");
|
||||
pstmt.setString(1, "3");
|
||||
rs = pstmt.executeQuery();
|
||||
JdbcUtils.printResultSet(rs);
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
JdbcUtils.close(rs);
|
||||
JdbcUtils.close(pstmt);
|
||||
JdbcUtils.close(conn);
|
||||
}
|
||||
|
||||
Thread.sleep(3000);
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.alibaba.druid.oracle;
|
||||
|
||||
import com.alibaba.druid.DbTestCase;
|
||||
import com.alibaba.druid.benckmark.proxy.BenchmarkExecutor;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
import com.alibaba.druid.util.OracleUtils;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 23/07/2017.
|
||||
*/
|
||||
public class Oracle_PSCacheTest2 extends DbTestCase {
|
||||
public Oracle_PSCacheTest2() {
|
||||
super("pool_config/oracle_db_sonar.properties");
|
||||
}
|
||||
|
||||
Connection connDDL;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
connDDL = DriverManager.getConnection("jdbc:oracle:thin:@47.94.57.164:1521:prod11g", "ecs_user", "adam123456");
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(connDDL);
|
||||
}
|
||||
|
||||
public void test_oracle() throws Exception {
|
||||
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@47.94.57.164:1521:prod11g", "ecs_user", "adam123456");
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
String sql = "select * from t1 where f0 = ?";
|
||||
|
||||
pstmt = conn.prepareStatement(sql);
|
||||
executeQuery(pstmt);
|
||||
|
||||
OracleUtils.enterImplicitCache(pstmt);
|
||||
OracleUtils.exitImplicitCacheToActive(pstmt);
|
||||
executeQuery(pstmt);
|
||||
|
||||
addColumn();
|
||||
|
||||
pstmt.close();
|
||||
pstmt = conn.prepareStatement(sql);
|
||||
|
||||
executeQuery(pstmt);
|
||||
dropColumn();
|
||||
|
||||
JdbcUtils.close(conn);
|
||||
|
||||
}
|
||||
|
||||
private void executeQuery(PreparedStatement pstmt) throws SQLException {
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
pstmt.clearParameters();
|
||||
pstmt.setString(1, "3");
|
||||
rs = pstmt.executeQuery();
|
||||
JdbcUtils.printResultSet(rs);
|
||||
} finally {
|
||||
JdbcUtils.close(rs);
|
||||
}
|
||||
}
|
||||
|
||||
void addColumn() throws Exception {
|
||||
Statement stmt = null;
|
||||
stmt = connDDL.createStatement();
|
||||
stmt.execute("alter table t1 add (f1 varchar2(20))");
|
||||
stmt.close();
|
||||
}
|
||||
|
||||
void dropColumn() throws Exception {
|
||||
Statement stmt = null;
|
||||
stmt = connDDL.createStatement();
|
||||
stmt.execute("alter table t1 drop column f1");
|
||||
stmt.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user