You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2008/02/08 21:31:32 UTC

svn commit: r619991 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java

Author: djd
Date: Fri Feb  8 12:31:31 2008
New Revision: 619991

URL: http://svn.apache.org/viewvc?rev=619991&view=rev
Log:
Add commented out code that exposes the bug described by DERBY-3401. Removing a listener from a pooled connection during logical connection close processing causes other listeners to be ignored.

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=619991&r1=619990&r2=619991&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 Fri Feb  8 12:31:31 2008
@@ -629,11 +629,15 @@
     		J2EEDataSource.getConnectionPoolDataSource();
     	subtestPooledReuseOnClose(cpds.getPooledConnection());
         subtestPooledCloseOnClose(cpds.getPooledConnection());
+        // DERBY-3401 - removing a callback during a close causes problems.
+        //subtestPooledRemoveListenerOnClose(cpds.getPooledConnection());
 
     	// PooledConnection from an XDataSource
     	XADataSource xads = J2EEDataSource.getXADataSource();
     	subtestPooledReuseOnClose(xads.getXAConnection());
         subtestPooledCloseOnClose(xads.getXAConnection());
+        // DERBY-3401 - removing a callback during a close causes problems.
+        //subtestPooledRemoveListenerOnClose(xads.getXAConnection());
     }
     
     /**
@@ -733,6 +737,73 @@
             assertSQLState("08003", sqle);
         }
     }
+    
+    /**
+     * Tests that a listener of a pooled connection can successfully
+     * remove itself during the processing of its close event by its listener.
+     */
+    private void subtestPooledRemoveListenerOnClose(final PooledConnection pc) throws SQLException
+    {
+        
+        final int[] count1 = new int[1];
+        pc.addConnectionEventListener(new ConnectionEventListener() {
+
+            /**
+             * Mimic a pool handler that removes the listener during
+             * a logical close.
+             */
+            public void connectionClosed(ConnectionEvent event) {
+                PooledConnection pce = (PooledConnection) event.getSource();
+                assertSame(pc, pce);
+                count1[0]++;
+                pce.removeConnectionEventListener(this);
+            }
+
+            public void connectionErrorOccurred(ConnectionEvent event) {
+            }
+            
+        });
+        
+        // and have another listener to ensure removing one leaves
+        // the other working and intact.
+        final int[] count2 = new int[1];
+        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);
+                count2[0]++;
+            }
+
+            public void connectionErrorOccurred(ConnectionEvent event) {
+            }
+            
+        });        
+        // no callback yet
+        assertEquals(0, count1[0]);
+        assertEquals(0, count2[0]);
+        
+        // Open and close a connection to invoke the logic above
+        // through the callback
+        pc.getConnection().close();
+        
+        // one callback for each
+        assertEquals(1, count1[0]);
+        assertEquals(1, count2[0]);
+              
+        // the callback (count1) that was removed is not called on the
+        // second close but the second callback (count2) is called.
+        pc.getConnection().close();
+        assertEquals(1, count1[0]);
+        assertEquals(2, count2[0]);
+        
+        pc.close();
+    }
+
     
     public void testAllDataSources() throws SQLException, Exception
     {