commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r607117 - in /commons/proper/pool/branches/1_4_RELEASE_BRANCH/src: java/org/apache/commons/pool/impl/GenericObjectPool.java test/org/apache/commons/pool/TestObjectPool.java
Date Thu, 27 Dec 2007 20:15:32 GMT
Author: psteitz
Date: Thu Dec 27 12:15:31 2007
New Revision: 607117

URL: http://svn.apache.org/viewvc?rev=607117&view=rev
Log:
Fixed an error introduced in r385746 (post-1.3 changes to
improve exception management). When passivate throws an
exception while returning an object, after destroying the
instance, numActive needs to be decremented.  

Modified:
    commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
    commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/test/org/apache/commons/pool/TestObjectPool.java

Modified: commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/GenericObjectPool.java?rev=607117&r1=607116&r2=607117&view=diff
==============================================================================
--- commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
(original)
+++ commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
Thu Dec 27 12:15:31 2007
@@ -1082,6 +1082,13 @@
                 } catch (Exception e2) {
                     // swallowed
                 }
+                // TODO: Correctness here depends on control in addObjectToPool.
+                // These two methods should be refactored, removing the 
+                // "behavior flag",decrementNumActive, from addObjectToPool.
+                synchronized(this) {
+                    _numActive--;
+                    notifyAll();
+                }
             }
         }
     }

Modified: commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/test/org/apache/commons/pool/TestObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/test/org/apache/commons/pool/TestObjectPool.java?rev=607117&r1=607116&r2=607117&view=diff
==============================================================================
--- commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/test/org/apache/commons/pool/TestObjectPool.java
(original)
+++ commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/test/org/apache/commons/pool/TestObjectPool.java
Thu Dec 27 12:15:31 2007
@@ -273,14 +273,19 @@
 
         //// Test exception handling of returnObject
         reset(pool, factory, expectedMethods);
-
+        pool.addObject();
+        pool.addObject();
+        pool.addObject();
+        assertEquals(3, pool.getNumIdle());
         // passivateObject should swallow exceptions and not add the object to the pool
-        idleCount = pool.getNumIdle();
         obj = pool.borrowObject();
+        Object obj2 = pool.borrowObject();
+        assertEquals(1, pool.getNumIdle());
+        assertEquals(2, pool.getNumActive());
         clear(factory, expectedMethods);
         factory.setPassivateObjectFail(true);
         pool.returnObject(obj);
-       // StackObjectPool, SoftReferenceObjectPool also validate on return
+        // StackObjectPool, SoftReferenceObjectPool also validate on return
         if (pool instanceof StackObjectPool || 
                 pool instanceof SoftReferenceObjectPool) {
             expectedMethods.add(new MethodCall(
@@ -289,7 +294,8 @@
         expectedMethods.add(new MethodCall("passivateObject", obj));
         removeDestroyObjectCall(factory.getMethodCalls()); // The exact timing of destroyObject
is flexible here.
         assertEquals(expectedMethods, factory.getMethodCalls());
-        assertEquals(idleCount, pool.getNumIdle());
+        assertEquals(1, pool.getNumIdle());   // Not returned
+        assertEquals(1, pool.getNumActive()); // But not in active count
 
         // destroyObject should swallow exceptions too
         reset(pool, factory, expectedMethods);



Mime
View raw message