You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sa...@apache.org on 2006/03/17 08:49:26 UTC
svn commit: r386562 -
/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
Author: sandymac
Date: Thu Mar 16 23:49:24 2006
New Revision: 386562
URL: http://svn.apache.org/viewcvs?rev=386562&view=rev
Log:
Impoves unit test code coverage for GenericObjectPool.
Modified:
jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
Modified: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java?rev=386562&r1=386561&r2=386562&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java (original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java Thu Mar 16 23:49:24 2006
@@ -22,6 +22,7 @@
import org.apache.commons.pool.ObjectPool;
import org.apache.commons.pool.PoolableObjectFactory;
import org.apache.commons.pool.TestObjectPool;
+import org.apache.commons.pool.PoolUtils;
import java.util.NoSuchElementException;
@@ -119,6 +120,31 @@
pool.close();
}
+ public void testEvict() throws Exception {
+ // yea this is hairy but it tests all the code paths in GOP.evict()
+ final SimpleFactory factory = new SimpleFactory();
+ final GenericObjectPool pool = new GenericObjectPool(factory);
+ pool.setSoftMinEvictableIdleTimeMillis(10);
+ pool.setMinIdle(2);
+ pool.setTestWhileIdle(true);
+ PoolUtils.prefill(pool, 5);
+ pool.evict();
+ factory.setEvenValid(false);
+ factory.setOddValid(false);
+ factory.setThrowExceptionOnActivate(true);
+ pool.evict();
+ PoolUtils.prefill(pool, 5);
+ factory.setThrowExceptionOnActivate(false);
+ factory.setThrowExceptionOnPassivate(true);
+ pool.evict();
+ factory.setThrowExceptionOnPassivate(false);
+ factory.setEvenValid(true);
+ factory.setOddValid(true);
+ Thread.sleep(125);
+ pool.evict();
+ assertEquals(2, pool.getNumIdle());
+ }
+
public void testExceptionOnPassivateDuringReturn() throws Exception {
SimpleFactory factory = new SimpleFactory();
GenericObjectPool pool = new GenericObjectPool(factory);
@@ -304,6 +330,10 @@
assertEquals(11235L,pool.getTimeBetweenEvictionRunsMillis());
}
{
+ pool.setSoftMinEvictableIdleTimeMillis(12135L);
+ assertEquals(12135L,pool.getSoftMinEvictableIdleTimeMillis());
+ }
+ {
pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
assertEquals(GenericObjectPool.WHEN_EXHAUSTED_BLOCK,pool.getWhenExhaustedAction());
pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_FAIL);
@@ -811,6 +841,15 @@
pool.returnObject(obj);
assertEquals("should be one idle", 1, pool.getNumIdle());
assertEquals("should be zero active", 0, pool.getNumActive());
+
+ ObjectPool op = new GenericObjectPool();
+ try {
+ op.addObject();
+ fail("Expected IllegalStateException when there is no factory.");
+ } catch (IllegalStateException ise) {
+ //expected
+ }
+ op.close();
}
private GenericObjectPool pool = null;
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org