Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 0C7ED9FB250 for ; Sat, 21 Jul 2007 21:02:56 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 68674-06 for ; Sat, 21 Jul 2007 21:02:41 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from gw01.mail.saunalahti.fi (gw01.mail.saunalahti.fi [195.197.172.115]) by postgresql.org (Postfix) with ESMTP id 6DB7F9FA5ED for ; Sat, 21 Jul 2007 21:02:52 -0300 (ADT) Received: from [10.0.0.4] (a88-113-10-143.elisa-laajakaista.fi [88.113.10.143]) (using SSLv3 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by gw01.mail.saunalahti.fi (Postfix) with ESMTP id 1A190151419 for ; Sun, 22 Jul 2007 03:02:50 +0300 (EEST) Subject: Fix more unit test connection leaks From: Mikko Tiihonen To: pgsql-jdbc Content-Type: text/plain Date: Sun, 22 Jul 2007 03:02:49 +0300 Message-Id: <1185062569.1632.80.camel@dual.local> Mime-Version: 1.0 X-Mailer: Evolution 2.10.2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/99 X-Sequence-Number: 17273 Hi, I found some more connection leaks from the test cases. Index: org/postgresql/test/jdbc2/MiscTest.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/MiscTest.java,v retrieving revision 1.20 diff -u -r1.20 MiscTest.java --- org/postgresql/test/jdbc2/MiscTest.java 2 Dec 2005 03:05:10 -0000 1.20 +++ org/postgresql/test/jdbc2/MiscTest.java 21 Jul 2007 21:08:18 -0000 @@ -66,6 +66,7 @@ rs.close(); stmt.cancel(); } + TestUtil.closeDB(con); } public void testError() throws Exception @@ -130,5 +131,6 @@ con.commit(); TestUtil.dropTable(con, "test_lock"); con.close(); + con2.close(); } } Index: org/postgresql/test/jdbc2/ConnectionTest.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/ConnectionTest.java,v retrieving revision 1.21 diff -u -r1.21 ConnectionTest.java --- org/postgresql/test/jdbc2/ConnectionTest.java 24 Nov 2005 02:31:43 -0000 1.21 +++ org/postgresql/test/jdbc2/ConnectionTest.java 21 Jul 2007 21:08:17 -0000 @@ -22,6 +22,8 @@ public class ConnectionTest extends TestCase { + private Connection con; + /* * Constructor */ @@ -33,7 +35,7 @@ // Set up the fixture for this testcase: the tables for this test. protected void setUp() throws Exception { - Connection con = TestUtil.openDB(); + con = TestUtil.openDB(); TestUtil.createTable(con, "test_a", "imagename name,image oid,id int4"); TestUtil.createTable(con, "test_c", "source text,cost money,imageid int4"); @@ -44,7 +46,9 @@ // Tear down the fixture for this test case. protected void tearDown() throws Exception { - Connection con = TestUtil.openDB(); + TestUtil.closeDB(con); + + con = TestUtil.openDB(); TestUtil.dropTable(con, "test_a"); TestUtil.dropTable(con, "test_c"); @@ -57,15 +61,15 @@ */ public void testCreateStatement() throws Exception { - Connection conn = TestUtil.openDB(); + con = TestUtil.openDB(); // A standard Statement - Statement stat = conn.createStatement(); + Statement stat = con.createStatement(); assertNotNull(stat); stat.close(); // Ask for Updateable ResultSets - stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); + stat = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); assertNotNull(stat); stat.close(); } @@ -75,17 +79,17 @@ */ public void testPrepareStatement() throws Exception { - Connection conn = TestUtil.openDB(); + con = TestUtil.openDB(); String sql = "select source,cost,imageid from test_c"; // A standard Statement - PreparedStatement stat = conn.prepareStatement(sql); + PreparedStatement stat = con.prepareStatement(sql); assertNotNull(stat); stat.close(); // Ask for Updateable ResultSets - stat = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); + stat = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); assertNotNull(stat); stat.close(); } @@ -103,7 +107,7 @@ public void testNativeSQL() throws Exception { // test a simple escape - Connection con = TestUtil.openDB(); + con = TestUtil.openDB(); assertEquals("DATE '2005-01-24'",con.nativeSQL("{d '2005-01-24'}")); } @@ -112,7 +116,7 @@ */ public void testTransactions() throws Exception { - Connection con = TestUtil.openDB(); + con = TestUtil.openDB(); Statement st; ResultSet rs; @@ -154,7 +158,7 @@ */ public void testIsClosed() throws Exception { - Connection con = TestUtil.openDB(); + con = TestUtil.openDB(); // Should not say closed assertTrue(!con.isClosed()); @@ -170,7 +174,7 @@ */ public void testWarnings() throws Exception { - Connection con = TestUtil.openDB(); + con = TestUtil.openDB(); String testStr = "This Is OuR TeSt message"; @@ -200,7 +204,7 @@ */ public void testTransactionIsolation() throws Exception { - Connection con = TestUtil.openDB(); + con = TestUtil.openDB(); // PostgreSQL defaults to READ COMMITTED assertEquals(Connection.TRANSACTION_READ_COMMITTED, @@ -274,7 +278,7 @@ */ public void testTypeMaps() throws Exception { - Connection con = TestUtil.openDB(); + con = TestUtil.openDB(); // preserve the current map java.util.Map oldmap = con.getTypeMap(); @@ -296,7 +300,7 @@ */ public void testDoubleClose() throws Exception { - Connection con = TestUtil.openDB(); + con = TestUtil.openDB(); con.close(); con.close(); } Index: org/postgresql/test/jdbc2/DatabaseMetaDataTest.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java,v retrieving revision 1.38 diff -u -r1.38 DatabaseMetaDataTest.java --- org/postgresql/test/jdbc2/DatabaseMetaDataTest.java 15 Jul 2007 15:33:33 -0000 1.38 +++ org/postgresql/test/jdbc2/DatabaseMetaDataTest.java 21 Jul 2007 21:08:18 -0000 @@ -167,6 +167,7 @@ TestUtil.dropTable( con1, "vv" ); TestUtil.dropTable( con1, "ww" ); + TestUtil.closeDB(con1); } public void testForeignKeyActions() throws Exception @@ -192,6 +193,7 @@ TestUtil.dropTable(conn, "fkt2"); TestUtil.dropTable(conn, "fkt1"); TestUtil.dropTable(conn, "pkt"); + TestUtil.closeDB(conn); } public void testForeignKeysToUniqueIndexes() throws Exception @@ -310,7 +312,7 @@ TestUtil.dropTable( con1, "users" ); TestUtil.dropTable( con1, "people" ); TestUtil.dropTable( con1, "policy" ); - + TestUtil.closeDB(con1); } public void testColumns() throws SQLException