db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r619695 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java
Date Fri, 08 Feb 2008 00:14:15 GMT
Author: djd
Date: Thu Feb  7 16:14:12 2008
New Revision: 619695

URL: http://svn.apache.org/viewvc?rev=619695&view=rev
Log:
Expand the DataSourceTest testing added in DERBY-2142 to include closing the PooledConnection
during a callback resulting from a close on its logical connection.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java?rev=619695&r1=619694&r2=619695&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java
Thu Feb  7 16:14:12 2008
@@ -617,26 +617,25 @@
     }
     
     /**
-     * Test that a PooledConnection can be reused during the close
-     * event raised by the closing of its logical connection.
+     * Test that a PooledConnection can be reused and closed
+     * (separately) during the close event raised by the
+     * closing of its logical connection.
      * DERBY-2142.
      * @throws SQLException 
      *
      */
     public void testPooledReuseOnClose() throws SQLException
     {
-    	// TEMP - seems to fail on network client
-    	if (!usingEmbedded())
-    		return;
-    	
     	// PooledConnection from a ConnectionPoolDataSource
     	ConnectionPoolDataSource cpds =
     		J2EEDataSource.getConnectionPoolDataSource();
     	subtestPooledReuseOnClose(cpds.getPooledConnection());
+        subtestPooledCloseOnClose(cpds.getPooledConnection());
 
     	// PooledConnection from an XDataSource
     	XADataSource xads = J2EEDataSource.getXADataSource();
     	subtestPooledReuseOnClose(xads.getXAConnection());
+        subtestPooledCloseOnClose(xads.getXAConnection());
     }
     
     /**
@@ -690,6 +689,51 @@
     	c2.createStatement().close();
     	
     	pc.close();
+    }
+    
+    /**
+     * Tests that a pooled connection can successfully be closed
+     * during the processing of its close event by its listener.
+     */
+    private void subtestPooledCloseOnClose(final PooledConnection pc) throws SQLException
+    {
+        pc.addConnectionEventListener(new ConnectionEventListener() {
+
+            /**
+             * Mimic a pool handler that closes the PooledConnection
+             * (say it no longer needs it, pool size being reduced)
+             */
+            public void connectionClosed(ConnectionEvent event) {
+                PooledConnection pce = (PooledConnection) event.getSource();
+                assertSame(pc, pce);
+                try {
+                    pce.close();
+                } catch (SQLException e) {
+                    // Need to catch the exception here because
+                    // we cannot throw an exception through
+                    // the api method.
+                    fail(e.getMessage());
+                }
+            }
+
+            public void connectionErrorOccurred(ConnectionEvent event) {
+            }
+            
+        });
+        
+        // Open and close a connection to invoke the logic above
+        // through the callback
+        pc.getConnection().close();
+                
+        // The callback closed the actual pooled connection
+        // so subsequent requests to get a logical connection
+        // should fail.
+        try {
+            pc.getConnection();
+            fail("PooledConnection should be closed");
+        } catch (SQLException sqle) {
+            assertSQLState("08003", sqle);
+        }
     }
     
     public void testAllDataSources() throws SQLException, Exception



Mime
View raw message