bug fixed : dup close

This commit is contained in:
wenshao
2011-12-08 14:32:30 +08:00
parent e4456b916e
commit b08281a153
3 changed files with 31 additions and 2 deletions
@@ -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());
}
}