mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add testcase & bug fixed
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.ValidConnectionChecker;
|
||||
|
||||
public class DruidDataSourceTest5 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
private final AtomicBoolean validate = new AtomicBoolean(true);
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
validate.set(true);
|
||||
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.setInitialSize(1);
|
||||
|
||||
dataSource.setValidConnectionChecker(new ValidConnectionChecker() {
|
||||
|
||||
@Override
|
||||
public boolean isValidConnection(Connection c, String query, int validationQueryTimeout) {
|
||||
return validate.get();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void testValidate() throws Exception {
|
||||
validate.set(false);
|
||||
|
||||
Exception error = null;
|
||||
try {
|
||||
dataSource.getConnection();
|
||||
} catch (SQLException e) {
|
||||
error = e;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
|
||||
validate.set(true);
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void testValidate_1() throws Exception {
|
||||
validate.set(false);
|
||||
|
||||
Exception error = null;
|
||||
try {
|
||||
dataSource.init();
|
||||
} catch (SQLException e) {
|
||||
error = e;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
|
||||
validate.set(true);
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void testValidate_3() throws Exception {
|
||||
validate.set(false);
|
||||
|
||||
Exception error = null;
|
||||
try {
|
||||
dataSource.init();
|
||||
} catch (SQLException e) {
|
||||
error = e;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
|
||||
validate.set(true);
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user