mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for exception sorter
This commit is contained in:
+6
@@ -1,5 +1,6 @@
|
||||
package com.alibaba.druid.bvt.pool.exception;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@@ -59,6 +60,11 @@ public class OracleExceptionSorterTest_closeConn extends TestCase {
|
||||
mockConn.setError(exception);
|
||||
|
||||
conn.close();
|
||||
|
||||
{
|
||||
Connection conn2 = dataSource.getConnection();
|
||||
conn2.close();
|
||||
}
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(2, dataSource.getCreateCount());
|
||||
|
||||
+6
@@ -1,5 +1,6 @@
|
||||
package com.alibaba.druid.bvt.pool.exception;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@@ -58,6 +59,11 @@ public class OracleExceptionSorterTest_closeConn_1 extends TestCase {
|
||||
mockConn.setError(exception);
|
||||
|
||||
conn.close();
|
||||
|
||||
{
|
||||
Connection conn2 = dataSource.getConnection();
|
||||
conn2.close();
|
||||
}
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(2, dataSource.getCreateCount());
|
||||
|
||||
+6
@@ -1,5 +1,6 @@
|
||||
package com.alibaba.druid.bvt.pool.exception;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@@ -58,6 +59,11 @@ public class OracleExceptionSorterTest_closeConn_2 extends TestCase {
|
||||
mockConn.setError(exception);
|
||||
|
||||
conn.close();
|
||||
|
||||
{
|
||||
Connection conn2 = dataSource.getConnection();
|
||||
conn2.close();
|
||||
}
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(2, dataSource.getCreateCount());
|
||||
|
||||
+6
@@ -1,5 +1,6 @@
|
||||
package com.alibaba.druid.bvt.pool.exception;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@@ -59,6 +60,11 @@ public class OracleExceptionSorterTest_closeConn_3 extends TestCase {
|
||||
mockConn.setError(exception);
|
||||
|
||||
conn.close();
|
||||
|
||||
{
|
||||
Connection conn2 = dataSource.getConnection();
|
||||
conn2.close();
|
||||
}
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(2, dataSource.getCreateCount());
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package com.alibaba.druid.bvt.pool.exception;
|
||||
|
||||
import java.sql.Connection;
|
||||
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_commit 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.prepareStatement(sql);
|
||||
|
||||
SQLException exception = new SQLException("xx", "xxx", 28);
|
||||
mockConn.setError(exception);
|
||||
|
||||
Exception commitError = null;
|
||||
try {
|
||||
conn.commit();
|
||||
} catch (Exception ex) {
|
||||
commitError = ex;
|
||||
}
|
||||
Assert.assertNotNull(commitError);
|
||||
|
||||
conn.close();
|
||||
|
||||
{
|
||||
Connection conn2 = dataSource.getConnection();
|
||||
conn2.close();
|
||||
}
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(2, dataSource.getCreateCount());
|
||||
}
|
||||
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package com.alibaba.druid.bvt.pool.exception;
|
||||
|
||||
import java.sql.Connection;
|
||||
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_rollback 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);
|
||||
|
||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
stmt.execute();
|
||||
|
||||
SQLException exception = new SQLException("xx", "xxx", 28);
|
||||
mockConn.setError(exception);
|
||||
|
||||
Exception rollbackError = null;
|
||||
try {
|
||||
conn.rollback();
|
||||
} catch (Exception ex) {
|
||||
rollbackError = ex;
|
||||
}
|
||||
Assert.assertNotNull(rollbackError);
|
||||
|
||||
conn.close();
|
||||
|
||||
{
|
||||
Connection conn2 = dataSource.getConnection();
|
||||
conn2.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.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
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_setCatalog 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);
|
||||
|
||||
SQLException exception = new SQLException("xx", "xxx", 28);
|
||||
mockConn.setError(exception);
|
||||
|
||||
Exception setError = null;
|
||||
try {
|
||||
conn.setCatalog("xxx");
|
||||
} catch (Exception ex) {
|
||||
setError = ex;
|
||||
}
|
||||
Assert.assertNotNull(setError);
|
||||
|
||||
conn.close();
|
||||
|
||||
{
|
||||
Connection conn2 = dataSource.getConnection();
|
||||
conn2.close();
|
||||
}
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(2, dataSource.getCreateCount());
|
||||
}
|
||||
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package com.alibaba.druid.bvt.pool.exception;
|
||||
|
||||
import java.sql.Connection;
|
||||
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_setIsolationLevel 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);
|
||||
|
||||
SQLException exception = new SQLException("xx", "xxx", 28);
|
||||
mockConn.setError(exception);
|
||||
|
||||
Exception setError = null;
|
||||
try {
|
||||
conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
|
||||
} catch (Exception ex) {
|
||||
setError = ex;
|
||||
}
|
||||
Assert.assertNotNull(setError);
|
||||
|
||||
conn.close();
|
||||
|
||||
{
|
||||
Connection conn2 = dataSource.getConnection();
|
||||
conn2.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.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
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_setReadOnly 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);
|
||||
|
||||
SQLException exception = new SQLException("xx", "xxx", 28);
|
||||
mockConn.setError(exception);
|
||||
|
||||
Exception setError = null;
|
||||
try {
|
||||
conn.setReadOnly(true);
|
||||
} catch (Exception ex) {
|
||||
setError = ex;
|
||||
}
|
||||
Assert.assertNotNull(setError);
|
||||
|
||||
conn.close();
|
||||
|
||||
{
|
||||
Connection conn2 = dataSource.getConnection();
|
||||
conn2.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.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
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_setSavepoint 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);
|
||||
|
||||
SQLException exception = new SQLException("xx", "xxx", 28);
|
||||
mockConn.setError(exception);
|
||||
|
||||
Exception setError = null;
|
||||
try {
|
||||
conn.setSavepoint();
|
||||
} catch (Exception ex) {
|
||||
setError = ex;
|
||||
}
|
||||
Assert.assertNotNull(setError);
|
||||
|
||||
conn.close();
|
||||
|
||||
{
|
||||
Connection conn2 = dataSource.getConnection();
|
||||
conn2.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.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
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_setSavepointWithName 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);
|
||||
|
||||
SQLException exception = new SQLException("xx", "xxx", 28);
|
||||
mockConn.setError(exception);
|
||||
|
||||
Exception setError = null;
|
||||
try {
|
||||
conn.setSavepoint("xxx");
|
||||
} catch (Exception ex) {
|
||||
setError = ex;
|
||||
}
|
||||
Assert.assertNotNull(setError);
|
||||
|
||||
conn.close();
|
||||
|
||||
{
|
||||
Connection conn2 = dataSource.getConnection();
|
||||
conn2.close();
|
||||
}
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(2, dataSource.getCreateCount());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user