commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1174510 - /commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
Date Fri, 23 Sep 2011 03:44:23 GMT
Author: psteitz
Date: Fri Sep 23 03:44:23 2011
New Revision: 1174510

URL: http://svn.apache.org/viewvc?rev=1174510&view=rev
Log:
Added (currently failing, disabled) test to verify per key liveness.

Modified:
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java?rev=1174510&r1=1174509&r2=1174510&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
Fri Sep 23 03:44:23 2011
@@ -1310,6 +1310,34 @@ public class TestGenericKeyedObjectPool 
         pool.returnObject("1", waiter);  // Will throw IllegalStateException if dead
     }
     
+    
+    /**
+     * Verifies that threads that get parked waiting for keys not in use
+     * when the pool is at maxTotal eventually get served.
+     */
+    //@Test
+    public void testLivenessPerKey() throws Exception {
+        SimpleFactory<String> factory = new SimpleFactory<String>();
+        GenericKeyedObjectPool<String,String> pool =
+            new GenericKeyedObjectPool<String,String>(factory);
+        pool.setMaxIdlePerKey(3);
+        pool.setMaxTotal(3);
+        pool.setMaxTotalPerKey(3);
+        pool.setMaxWait(3000);  // Really a timeout for the test
+        
+        // Check out and briefly hold 3 "1"s
+        WaitingTestThread t1 = new WaitingTestThread(pool, "1", 100);
+        WaitingTestThread t2 = new WaitingTestThread(pool, "1", 100);
+        WaitingTestThread t3 = new WaitingTestThread(pool, "1", 100);
+        t1.start();
+        t2.start();
+        t3.start();
+        
+        // Try to get a "2" while all capacity is in use.
+        // Thread will park waiting on empty queue. Verify it gets served.
+        pool.borrowObject("2");   
+    }
+    
     /*
      * Very simple test thread that just tries to borrow an object from
      * the provided pool with the specified key and returns it



Mime
View raw message