commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1550655 - in /commons/proper/pool/trunk: doc/ src/changes/changes.xml src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
Date Fri, 13 Dec 2013 06:32:42 GMT
Author: psteitz
Date: Fri Dec 13 06:32:42 2013
New Revision: 1550655

URL: http://svn.apache.org/r1550655
Log:
Added missing create counter decrement in GenericKeyedObjectPool create method on factory
exception path. Prior to this fix, exceptions thrown by factory makeObject calls could leak
per key capacity.

JIRA: POOL-243
Thanks to: Michal Sabo


Added:
    commons/proper/pool/trunk/doc/
Modified:
    commons/proper/pool/trunk/src/changes/changes.xml
    commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.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=1550655&r1=1550654&r2=1550655&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/changes/changes.xml (original)
+++ commons/proper/pool/trunk/src/changes/changes.xml Fri Dec 13 06:32:42 2013
@@ -46,6 +46,11 @@ The <action> type attribute can be add,u
   <release version="2.1" date="TBD" description=
       "This is a maintenance release that includes a small number of new
        features as well as including bugfixes and test case improvements.">
+    <action issue="POOL-243" dev="psteitz" type="fix" duu-to="Michal Sabo">
+      Added missing create counter decrement in GenericKeyedObjectPool create method on factory
+      exception path. Prior to this fix, exceptions thrown by factory makeObject calls could
leak
+      per key capacity.
+    </action>
     <action issue="POOL-240" dev="psteitz" type="fix" due-to="Dan McNulty">
       Ensured that blocked threads waiting on a depleted pool get served when
       objects are destroyed due to validation or passivation failures in

Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java?rev=1550655&r1=1550654&r2=1550655&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
Fri Dec 13 06:32:42 2013
@@ -1007,6 +1007,7 @@ public class GenericKeyedObjectPool<K,T>
             p = factory.makeObject(key);
         } catch (Exception e) {
             numTotal.decrementAndGet();
+            objectDeque.getCreateCount().decrementAndGet();
             throw e;
         }
 

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=1550655&r1=1550654&r2=1550655&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
Fri Dec 13 06:32:42 2013
@@ -1635,7 +1635,10 @@ public class TestGenericKeyedObjectPool 
             this.valid = valid;
         }
         @Override
-        public PooledObject<String> makeObject(K key) {
+        public PooledObject<String> makeObject(K key) throws Exception {
+            if (exceptionOnCreate) {
+                throw new Exception();
+            }
             String out = null;
             synchronized(this) {
                 activeCount++;
@@ -1722,6 +1725,7 @@ public class TestGenericKeyedObjectPool 
         boolean exceptionOnPassivate = false;
         boolean exceptionOnActivate = false;
         boolean exceptionOnDestroy = false;
+        boolean exceptionOnCreate = false;
 
         private void doWait(long latency) {
             try {
@@ -1912,6 +1916,28 @@ 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
+    public void testMakeObjectException()
+        throws Exception {
+        SimpleFactory<String> factory = new SimpleFactory<String>();
+        GenericKeyedObjectPool<String, String> pool = new GenericKeyedObjectPool<String,
String>(factory);
+        pool.setMaxTotalPerKey(1);
+        pool.setBlockWhenExhausted(false);
+        factory.exceptionOnCreate = true;
+        try {
+            pool.borrowObject("One");
+        } catch (Exception ex) {
+            // expected
+        }
+        factory.exceptionOnCreate = false;
+        pool.borrowObject("One");
+    }
 
     private static class DummyFactory
             extends BaseKeyedPooledObjectFactory<Object,Object> {



Mime
View raw message