commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r329395 - 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:43:12 GMT
Author: rdonkin
Date: Sat Oct 29 03:43:01 2005
New Revision: 329395

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

Modified:
    jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPool.java
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.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/GenericKeyedObjectPool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java?rev=329395&r1=329394&r2=329395&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
Sat Oct 29 03:43:01 2005
@@ -981,7 +981,7 @@
         if(_maxIdle >= 0 && (pool.size() >= _maxIdle)) {
             shouldDestroy = true;
         } else if(success) {
-            pool.addFirst(new ObjectTimestampPair(obj));
+            pool.addLast(new ObjectTimestampPair(obj));
             _totalIdle++;
         }
         notifyAll();

Modified: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPool.java?rev=329395&r1=329394&r2=329395&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPool.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPool.java
Sat Oct 29 03:43:01 2005
@@ -44,6 +44,18 @@
     protected abstract Object getNthObject(Object key, int n);
 
     protected abstract Object makeKey(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 {
     }
@@ -90,9 +102,19 @@
         _pool.returnObject(keya,obj0);
         _pool.returnObject(keya,obj2);
         obj2 = _pool.borrowObject(keya);
-        assertEquals(getNthObject(keya,2),obj2);
+        if (isLifo()) {
+            assertEquals(getNthObject(keya,2),obj2);
+        }
+        if (isFifo()) {
+            assertEquals(getNthObject(keya,0),obj2);
+        }
         obj0 = _pool.borrowObject(keya);
-        assertEquals(getNthObject(keya,0),obj0);
+        if (isLifo()) {
+            assertEquals(getNthObject(keya,0),obj0);
+        }
+        if (isFifo()) {
+            assertEquals(getNthObject(keya,2),obj0);
+        }
     }
 
     public void testBaseNumActiveNumIdle() throws Exception {

Modified: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java?rev=329395&r1=329394&r2=329395&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java
Sat Oct 29 03:43:01 2005
@@ -591,6 +591,20 @@
         assertTrue("Should be 5 idle, found " + pool.getNumIdle(),pool.getNumIdle() == 5);
     }
     
+    public void testFIFO() throws Exception {
+        final Object key = "key";
+        pool.addObject(key); // "key0"
+        pool.addObject(key); // "key1"
+        pool.addObject(key); // "key2"
+        assertEquals("Oldest", "key0", pool.borrowObject(key));
+        assertEquals("Middle", "key1", pool.borrowObject(key));
+        assertEquals("Youngest", "key2", pool.borrowObject(key));
+        assertEquals("new-3", "key3", pool.borrowObject(key));
+        pool.returnObject(key, "r");
+        assertEquals("returned", "r", pool.borrowObject(key));
+        assertEquals("new-4", "key4", pool.borrowObject(key));
+    }
+
     class TestThread implements Runnable {
         java.util.Random _random = new java.util.Random();
         KeyedObjectPool _pool = null;
@@ -670,6 +684,14 @@
         public void passivateObject(Object key, Object obj) { }
         int counter = 0;
         boolean valid;
+    }
+
+    protected boolean isLifo() {
+        return false;
+    }
+
+    protected boolean isFifo() {
+        return true;
     }
 
 }

Modified: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java?rev=329395&r1=329394&r2=329395&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java
Sat Oct 29 03:43:01 2005
@@ -280,4 +280,12 @@
         public void activateObject(Object key, Object obj) { }
         public void passivateObject(Object key, Object obj) { }
     }
+
+    protected boolean isLifo() {
+        return true;
+    }
+
+    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=329395&r1=329394&r2=329395&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:43:01 2005
@@ -395,7 +395,7 @@
     }
 
     protected boolean isLifo() {
-        return false;
+        return true;
     }
 
     protected boolean isFifo() {



---------------------------------------------------------------------
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