mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add testcase & bug fixed for DruidConnectionHolderInitError
This commit is contained in:
@@ -18,7 +18,7 @@ public class DruidConnectionHolderTest extends TestCase {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setInitialSize(1);
|
||||
dataSource.getProxyFilters().add(new FilterAdapter() {
|
||||
|
||||
public int connection_getTransactionIsolation(FilterChain chain, ConnectionProxy connection)
|
||||
@@ -34,7 +34,8 @@ public class DruidConnectionHolderTest extends TestCase {
|
||||
}
|
||||
|
||||
public void test_mysqlSyntaxError() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.close();
|
||||
dataSource.init();
|
||||
|
||||
dataSource.getConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.filter.FilterAdapter;
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.GetConnectionTimeoutException;
|
||||
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
|
||||
|
||||
public class DruidConnectionHolderTest2 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.getProxyFilters().add(new FilterAdapter() {
|
||||
|
||||
public int connection_getTransactionIsolation(FilterChain chain, ConnectionProxy connection)
|
||||
throws SQLException {
|
||||
throw new SQLException();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_mysqlSyntaxError() throws Exception {
|
||||
Exception error = null;
|
||||
try {
|
||||
dataSource.getConnection(100);
|
||||
} catch (GetConnectionTimeoutException e) {
|
||||
error = e;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.filter.FilterAdapter;
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.GetConnectionTimeoutException;
|
||||
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
|
||||
|
||||
public class DruidConnectionHolderTest3 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.setInitialSize(1);
|
||||
dataSource.getProxyFilters().add(new FilterAdapter() {
|
||||
|
||||
public int connection_getTransactionIsolation(FilterChain chain, ConnectionProxy connection)
|
||||
throws SQLException {
|
||||
throw new MySQLException();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_mysqlSyntaxError() throws Exception {
|
||||
{
|
||||
Exception error = null;
|
||||
try {
|
||||
dataSource.init();
|
||||
} catch (MySQLException e) {
|
||||
error = e;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
Assert.assertEquals(0, dataSource.getPoolingCount());
|
||||
|
||||
Exception error = null;
|
||||
try {
|
||||
dataSource.getConnection(100);
|
||||
} catch (GetConnectionTimeoutException e) {
|
||||
error = e;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
public static class MySQLException extends SQLException {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey;
|
||||
import com.alibaba.druid.pool.PreparedStatementPool.MethodType;
|
||||
|
||||
public class PreparedStatementKeyTest extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
PreparedStatementKey k1 = new PreparedStatementKey("select 'a'", "c1", MethodType.M1, 101, 102, 103);
|
||||
Assert.assertEquals(101, k1.getResultSetType());
|
||||
Assert.assertEquals(102, k1.getResultSetConcurrency());
|
||||
Assert.assertEquals(103, k1.getResultSetHoldability());
|
||||
}
|
||||
|
||||
public void test_eq() throws Exception {
|
||||
Assert.assertEquals(new PreparedStatementKey("select 'a'", "c1", MethodType.M1, 101, 102, 103),
|
||||
new PreparedStatementKey("select 'a'", "c1", MethodType.M1, 101, 102, 103));
|
||||
|
||||
}
|
||||
|
||||
public void test_not_eq() throws Exception {
|
||||
Assert.assertFalse( //
|
||||
new PreparedStatementKey("select 'a'", "c1", MethodType.M1, 101, 102, 103).equals( //
|
||||
new PreparedStatementKey("select 'a'", "c1", MethodType.M1, 201, 102, 103)));
|
||||
|
||||
}
|
||||
|
||||
public void test_not_eq_1() throws Exception {
|
||||
Assert.assertFalse( //
|
||||
new PreparedStatementKey("select 'a'", "c1", MethodType.M1, 101, 102, 103).equals( //
|
||||
new PreparedStatementKey("select 'a'", "c1", MethodType.M1, 101, 202, 103)));
|
||||
|
||||
}
|
||||
|
||||
public void test_not_eq_2() throws Exception {
|
||||
Assert.assertFalse( //
|
||||
new PreparedStatementKey("select 'a'", "c1", MethodType.M1, 101, 102, 103).equals( //
|
||||
new PreparedStatementKey("select 'a'", "c1", MethodType.M1, 101, 102, 203)));
|
||||
|
||||
}
|
||||
|
||||
public void test_not_eq_3() throws Exception {
|
||||
Assert.assertFalse( //
|
||||
new PreparedStatementKey("select 'a'", "c1", MethodType.M1, 101, 102, 103).equals( //
|
||||
new PreparedStatementKey("select 'a'", "c1", MethodType.M2, 101, 102, 103)));
|
||||
|
||||
}
|
||||
|
||||
public void test_not_eq_4() throws Exception {
|
||||
Assert.assertFalse( //
|
||||
new PreparedStatementKey("select 'a'", "c1", MethodType.M1, 101, 102, 103).equals( //
|
||||
new PreparedStatementKey("select 'a'", "c2", MethodType.M1, 101, 102, 103)));
|
||||
|
||||
}
|
||||
|
||||
public void test_not_eq_5() throws Exception {
|
||||
Assert.assertFalse( //
|
||||
new PreparedStatementKey("select 'a'", "c1", MethodType.M1, 101, 102, 103).equals( //
|
||||
new PreparedStatementKey("select 'b'", "c1", MethodType.M1, 101, 102, 103)));
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user