commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1562387 - in /commons/proper/pool/trunk/src: changes/ main/java/org/apache/commons/pool2/impl/ test/java/org/apache/commons/pool2/impl/
Date Wed, 29 Jan 2014 10:04:14 GMT
Author: markt
Date: Wed Jan 29 10:04:13 2014
New Revision: 1562387

URL: http://svn.apache.org/r1562387
Log:
Fix POOL-248
Ensure that if an attempt is made to return an object multiple times that the current active
and idle object counts are not corrupted.

Modified:
    commons/proper/pool/trunk/src/changes/changes.xml
    commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java

Modified: commons/proper/pool/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/changes/changes.xml?rev=1562387&r1=1562386&r2=1562387&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/changes/changes.xml (original)
+++ commons/proper/pool/trunk/src/changes/changes.xml Wed Jan 29 10:04:13 2014
@@ -45,6 +45,10 @@ The <action> type attribute can be add,u
   <body>
   <release version="2.2" date="TBD" description=
 "TBD">
+    <action issue="POOL-258" dev="markt" type="fix" due-to="Warren Chen">
+      Ensure that if an attempt is made to return an object multiple times that
+      the current active and idle object counts are not corrupted.
+    </action>
   </release>
    <release version="2.1" date="2013-12-30" description=
 "This is a maintenance release that includes a small number of new features as well as 

Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java?rev=1562387&r1=1562386&r2=1562387&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
Wed Jan 29 10:04:13 2014
@@ -541,8 +541,7 @@ public class GenericObjectPool<T> extend
                 // Make sure object is not being reclaimed
                 synchronized(p) {
                     final PooledObjectState state = p.getState();
-                    if (state == PooledObjectState.ABANDONED ||
-                            state == PooledObjectState.INVALID) {
+                    if (state != PooledObjectState.ALLOCATED) {
                         return;
                     } else {
                         p.markReturning(); // Keep from being marked abandoned

Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java?rev=1562387&r1=1562386&r2=1562387&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
Wed Jan 29 10:04:13 2014
@@ -1916,10 +1916,10 @@ public class TestGenericKeyedObjectPool 
         String obj = pool.borrowObject("one");
         pool.returnObject("one", obj);
     }
-    
+
     /**
      * Verify that factory exceptions creating objects do not corrupt per key create count.
-     * 
+     *
      * JIRA: POOL-243
      */
     @Test

Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java?rev=1562387&r1=1562386&r2=1562387&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
Wed Jan 29 10:04:13 2014
@@ -2107,6 +2107,32 @@ public class TestGenericObjectPool exten
         assertEquals(2, swallowedExceptions.size());
     }
 
+    // POOL-248
+    @Test
+    public void testMultipleReturnOfSameObject() throws Exception {
+        final GenericObjectPool<String> pool = new GenericObjectPool<String>(
+                factory, new GenericObjectPoolConfig(),
+                new AbandonedConfig());
+
+        Assert.assertEquals(0, pool.getNumActive());
+        Assert.assertEquals(0, pool.getNumIdle());
+
+        String obj = pool.borrowObject();
+
+        Assert.assertEquals(1, pool.getNumActive());
+        Assert.assertEquals(0, pool.getNumIdle());
+
+        pool.returnObject(obj);
+
+        Assert.assertEquals(0, pool.getNumActive());
+        Assert.assertEquals(1, pool.getNumIdle());
+
+        pool.returnObject(obj);
+
+        Assert.assertEquals(0, pool.getNumActive());
+        Assert.assertEquals(1, pool.getNumIdle());
+    }
+
     private static final class DummyFactory
             extends BasePooledObjectFactory<Object> {
         @Override



Mime
View raw message