You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2013/11/26 03:22:10 UTC
svn commit: r1545510 -
/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
Author: psteitz
Date: Tue Nov 26 02:22:09 2013
New Revision: 1545510
URL: http://svn.apache.org/r1545510
Log:
Added tests (disabled) demonstrating POOL-240.
Modified:
commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java?rev=1545510&r1=1545509&r2=1545510&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java Tue Nov 26 02:22:09 2013
@@ -1850,6 +1850,65 @@ public class TestGenericKeyedObjectPool
throw new AssertionError(result.get());
}
}
+
+ /**
+ * Verify that threads waiting on a depleted pool get served when a checked out object is
+ * invalidated.
+ *
+ * JIRA: POOL-240
+ */
+ //@Test
+ public void testInvalidateFreesCapacity()
+ throws Exception {
+ SimpleFactory<String> factory = new SimpleFactory<String>();
+ GenericKeyedObjectPool<String, String> pool = new GenericKeyedObjectPool<String, String>(factory);
+ pool.setMaxTotalPerKey(2);
+ pool.setMaxWaitMillis(500);
+ // Borrow an instance and hold if for 5 seconds
+ WaitingTestThread thread1 = new WaitingTestThread(pool, "one", 5000);
+ thread1.start();
+ // Borrow another instance
+ String obj = pool.borrowObject("one");
+ // Launch another thread - will block, but fail in 500 ms
+ WaitingTestThread thread2 = new WaitingTestThread(pool, "one", 100);
+ thread2.start();
+ // Invalidate the object borrowed by this thread - should allow thread2 to create
+ Thread.sleep(20);
+ pool.invalidateObject("one", 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
+ */
+ //@Test
+ public void testValidationFailureOnReturnFreesCapacity()
+ throws Exception {
+ SimpleFactory<String> factory = new SimpleFactory<String>();
+ factory.setValid(false); // Validate will always fail
+ factory.setValidationEnabled(true);
+ GenericKeyedObjectPool<String, String> pool = new GenericKeyedObjectPool<String, String>(factory);
+ pool.setMaxTotalPerKey(2);
+ pool.setMaxWaitMillis(1500);
+ pool.setTestOnReturn(true);
+ pool.setTestOnBorrow(false);
+ // Borrow an instance and hold if for 5 seconds
+ WaitingTestThread thread1 = new WaitingTestThread(pool,"one", 5000);
+ thread1.start();
+ // Borrow another instance and return it after 500 ms (validation will fail)
+ WaitingTestThread thread2 = new WaitingTestThread(pool,"one", 500);
+ thread2.start();
+ Thread.sleep(50);
+ // Try to borrow an object
+ String obj = pool.borrowObject("one");
+ pool.returnObject("one", obj);
+ }
private static class DummyFactory
extends BaseKeyedPooledObjectFactory<Object,Object> {