commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1549800 - /commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java
Date Tue, 10 Dec 2013 09:46:14 GMT
Author: markt
Date: Tue Dec 10 09:46:14 2013
New Revision: 1549800

URL: http://svn.apache.org/r1549800
Log:
Add a test case for DBCP-260
If the pool is exhausted and a thread is blocked waiting for a connection, check that that
thread is services as soon as an abandoned object is reclaimed.

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

Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java?rev=1549800&r1=1549799&r2=1549800&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java
Tue Dec 10 09:46:14 2013
@@ -226,6 +226,33 @@ public class TestAbandonedObjectPool {
         Assert.assertTrue(!obj2.isDestroyed());  // and not destroyed
     }
 
+    /**
+     * Test case for https://issues.apache.org/jira/browse/DBCP-260.
+     * Borrow and abandon all the available objects then attempt to borrow one
+     * further object which should block until the abandoned objects are
+     * removed. We don't want the test to block indefinitely when it fails so
+     * use maxWait be check we don't actually have to wait that long.
+     */
+    @Test
+    public void testWhenExhaustedBlock() throws Exception {
+        abandonedConfig.setRemoveAbandonedOnMaintenance(true);
+        pool.setAbandonedConfig(abandonedConfig);
+        pool.setTimeBetweenEvictionRunsMillis(500);
+
+        pool.setMaxTotal(1);
+
+        @SuppressWarnings("unused") // This is going to be abandoned
+        PooledTestObject o1 = pool.borrowObject();
+
+        long start = System.currentTimeMillis();
+        PooledTestObject o2 = pool.borrowObject(5000);
+        long end = System.currentTimeMillis();
+
+        pool.returnObject(o2);
+
+        Assert.assertTrue (end - start < 5000);
+    }
+
     class ConcurrentBorrower extends Thread {
         private ArrayList<PooledTestObject> _borrowed;
 



Mime
View raw message