mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed : dup close
This commit is contained in:
@@ -3,9 +3,12 @@ package com.alibaba.druid.bvt.pool;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockConnection;
|
||||
import com.alibaba.druid.mock.MockConnectionClosedException;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
|
||||
@@ -17,6 +20,7 @@ public class Bug_for_dupCloseStmtError extends TestCase {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:");
|
||||
dataSource.setPoolPreparedStatements(false);
|
||||
dataSource.setTestOnBorrow(true);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
@@ -26,14 +30,24 @@ public class Bug_for_dupCloseStmtError extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void test_0() throws Exception {
|
||||
public void test_2() throws Exception {
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement("select 1");
|
||||
stmt.setString(1, "xx");
|
||||
|
||||
|
||||
MockConnection mockConn = conn.unwrap(MockConnection.class);
|
||||
mockConn.close();
|
||||
|
||||
MockConnectionClosedException error = null;
|
||||
try {
|
||||
stmt.execute();
|
||||
} catch (MockConnectionClosedException ex) {
|
||||
error = ex;
|
||||
}
|
||||
|
||||
Assert.assertNotNull(error);
|
||||
|
||||
conn.close();
|
||||
stmt.close();
|
||||
}
|
||||
@@ -43,5 +57,6 @@ public class Bug_for_dupCloseStmtError extends TestCase {
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(0, dataSource.getDupCloseCount());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user