From babcee9b43858ae23168ea5cf1acccde89192423 Mon Sep 17 00:00:00 2001 From: wenshao Date: Tue, 19 Jul 2011 08:06:22 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.alibabatech.com/svn/druid/trunk@477 b9813039-fb51-4c41-a8b9-e21c2acb5095 --- .../alibaba/druid/bvt/pool/TestClose_2.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/test/java/com/alibaba/druid/bvt/pool/TestClose_2.java diff --git a/src/test/java/com/alibaba/druid/bvt/pool/TestClose_2.java b/src/test/java/com/alibaba/druid/bvt/pool/TestClose_2.java new file mode 100644 index 0000000000..961114f5f6 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/pool/TestClose_2.java @@ -0,0 +1,47 @@ +package com.alibaba.druid.bvt.pool; + +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.ResultSet; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import com.alibaba.druid.pool.DruidDataSource; + +public class TestClose_2 extends TestCase { + + public void test_close() throws Exception { + DruidDataSource dataSource = new DruidDataSource(); + dataSource.setPoolPreparedStatements(true); + dataSource.setUrl("jdbc:mock:xxx"); + + String sql = "SELECT 1"; + + Connection conn = dataSource.getConnection(); + CallableStatement stmt = conn.prepareCall(sql); + ResultSet rs = stmt.executeQuery(); + rs.next(); + Assert.assertEquals(false, rs.isClosed()); + + Assert.assertEquals(false, stmt.isClosed()); + stmt.close(); + Assert.assertEquals(true, stmt.isClosed()); + Assert.assertEquals(true, rs.isClosed()); + + CallableStatement stmt2 = conn.prepareCall(sql); + Assert.assertEquals(false, stmt.isClosed()); + + Assert.assertEquals(stmt, stmt2); + + conn.close(); + + Assert.assertEquals(true, stmt.isClosed()); + Assert.assertEquals(true, rs.isClosed()); + + rs.close(); + stmt.close(); + + dataSource.close(); + } +}