mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve wall filter
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package com.alibaba.druid.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
|
||||
public class QueryTimeoutTest extends TestCase {
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:oracle:thin:@10.20.36.21:1521:OINTEST");
|
||||
dataSource.setUsername("alibaba");
|
||||
dataSource.setPassword("deYcR7facWSJtCuDpm2r");
|
||||
dataSource.setInitialSize(1);
|
||||
dataSource.setMaxActive(14);
|
||||
dataSource.setMinIdle(1);
|
||||
dataSource.setMinEvictableIdleTimeMillis(300 * 1000); // 300 / 10
|
||||
dataSource.setTimeBetweenEvictionRunsMillis(180 * 1000); // 180 / 10
|
||||
dataSource.setTestWhileIdle(true);
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.setValidationQuery("SELECT 1 FROM DUAL");
|
||||
dataSource.setFilters("stat");
|
||||
}
|
||||
|
||||
public void test_queryTimeout() throws Exception {
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "SELECT * FROM ws_product WHERE HAVE_IMAGE = 'N' AND ROWNUM < 1000";
|
||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
stmt.setQueryTimeout(1);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
JdbcUtils.printResultSet(rs);
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "SELECT 'x' FROM DUAL";
|
||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
stmt.setQueryTimeout(1);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
JdbcUtils.printResultSet(rs);
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user