commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1544942 - /commons/proper/pool/branches/1_5_RELEASE/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
Date Sun, 24 Nov 2013 08:41:55 GMT
Author: psteitz
Date: Sun Nov 24 08:41:55 2013
New Revision: 1544942

URL: http://svn.apache.org/r1544942
Log:
Fixed broken test; added tests for POOL-240 (tests pass here).

Modified:
    commons/proper/pool/branches/1_5_RELEASE/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java

Modified: commons/proper/pool/branches/1_5_RELEASE/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/1_5_RELEASE/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java?rev=1544942&r1=1544941&r2=1544942&view=diff
==============================================================================
--- commons/proper/pool/branches/1_5_RELEASE/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
(original)
+++ commons/proper/pool/branches/1_5_RELEASE/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
Sun Nov 24 08:41:55 2013
@@ -1782,4 +1782,59 @@ public class TestGenericObjectPool exten
         pool.returnObject(instance);
         assertEquals(factory.getMakeCounter(), pool.getNumIdle());
     }
+    
+    /**
+     * Verify that threads waiting on a depleted pool get served when a checked out
+     * object is invalidated.
+     * 
+     * JIRA: POOL-240
+     */
+    public void testInvalidateFreesCapacity() throws Exception {
+        SimpleFactory factory = new SimpleFactory();
+        GenericObjectPool pool = new GenericObjectPool(factory); 
+        pool.setMaxActive(2);
+        pool.setMaxWait(500); 
+        // Borrow an instance and hold if for 5 seconds
+        WaitingTestThread thread1 = new WaitingTestThread(pool, 5000);
+        thread1.start();
+        // Borrow another instance
+        Object obj = pool.borrowObject();
+        // Launch another thread - will block, but fail in 500 ms
+        WaitingTestThread thread2 = new WaitingTestThread(pool, 100);
+        thread2.start();
+        // Invalidate the object borrowed by this thread - should allow thread2 to create
+        Thread.sleep(20);
+        pool.invalidateObject(obj);
+        Thread.sleep(600); // Wait for thread2 to timeout
+        if (thread2._thrown != null) {
+            fail(thread2._thrown.toString());
+        } 
+    }
+    
+    /**
+     * Verify that threads waiting on a depleted pool get served when a returning
+     * object fails validation.
+     * 
+     * JIRA: POOL-240
+     */
+    public void testValidationFailureOnReturnFreesCapacity() throws Exception {
+        SimpleFactory factory = new SimpleFactory();
+        factory.setValidationEnabled(true);
+        factory.setValid(false);  // Validate will always fail
+        GenericObjectPool pool = new GenericObjectPool(factory); 
+        pool.setMaxActive(2);
+        pool.setMaxWait(1500); 
+        pool.setTestOnReturn(true);
+        pool.setTestOnBorrow(false);
+        // Borrow an instance and hold if for 5 seconds
+        WaitingTestThread thread1 = new WaitingTestThread(pool, 5000);
+        thread1.start();
+        // Borrow another instance and return it after 500 ms (validation will fail)
+        WaitingTestThread thread2 = new WaitingTestThread(pool, 500);
+        thread2.start();
+        Thread.sleep(50);
+        // Try to borrow an object
+        Object obj = pool.borrowObject();
+        pool.returnObject(obj);
+    }
 }



Mime
View raw message