mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add test
This commit is contained in:
@@ -33,11 +33,11 @@ public class TestMySqlPing extends TestCase {
|
||||
|
||||
Connection conn = DriverManager.getConnection(jdbcUrl, user, password);
|
||||
|
||||
com.mysql.jdbc.Connection oracleConn = (com.mysql.jdbc.Connection) conn;
|
||||
com.mysql.jdbc.Connection mysqlConn = (com.mysql.jdbc.Connection) conn;
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
ping_1000(oracleConn);
|
||||
select_1000(oracleConn);
|
||||
ping_1000(mysqlConn);
|
||||
select_1000(mysqlConn);
|
||||
}
|
||||
|
||||
conn.close();
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.alibaba.druid;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class TestMySqlPing2 extends TestCase {
|
||||
|
||||
private String jdbcUrl;
|
||||
private String user;
|
||||
private String password;
|
||||
private String driverClass;
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
// jdbcUrl = "jdbc:oracle:thin:@10.20.149.85:1521:ocnauto";
|
||||
// user = "alibaba";
|
||||
// password = "ccbuauto";
|
||||
// SQL = "SELECT * FROM WP_ORDERS WHERE ID = ?";
|
||||
|
||||
jdbcUrl = "jdbc:mysql://10.20.147.142:3308/dragoon_v25_masterdb";
|
||||
user = "dragoon_admin";
|
||||
password = "dragoon_root";
|
||||
|
||||
driverClass = "com.mysql.jdbc.Driver";
|
||||
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl(jdbcUrl);
|
||||
dataSource.setUsername(user);
|
||||
dataSource.setPassword(password);
|
||||
|
||||
dataSource.setMaxActive(4);
|
||||
dataSource.setMinIdle(1);
|
||||
dataSource.setTestOnBorrow(true);
|
||||
}
|
||||
|
||||
public void test_o() throws Exception {
|
||||
{
|
||||
Connection[] connections = new Connection[3];
|
||||
for (int i = 0; i < connections.length; ++i) {
|
||||
connections[i] = dataSource.getConnection();
|
||||
}
|
||||
|
||||
for (int i = 0; i < connections.length; ++i) {
|
||||
Statement stmt = connections[i].createStatement();
|
||||
ResultSet rs = stmt.executeQuery("select now()");
|
||||
JdbcUtils.printResultSet(rs);
|
||||
rs.close();
|
||||
stmt.close();
|
||||
}
|
||||
|
||||
for (int i = 0; i < connections.length; ++i) {
|
||||
connections[i].close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Thread.sleep(1000 * 60 * 60); // 60 minutes
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("select now()");
|
||||
JdbcUtils.printResultSet(rs);
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void pring(com.mysql.jdbc.Connection oracleConn) throws SQLException {
|
||||
oracleConn.ping();
|
||||
}
|
||||
|
||||
public void select(com.mysql.jdbc.Connection oracleConn) throws SQLException {
|
||||
Statement stmt = oracleConn.createStatement();
|
||||
stmt.execute("SELECT 'x'");
|
||||
stmt.close();
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,10 @@ public class MustParameterizedTest3 extends TestCase {
|
||||
Assert.assertFalse(WallUtils.isValidateMySql("delete from t where id = 'aa' + 'bbb'", config));
|
||||
Assert.assertTrue(WallUtils.isValidateMySql("select * from t where id = ? ORDER BY 1", config));
|
||||
Assert.assertTrue(WallUtils.isValidateMySql("select 1, 2, 3 from t where id = ?", config));
|
||||
Assert.assertFalse(WallUtils.isValidateMySql("select 1, 2, 3 from t where id = 7", config));
|
||||
Assert.assertFalse(WallUtils.isValidateMySql("select 1, 2, 3 from t where id = ? union select * from t", config));
|
||||
Assert.assertFalse(WallUtils.isValidateMySql("select 1, 2, 3 from t where id = ? union select * from t fid = fid", config));
|
||||
Assert.assertFalse(WallUtils.isValidateMySql("select 1, 2, 3 from t where id = ? union select * from t fid > 5", config));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user