mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add validationQuery check
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Connection;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class ValidationQueryLogDB2Test extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setDbType(JdbcConstants.DB2);
|
||||
dataSource.setDriver(new MockDriver() {
|
||||
public int getMajorVersion() {
|
||||
return 10;
|
||||
}
|
||||
});
|
||||
dataSource.setValidationQuery("SELECT 'x'");
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_oracle() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
conn.close();
|
||||
|
||||
Field field = DruidDataSource.class.getDeclaredField("LOG");
|
||||
field.setAccessible(true);
|
||||
Log log = (Log) field.get(null);
|
||||
Assert.assertEquals(1, log.getErrorCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Connection;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class ValidationQueryLogTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setDbType(JdbcConstants.ORACLE);
|
||||
dataSource.setDriver(new MockDriver() {
|
||||
public int getMajorVersion() {
|
||||
return 10;
|
||||
}
|
||||
});
|
||||
dataSource.setValidationQuery("SELECT 'x'");
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_oracle() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
conn.close();
|
||||
|
||||
Field field = DruidDataSource.class.getDeclaredField("LOG");
|
||||
field.setAccessible(true);
|
||||
Log log = (Log) field.get(null);
|
||||
Assert.assertEquals(1, log.getErrorCount());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user