commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r329393 - in /jakarta/commons/proper/pool/trunk/src: java/org/apache/commons/pool/impl/ test/org/apache/commons/pool/ test/org/apache/commons/pool/impl/
Date Sat, 29 Oct 2005 10:19:36 GMT
Author: rdonkin
Date: Sat Oct 29 03:19:26 2005
New Revision: 329393

URL: http://svn.apache.org/viewcvs?rev=329393&view=rev
Log:
Made GenericObjectPool a FIFO as per documentation. Submitted by Sandy McArthur. Issue#33264.

Modified:
    jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPool.java
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftReferenceObjectPool.java
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java

Modified: jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java?rev=329393&r1=329392&r2=329393&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
Sat Oct 29 03:19:26 2005
@@ -925,7 +925,7 @@
         if((_maxIdle >= 0) && (_pool.size() >= _maxIdle)) {
             shouldDestroy = true;
         } else if(success) {
-            _pool.addFirst(new ObjectTimestampPair(obj));
+            _pool.addLast(new ObjectTimestampPair(obj));
         }
         notifyAll(); // _numActive has changed
 

Modified: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPool.java?rev=329393&r1=329392&r2=329393&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPool.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPool.java
Sat Oct 29 03:19:26 2005
@@ -41,6 +41,18 @@
      * object (zero indexed) created by the _pool.
      */
     protected abstract Object getNthObject(int n);
+    
+    /**
+     * Is the implementations LIFO?
+     * @return
+     */
+    protected abstract boolean isLifo();
+    
+    /**
+     * Is the implementationn FIFO?
+     * @return
+     */
+    protected abstract boolean isFifo();
 
     public void setUp() throws Exception {
     }
@@ -105,9 +117,20 @@
         _pool.returnObject(obj0);
         _pool.returnObject(obj2);
         obj2 = _pool.borrowObject();
-        assertEquals(getNthObject(2),obj2);
+        if (isLifo()) {
+            assertEquals(getNthObject(2),obj2);
+        }
+        if (isFifo()) {
+            assertEquals(getNthObject(0),obj2);
+        }
+            
         obj0 = _pool.borrowObject();
-        assertEquals(getNthObject(0),obj0);
+        if (isLifo()) {
+            assertEquals(getNthObject(0),obj0);
+        }
+        if (isFifo()) {
+            assertEquals(getNthObject(2),obj0);
+        }
     }
 
     public void testBaseNumActiveNumIdle() throws Exception {

Modified: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java?rev=329393&r1=329392&r2=329393&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
Sat Oct 29 03:19:26 2005
@@ -830,7 +830,20 @@
             _complete = true;
         }
     }
-    
+
+    public void testFIFO() throws Exception {
+        pool.addObject(); // "0"
+        pool.addObject(); // "1"
+        pool.addObject(); // "2"
+        assertEquals("Oldest", "0", pool.borrowObject());
+        assertEquals("Middle", "1", pool.borrowObject());
+        assertEquals("Youngest", "2", pool.borrowObject());
+        assertEquals("new-3", "3", pool.borrowObject());
+        pool.returnObject("r");
+        assertEquals("returned", "r", pool.borrowObject());
+        assertEquals("new-4", "4", pool.borrowObject());
+    }
+
     public void testAddObject() throws Exception {
         assertEquals("should be zero idle", 0, pool.getNumIdle());
     	pool.addObject();
@@ -998,6 +1011,15 @@
         public void setValidationEnabled(boolean b) {
             enableValidation = b;
         }
+    }
+
+    protected boolean isLifo() {
+ 
+        return false;
+    }
+
+    protected boolean isFifo() {
+        return true;
     }
 }
 

Modified: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftReferenceObjectPool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftReferenceObjectPool.java?rev=329393&r1=329392&r2=329393&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftReferenceObjectPool.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftReferenceObjectPool.java
Sat Oct 29 03:19:26 2005
@@ -124,4 +124,12 @@
         assertEquals("Wrong sequence", desiredSequence, testFactorySequenceStates);
     }
 
+    protected boolean isLifo() {
+        return false;
+    }
+
+    protected boolean isFifo() {
+        return false;
+    }
+
 }

Modified: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java?rev=329393&r1=329392&r2=329393&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java
Sat Oct 29 03:19:26 2005
@@ -393,5 +393,13 @@
         public void activateObject(Object obj) { }
         public void passivateObject(Object obj) { }
     }
+
+    protected boolean isLifo() {
+        return false;
+    }
+
+    protected boolean isFifo() {
+        return false;
+    }
 }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message