commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sandy...@apache.org
Subject svn commit: r386471 - /jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestPoolUtils.java
Date Thu, 16 Mar 2006 22:16:16 GMT
Author: sandymac
Date: Thu Mar 16 14:16:14 2006
New Revision: 386471

URL: http://svn.apache.org/viewcvs?rev=386471&view=rev
Log:
Impoves unit test code coverage for PoolUtils. TestPoolUtils now tests 
every code path that can be tested using the public interface of PoolUtils.

Modified:
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestPoolUtils.java

Modified: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestPoolUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestPoolUtils.java?rev=386471&r1=386470&r2=386471&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestPoolUtils.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestPoolUtils.java
Thu Mar 16 14:16:14 2006
@@ -34,6 +34,9 @@
 import java.util.Iterator;
 import java.util.Arrays;
 
+import org.apache.commons.pool.impl.GenericObjectPool;
+import org.apache.commons.pool.impl.GenericKeyedObjectPool;
+
 /**
  * Unit tests for {@link PoolUtils}.
  *
@@ -273,13 +276,32 @@
             // expected
         }
 
-        // Because this isn't determinist and you can get false failures, try more than once.
+        final List calledMethods = new ArrayList();
+
+        // Test that the minIdle check doesn't add too many idle objects
+        final PoolableObjectFactory pof = (PoolableObjectFactory)createProxy(PoolableObjectFactory.class,
calledMethods);
+        final ObjectPool op = new GenericObjectPool(pof);
+        PoolUtils.checkMinIdle(op, 2, 100);
+        Thread.sleep(400);
+        assertEquals(2, op.getNumIdle());
+        op.close();
+        int makeObjectCount = 0;
+        final Iterator iter = calledMethods.iterator();
+        while (iter.hasNext()) {
+            final String methodName = (String)iter.next();
+            if ("makeObject".equals(methodName)) {
+                makeObjectCount++;
+            }
+        }
+        assertEquals("makeObject should have been called two time", 2, makeObjectCount);
+
+        // Because this isn't deterministic and you can get false failures, try more than
once.
         AssertionFailedError afe = null;
         int triesLeft = 3;
         do {
             afe = null;
             try {
-                final List calledMethods = new ArrayList();
+                calledMethods.clear();
                 final ObjectPool pool = (ObjectPool)createProxy(ObjectPool.class, calledMethods);
                 final TimerTask task = PoolUtils.checkMinIdle(pool, 1, CHECK_PERIOD); //
checks minIdle immediately
 
@@ -325,15 +347,35 @@
             // expected
         }
 
-        // Because this isn't determinist and you can get false failures, try more than once.
+        final List calledMethods = new ArrayList();
+        final Object key = new Object();
+
+        // Test that the minIdle check doesn't add too many idle objects
+        final KeyedPoolableObjectFactory kpof = (KeyedPoolableObjectFactory)createProxy(KeyedPoolableObjectFactory.class,
calledMethods);
+        final KeyedObjectPool kop = new GenericKeyedObjectPool(kpof);
+        PoolUtils.checkMinIdle(kop, key, 2, 100);
+        Thread.sleep(400);
+        assertEquals(2, kop.getNumIdle(key));
+        assertEquals(2, kop.getNumIdle());
+        kop.close();
+        int makeObjectCount = 0;
+        final Iterator iter = calledMethods.iterator();
+        while (iter.hasNext()) {
+            final String methodName = (String)iter.next();
+            if ("makeObject".equals(methodName)) {
+                makeObjectCount++;
+            }
+        }
+        assertEquals("makeObject should have been called two time", 2, makeObjectCount);
+
+        // Because this isn't deterministic and you can get false failures, try more than
once.
         AssertionFailedError afe = null;
         int triesLeft = 3;
         do {
             afe = null;
             try {
-                final List calledMethods = new ArrayList();
+                calledMethods.clear();
                 final KeyedObjectPool pool = (KeyedObjectPool)createProxy(KeyedObjectPool.class,
calledMethods);
-                final Object key = new Object();
                 final TimerTask task = PoolUtils.checkMinIdle(pool, key, 1, CHECK_PERIOD);
// checks minIdle immediately
 
                 Thread.sleep(CHECK_SLEEP_PERIOD); // will check CHECK_COUNT more times.



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message