mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
package com.alibaba.druid.bvt.pool.exception;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.alibaba.druid.pool.vendor.OracleExceptionSorter;
|
||||
import com.alibaba.druid.test.util.OracleMockDriver;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class OracleExceptionSorterTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setExceptionSorter(new OracleExceptionSorter());
|
||||
|
||||
dataSource.setDriver(new OracleMockDriver());
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setMaxOpenPreparedStatements(100);
|
||||
dataSource.setFilters("log4j");
|
||||
}
|
||||
|
||||
protected void tearDowN() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
|
||||
public void test_connect() throws Exception {
|
||||
String sql = "SELECT 1";
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection();
|
||||
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||
pstmt.execute();
|
||||
pstmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
DruidPooledConnection conn = dataSource.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||
pstmt.setFetchSize(1000);
|
||||
|
||||
SQLException exception = new SQLException("xx", "xxx", 28);
|
||||
boolean fatal = false;
|
||||
try {
|
||||
conn.handleException(exception);
|
||||
} catch (SQLException ex) {
|
||||
fatal = true;
|
||||
}
|
||||
Assert.assertTrue(fatal);
|
||||
|
||||
pstmt.close();
|
||||
|
||||
SQLException commetError = null;
|
||||
try {
|
||||
conn.commit();
|
||||
} catch (SQLException ex) {
|
||||
commetError = ex;
|
||||
}
|
||||
|
||||
Assert.assertNotNull(commetError);
|
||||
Assert.assertSame(exception, commetError.getCause());
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package com.alibaba.druid.bvt.pool.exception;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.mock.MockConnection;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.alibaba.druid.pool.vendor.OracleExceptionSorter;
|
||||
import com.alibaba.druid.test.util.OracleMockDriver;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class OracleExceptionSorterTest_closeConn extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setExceptionSorter(new OracleExceptionSorter());
|
||||
|
||||
dataSource.setDriver(new OracleMockDriver());
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setMaxOpenPreparedStatements(100);
|
||||
}
|
||||
|
||||
protected void tearDowN() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
|
||||
public void test_connect() throws Exception {
|
||||
String sql = "SELECT 1";
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection();
|
||||
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||
pstmt.execute();
|
||||
pstmt.close();
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(1, dataSource.getCreateCount());
|
||||
}
|
||||
|
||||
DruidPooledConnection conn = dataSource.getConnection();
|
||||
MockConnection mockConn = conn.unwrap(MockConnection.class);
|
||||
Assert.assertNotNull(mockConn);
|
||||
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||
pstmt.setFetchSize(1000);
|
||||
|
||||
SQLException exception = new SQLException("xx", "xxx", 28);
|
||||
mockConn.setError(exception);
|
||||
|
||||
conn.close();
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(2, dataSource.getCreateCount());
|
||||
}
|
||||
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package com.alibaba.druid.bvt.pool.exception;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.mock.MockConnection;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.alibaba.druid.pool.vendor.OracleExceptionSorter;
|
||||
import com.alibaba.druid.test.util.OracleMockDriver;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class OracleExceptionSorterTest_closeConn_1 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setExceptionSorter(new OracleExceptionSorter());
|
||||
|
||||
dataSource.setDriver(new OracleMockDriver());
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setMaxOpenPreparedStatements(100);
|
||||
}
|
||||
|
||||
protected void tearDowN() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
|
||||
public void test_connect() throws Exception {
|
||||
String sql = "SELECT 1";
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection();
|
||||
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||
pstmt.execute();
|
||||
pstmt.close();
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(1, dataSource.getCreateCount());
|
||||
}
|
||||
|
||||
DruidPooledConnection conn = dataSource.getConnection();
|
||||
MockConnection mockConn = conn.unwrap(MockConnection.class);
|
||||
Assert.assertNotNull(mockConn);
|
||||
|
||||
conn.prepareStatement(sql);
|
||||
|
||||
SQLException exception = new SQLException("xx", "xxx", 28);
|
||||
mockConn.setError(exception);
|
||||
|
||||
conn.close();
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(2, dataSource.getCreateCount());
|
||||
}
|
||||
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package com.alibaba.druid.bvt.pool.exception;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.mock.MockConnection;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.alibaba.druid.pool.vendor.OracleExceptionSorter;
|
||||
import com.alibaba.druid.test.util.OracleMockDriver;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class OracleExceptionSorterTest_closeConn_2 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setExceptionSorter(new OracleExceptionSorter());
|
||||
|
||||
dataSource.setDriver(new OracleMockDriver());
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setMaxOpenPreparedStatements(100);
|
||||
}
|
||||
|
||||
protected void tearDowN() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
|
||||
public void test_connect() throws Exception {
|
||||
String sql = "SELECT 1";
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection();
|
||||
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||
pstmt.execute();
|
||||
pstmt.close();
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(1, dataSource.getCreateCount());
|
||||
}
|
||||
|
||||
DruidPooledConnection conn = dataSource.getConnection();
|
||||
MockConnection mockConn = conn.unwrap(MockConnection.class);
|
||||
Assert.assertNotNull(mockConn);
|
||||
|
||||
conn.setAutoCommit(false);
|
||||
|
||||
SQLException exception = new SQLException("xx", "xxx", 28);
|
||||
mockConn.setError(exception);
|
||||
|
||||
conn.close();
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(2, dataSource.getCreateCount());
|
||||
}
|
||||
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package com.alibaba.druid.bvt.pool.exception;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.mock.MockConnection;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.alibaba.druid.pool.vendor.OracleExceptionSorter;
|
||||
import com.alibaba.druid.test.util.OracleMockDriver;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class OracleExceptionSorterTest_closeConn_3 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setExceptionSorter(new OracleExceptionSorter());
|
||||
|
||||
dataSource.setDriver(new OracleMockDriver());
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setMaxOpenPreparedStatements(100);
|
||||
}
|
||||
|
||||
protected void tearDowN() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
|
||||
public void test_connect() throws Exception {
|
||||
String sql = "SELECT 1";
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection();
|
||||
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||
pstmt.execute();
|
||||
pstmt.close();
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(1, dataSource.getCreateCount());
|
||||
}
|
||||
|
||||
DruidPooledConnection conn = dataSource.getConnection();
|
||||
MockConnection mockConn = conn.unwrap(MockConnection.class);
|
||||
Assert.assertNotNull(mockConn);
|
||||
|
||||
conn.setAutoCommit(false);
|
||||
conn.setReadOnly(false);
|
||||
|
||||
SQLException exception = new SQLException("xx", "xxx", 28);
|
||||
mockConn.setError(exception);
|
||||
|
||||
conn.close();
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(2, dataSource.getCreateCount());
|
||||
}
|
||||
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package com.alibaba.druid.bvt.pool.exception;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.mock.MockConnection;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.alibaba.druid.pool.vendor.OracleExceptionSorter;
|
||||
import com.alibaba.druid.test.util.OracleMockDriver;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class OracleExceptionSorterTest_closeStmt extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setExceptionSorter(new OracleExceptionSorter());
|
||||
|
||||
dataSource.setDriver(new OracleMockDriver());
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setMaxOpenPreparedStatements(100);
|
||||
}
|
||||
|
||||
protected void tearDowN() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
|
||||
public void test_connect() throws Exception {
|
||||
String sql = "SELECT 1";
|
||||
{
|
||||
DruidPooledConnection conn = dataSource.getConnection();
|
||||
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||
pstmt.execute();
|
||||
pstmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
DruidPooledConnection conn = dataSource.getConnection();
|
||||
MockConnection mockConn = conn.unwrap(MockConnection.class);
|
||||
Assert.assertNotNull(mockConn);
|
||||
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||
pstmt.setFetchSize(1000);
|
||||
|
||||
SQLException exception = new SQLException("xx", "xxx", 28);
|
||||
mockConn.setError(exception);
|
||||
|
||||
SQLException closedErrror = null;
|
||||
try {
|
||||
pstmt.close();
|
||||
} catch (SQLException ex) {
|
||||
closedErrror = ex;
|
||||
}
|
||||
Assert.assertNotNull(closedErrror);
|
||||
Assert.assertSame(exception, closedErrror);
|
||||
|
||||
SQLException commetError = null;
|
||||
try {
|
||||
conn.commit();
|
||||
} catch (SQLException ex) {
|
||||
commetError = ex;
|
||||
}
|
||||
|
||||
Assert.assertNotNull(commetError);
|
||||
Assert.assertSame(exception, commetError.getCause());
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user