[PATCH] Stop test cases from leaking connections

From: Mikko Tiihonen <mikko(dot)tiihonen(at)iki(dot)fi>
To: pgsql-jdbc <pgsql-jdbc(at)postgresql(dot)org>
Subject: [PATCH] Stop test cases from leaking connections
Date: 2007-07-20 19:14:06
Message-ID: 1184958846.1632.33.camel@dual.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi,

The following patch fixes connection leaks in the current unit test
cases. The patch allows passing the tests with under 10 connections in
the server.

Index: org/postgresql/test/jdbc2/TimezoneTest.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/TimezoneTest.java,v
retrieving revision 1.4
diff -u -r1.4 TimezoneTest.java
--- org/postgresql/test/jdbc2/TimezoneTest.java 16 Apr 2007 18:31:38 -0000 1.4
+++ org/postgresql/test/jdbc2/TimezoneTest.java 20 Jul 2007 19:04:12 -0000
@@ -97,6 +97,7 @@
TimeZone.setDefault(saveTZ);

TestUtil.dropTable(con, "testtimezone");
+ TestUtil.closeDB(con);
}

public void testGetTimestamp() throws Exception
Index: org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java,v
retrieving revision 1.11
diff -u -r1.11 BaseDataSourceTest.java
--- org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java 11 Jan 2005 08:25:48 -0000 1.11
+++ org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java 20 Jul 2007 19:04:12 -0000
@@ -62,6 +62,7 @@
*/
protected void tearDown() throws Exception
{
+ TestUtil.closeDB(con);
con = TestUtil.openDB();
TestUtil.dropTable(con, "poolingtest");
TestUtil.closeDB(con);
Index: org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java,v
retrieving revision 1.15
diff -u -r1.15 ConnectionPoolTest.java
--- org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java 11 Jan 2005 08:25:48 -0000 1.15
+++ org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java 20 Jul 2007 19:04:12 -0000
@@ -320,7 +320,7 @@
try
{
PooledConnection pc = getPooledConnection();
- Connection con = pc.getConnection();
+ con = pc.getConnection();
assertTrue(!con.isClosed());
con.close();
assertTrue(con.isClosed());
@@ -346,7 +346,7 @@
try
{
PooledConnection pc = getPooledConnection();
- Connection con = pc.getConnection();
+ con = pc.getConnection();
Statement s = con.createStatement();
Connection conRetrieved = s.getConnection();

@@ -368,7 +368,7 @@
try
{
PooledConnection pc = getPooledConnection();
- Connection con = pc.getConnection();
+ con = pc.getConnection();
s = con.createStatement();
}
catch (SQLException e)
@@ -400,7 +400,7 @@
try
{
PooledConnection pc = getPooledConnection();
- Connection con = pc.getConnection();
+ con = pc.getConnection();
PreparedStatement s = con.prepareStatement("select 'x'");
Connection conRetrieved = s.getConnection();

@@ -422,7 +422,7 @@
try
{
PooledConnection pc = getPooledConnection();
- Connection con = pc.getConnection();
+ con = pc.getConnection();
CallableStatement s = con.prepareCall("select 'x'");
Connection conRetrieved = s.getConnection();

Index: org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java,v
retrieving revision 1.7
diff -u -r1.7 PoolingDataSourceTest.java
--- org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java 11 Jan 2005 08:25:48 -0000 1.7
+++ org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java 20 Jul 2007 19:04:13 -0000
@@ -34,11 +34,11 @@

protected void tearDown() throws Exception
{
- super.tearDown();
if (bds instanceof PoolingDataSource)
{
((PoolingDataSource) bds).close();
}
+ super.tearDown();
}

/**
Index: org/postgresql/test/jdbc3/Jdbc3CallableStatementTest.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc3/Jdbc3CallableStatementTest.java,v
retrieving revision 1.3
diff -u -r1.3 Jdbc3CallableStatementTest.java
--- org/postgresql/test/jdbc3/Jdbc3CallableStatementTest.java 15 Jul 2007 15:03:31 -0000 1.3
+++ org/postgresql/test/jdbc3/Jdbc3CallableStatementTest.java 20 Jul 2007 19:04:13 -0000
@@ -94,7 +94,7 @@
stmt.execute("drop function myiofunc(a INOUT int, b OUT int) ");
stmt.execute("drop function myif(a INOUT int, b IN int)");
stmt.close();
-
+ TestUtil.closeDB(con);
}
public void testSomeInOut() throws Throwable
{

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Mikko Tiihonen 2007-07-20 20:18:37 Test code for ResultSet numeric getXXX methods
Previous Message Kris Jurka 2007-07-19 12:34:00 Re: Using bytea with ResultSet.getBytes("..."). Problem. Help!!