commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1221821 - in /commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl: TestGenericKeyedObjectPool.java TestGenericObjectPool.java
Date Wed, 21 Dec 2011 17:40:00 GMT
Author: psteitz
Date: Wed Dec 21 17:39:59 2011
New Revision: 1221821

URL: http://svn.apache.org/viewvc?rev=1221821&view=rev
Log:
Porting test cases for POOL-189.

Modified:
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPool.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=1221821&r1=1221820&r2=1221821&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
Wed Dec 21 17:39:59 2011
@@ -1367,6 +1367,37 @@ public class TestGenericKeyedObjectPool 
         pool.close();
     }
     
+    /**
+     * POOL-189
+     */
+    public void testWhenExhaustedBlockClosePool() throws Exception {
+        SimpleFactory<String> factory = new SimpleFactory<String>();
+        GenericKeyedObjectPool<String,String> pool =
+            new GenericKeyedObjectPool<String,String>(factory);
+        pool.setMaxTotalPerKey(1);
+        pool.setBlockWhenExhausted(true);
+        pool.setMaxWait(0);
+        String obj1 = pool.borrowObject("a");
+        
+        // Make sure an object was obtained
+        assertNotNull(obj1);
+        
+        // Create a separate thread to try and borrow another object
+        WaitingTestThread wtt = new WaitingTestThread(pool, "a", 200);
+        wtt.start();
+        // Give wtt time to start
+        Thread.sleep(200);
+        
+        // close the pool (Bug POOL-189)
+        pool.close();
+        
+        // Give interrupt time to take effect
+        Thread.sleep(200);
+        
+        // Check thread was interrupted
+        assertTrue(wtt._thrown instanceof IllegalStateException);
+    }
+    
     /*
      * Very simple test thread that just tries to borrow an object from
      * the provided pool with the specified key and returns it

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPool.java?rev=1221821&r1=1221820&r2=1221821&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPool.java
Wed Dec 21 17:39:59 2011
@@ -1127,6 +1127,34 @@ public class TestGenericObjectPool exten
             */
         }
     }
+    
+    /**
+     * POOL-189
+     */
+    public void testWhenExhaustedBlockClosePool() throws Exception {
+        pool.setMaxTotal(1);
+        pool.setBlockWhenExhausted(true);
+        pool.setMaxWait(0);
+        Object obj1 = pool.borrowObject();
+        
+        // Make sure an object was obtained
+        assertNotNull(obj1);
+        
+        // Create a separate thread to try and borrow another object
+        WaitingTestThread wtt = new WaitingTestThread(pool, 200);
+        wtt.start();
+        // Give wtt time to start
+        Thread.sleep(200);
+        
+        // close the pool (Bug POOL-189)
+        pool.close();
+        
+        // Give interrupt time to take effect
+        Thread.sleep(200);
+        
+        // Check thread was interrupted
+        assertTrue(wtt._thrown instanceof IllegalStateException);
+    }
 
     private class ConcurrentBorrowAndEvictThread extends Thread {
         private boolean borrow;



Mime
View raw message