commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r606573 - in /commons/proper/pool/branches/1_4_RELEASE_BRANCH/src: java/org/apache/commons/pool/impl/ test/org/apache/commons/pool/ test/org/apache/commons/pool/impl/
Date Sun, 23 Dec 2007 16:38:10 GMT
Author: psteitz
Date: Sun Dec 23 08:38:09 2007
New Revision: 606573

URL: http://svn.apache.org/viewvc?rev=606573&view=rev
Log:
Completed changes from r603114 to revert post-1.3 changes in instance
validation for StackObjectPool, StackKeyedObjectPool, SoftReferenceObjecPool.

Modified:
    commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java
    commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java
    commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/StackObjectPool.java
    commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/test/org/apache/commons/pool/TestKeyedObjectPool.java
    commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/test/org/apache/commons/pool/TestObjectPool.java
    commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java

Modified: commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java?rev=606573&r1=606572&r2=606573&view=diff
==============================================================================
--- commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java
(original)
+++ commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java
Sun Dec 23 08:38:09 2007
@@ -128,10 +128,14 @@
     public synchronized void returnObject(Object obj) throws Exception {
         boolean success = !isClosed();
         if (_factory != null) {
-            try {
-                _factory.passivateObject(obj);
-            } catch(Exception e) {
+            if(!_factory.validateObject(obj)) {
                 success = false;
+            } else {
+                try {
+                    _factory.passivateObject(obj);
+                } catch(Exception e) {
+                    success = false;
+                }
             }
         }
 
@@ -175,7 +179,11 @@
         Object obj = _factory.makeObject();
 
         boolean success = true;
-        _factory.passivateObject(obj);
+        if(!_factory.validateObject(obj)) {
+            success = false;
+        } else {
+            _factory.passivateObject(obj);
+        }
 
         boolean shouldDestroy = !success;
         if(success) {
@@ -253,7 +261,7 @@
     }
 
     /**
-     * If any idle objects were garabage collected, remove their
+     * If any idle objects were garbage collected, remove their
      * {@link Reference} wrappers from the idle object pool.
      */
     private void pruneClearedReferences() {

Modified: commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java?rev=606573&r1=606572&r2=606573&view=diff
==============================================================================
--- commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java
(original)
+++ commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java
Sun Dec 23 08:38:09 2007
@@ -142,7 +142,6 @@
         Object obj = null;
         do {
             boolean newlyMade = false;
-            // TODO: Don't use exception, test size.
             if (!stack.empty()) {
                 obj = stack.pop();
                 _totIdle--;
@@ -184,7 +183,11 @@
         decrementActiveCount(key);
         if (null != _factory) {
             try {
-                _factory.passivateObject(key, obj);
+                if (_factory.validateObject(key, obj)) {
+                    _factory.passivateObject(key, obj);
+                } else {
+                    return;
+                }
             } catch (Exception e) {
                 try {
                     _factory.destroyObject(key, obj);
@@ -260,7 +263,18 @@
             throw new IllegalStateException("Cannot add objects without a factory.");
         }
         Object obj = _factory.makeObject(key);
-
+        try {
+            if (!_factory.validateObject(key, obj)) {
+               return;
+            }
+        } catch (Exception e) {
+            try {
+                _factory.destroyObject(key, obj);
+            } catch (Exception e2) {
+                // swallowed
+            }
+            return;
+        }
         _factory.passivateObject(key, obj);
 
         Stack stack = (Stack)_pools.get(key);

Modified: commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/StackObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/StackObjectPool.java?rev=606573&r1=606572&r2=606573&view=diff
==============================================================================
--- commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/StackObjectPool.java
(original)
+++ commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/java/org/apache/commons/pool/impl/StackObjectPool.java
Sun Dec 23 08:38:09 2007
@@ -182,10 +182,14 @@
     public synchronized void returnObject(Object obj) throws Exception {
         boolean success = !isClosed();
         if(null != _factory) {
-            try {
-                _factory.passivateObject(obj);
-            } catch(Exception e) {
+            if(!_factory.validateObject(obj)) {
                 success = false;
+            } else {
+                try {
+                    _factory.passivateObject(obj);
+                } catch(Exception e) {
+                    success = false;
+                }
             }
         }
 
@@ -288,7 +292,11 @@
         Object obj = _factory.makeObject();
 
         boolean success = true;
-        _factory.passivateObject(obj);
+        if(!_factory.validateObject(obj)) {
+            success = false;
+        } else {
+            _factory.passivateObject(obj);
+        }
 
         boolean shouldDestroy = !success;
 

Modified: commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/test/org/apache/commons/pool/TestKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/test/org/apache/commons/pool/TestKeyedObjectPool.java?rev=606573&r1=606572&r2=606573&view=diff
==============================================================================
--- commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/test/org/apache/commons/pool/TestKeyedObjectPool.java
(original)
+++ commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/test/org/apache/commons/pool/TestKeyedObjectPool.java
Sun Dec 23 08:38:09 2007
@@ -23,6 +23,7 @@
 import java.util.NoSuchElementException;
 
 import org.apache.commons.pool.impl.GenericKeyedObjectPool;
+import org.apache.commons.pool.impl.StackKeyedObjectPool;
 
 /**
  * Abstract {@link TestCase} for {@link ObjectPool} implementations.
@@ -106,6 +107,10 @@
         // addObject should make a new object, pasivate it and put it in the pool
         pool.addObject(KEY);
         expectedMethods.add(new MethodCall("makeObject", KEY).returned(ZERO));
+        if (pool instanceof StackKeyedObjectPool) {
+            expectedMethods.add(new MethodCall(
+                    "validateObject", KEY, ZERO).returned(Boolean.TRUE)); 
+        }
         expectedMethods.add(new MethodCall("passivateObject", KEY, ZERO));
         assertEquals(expectedMethods, factory.getMethodCalls());
 
@@ -135,6 +140,10 @@
             // expected
         }
         expectedMethods.add(new MethodCall("makeObject", KEY).returned(ONE));
+        if (pool instanceof StackKeyedObjectPool) {
+            expectedMethods.add(new MethodCall(
+                    "validateObject", KEY, ONE).returned(Boolean.TRUE)); 
+        }
         expectedMethods.add(new MethodCall("passivateObject", KEY, ONE));
         assertEquals(expectedMethods, factory.getMethodCalls());
     }
@@ -243,6 +252,10 @@
 
         // returned object should be passivated
         pool.returnObject(KEY, obj);
+        if (pool instanceof StackKeyedObjectPool) {
+            expectedMethods.add(new MethodCall(
+                    "validateObject", KEY, obj).returned(Boolean.TRUE)); 
+        }
         expectedMethods.add(new MethodCall("passivateObject", KEY, obj));
         assertEquals(expectedMethods, factory.getMethodCalls());
 
@@ -255,6 +268,10 @@
         clear(factory, expectedMethods);
         factory.setPassivateObjectFail(true);
         pool.returnObject(KEY, obj);
+        if (pool instanceof StackKeyedObjectPool) {
+            expectedMethods.add(new MethodCall(
+                    "validateObject", KEY, obj).returned(Boolean.TRUE)); 
+        }
         expectedMethods.add(new MethodCall("passivateObject", KEY, obj));
         TestObjectPool.removeDestroyObjectCall(factory.getMethodCalls()); // The exact timing
of destroyObject is flexible here.
         assertEquals(expectedMethods, factory.getMethodCalls());

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=606573&r1=606572&r2=606573&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
Sun Dec 23 08:38:09 2007
@@ -18,6 +18,8 @@
 
 import junit.framework.TestCase;
 import org.apache.commons.pool.impl.GenericObjectPool;
+import org.apache.commons.pool.impl.StackObjectPool;
+import org.apache.commons.pool.impl.SoftReferenceObjectPool;
 
 import java.util.List;
 import java.util.ArrayList;
@@ -115,6 +117,12 @@
         assertEquals(0, pool.getNumActive());
         assertEquals(1, pool.getNumIdle());
         expectedMethods.add(new MethodCall("makeObject").returned(ZERO));
+        // StackObjectPool, SoftReferenceObjectPool also validate on add
+        if (pool instanceof StackObjectPool || 
+                pool instanceof SoftReferenceObjectPool) {
+            expectedMethods.add(new MethodCall(
+                    "validateObject", ZERO).returned(Boolean.TRUE));
+        }
         expectedMethods.add(new MethodCall("passivateObject", ZERO));
         assertEquals(expectedMethods, factory.getMethodCalls());
 
@@ -144,6 +152,12 @@
             // expected
         }
         expectedMethods.add(new MethodCall("makeObject").returned(ONE));
+        // StackObjectPool, SofReferenceObjectPool also validate on add
+        if (pool instanceof StackObjectPool || 
+                pool instanceof SoftReferenceObjectPool) {
+            expectedMethods.add(new MethodCall(
+                    "validateObject", ONE).returned(Boolean.TRUE));
+        }
         expectedMethods.add(new MethodCall("passivateObject", ONE));
         assertEquals(expectedMethods, factory.getMethodCalls());
     }
@@ -248,6 +262,12 @@
 
         // returned object should be passivated
         pool.returnObject(obj);
+        // StackObjectPool, SoftReferenceObjectPool also validate on return
+        if (pool instanceof StackObjectPool || 
+                pool instanceof SoftReferenceObjectPool) {
+            expectedMethods.add(new MethodCall(
+                    "validateObject", obj).returned(Boolean.TRUE));
+        }
         expectedMethods.add(new MethodCall("passivateObject", obj));
         assertEquals(expectedMethods, factory.getMethodCalls());
 
@@ -260,6 +280,12 @@
         clear(factory, expectedMethods);
         factory.setPassivateObjectFail(true);
         pool.returnObject(obj);
+       // StackObjectPool, SoftReferenceObjectPool also validate on return
+        if (pool instanceof StackObjectPool || 
+                pool instanceof SoftReferenceObjectPool) {
+            expectedMethods.add(new MethodCall(
+                    "validateObject", obj).returned(Boolean.TRUE));
+        }
         expectedMethods.add(new MethodCall("passivateObject", obj));
         removeDestroyObjectCall(factory.getMethodCalls()); // The exact timing of destroyObject
is flexible here.
         assertEquals(expectedMethods, factory.getMethodCalls());

Modified: commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java?rev=606573&r1=606572&r2=606573&view=diff
==============================================================================
--- commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java
(original)
+++ commons/proper/pool/branches/1_4_RELEASE_BRANCH/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java
Sun Dec 23 08:38:09 2007
@@ -193,7 +193,7 @@
         // 1,3,5,...,19 pass validation, get checked out
         for(int i=0;i<10;i++) {
             pool.returnObject(obj[i]);
-            assertEquals("Each time we borrow, get one less active.", 9-i, pool.getNumActive());
+            assertEquals("Each time we return, get one less active.", 9-i, pool.getNumActive());
         }
         // 3, 9, 15 fail passivation.  
         assertEquals(7,pool.getNumIdle());
@@ -256,9 +256,10 @@
 
         for(int i=0;i<10;i++) {
             pool.returnObject(obj[i]);
-            assertEquals("Each time we borrow, get one less active.", 9-i, pool.getNumActive());
+            assertEquals("Each time we return, get one less active.", 9-i, pool.getNumActive());
         }
-        assertEquals(6,pool.getNumIdle());
+        // 0,2,4,6,8 fail validation, 3, 9 fail passivation - 3 left.
+        assertEquals(3,pool.getNumIdle());
     }
     
     public void testVariousConstructors() throws Exception {



Mime
View raw message