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 2007/12/20 02:32:21 UTC
svn commit: r605782 - in /commons/proper/pool/trunk:
src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java
xdocs/changes.xml
Author: psteitz
Date: Wed Dec 19 17:32:20 2007
New Revision: 605782
URL: http://svn.apache.org/viewvc?rev=605782&view=rev
Log:
Ported changes from 1.4 release branch to fix an error in the
GenericKeyedObjectPool constructor that takes
a Config instance as a parameter. The minIdle setting in the Config
was being ignored by the constructor. Also added tests for all
GKOP constructors.
JIRA: POOL-116
Modified:
commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java
commons/proper/pool/trunk/xdocs/changes.xml
Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java?rev=605782&r1=605781&r2=605782&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java Wed Dec 19 17:32:20 2007
@@ -312,7 +312,7 @@
* @param config a non-<code>null</code> {@link GenericKeyedObjectPool.Config} describing the configuration
*/
public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, GenericKeyedObjectPool.Config config) {
- this(factory,config.maxActive,config.whenExhaustedAction,config.maxWait,config.maxIdle,config.maxTotal,config.testOnBorrow,config.testOnReturn,config.timeBetweenEvictionRunsMillis,config.numTestsPerEvictionRun,config.minEvictableIdleTimeMillis,config.testWhileIdle);
+ this(factory,config.maxActive,config.whenExhaustedAction,config.maxWait,config.maxIdle,config.maxTotal, config.minIdle,config.testOnBorrow,config.testOnReturn,config.timeBetweenEvictionRunsMillis,config.numTestsPerEvictionRun,config.minEvictableIdleTimeMillis,config.testWhileIdle,config.lifo);
}
/**
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java?rev=605782&r1=605781&r2=605782&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java Wed Dec 19 17:32:20 2007
@@ -882,6 +882,269 @@
}
}
+ public void testConstructors() {
+
+ // Make constructor arguments all different from defaults
+ int maxActive = 1;
+ int maxIdle = 2;
+ long maxWait = 3;
+ int minIdle = 4;
+ int maxTotal = 5;
+ long minEvictableIdleTimeMillis = 6;
+ int numTestsPerEvictionRun = 7;
+ boolean testOnBorrow = true;
+ boolean testOnReturn = true;
+ boolean testWhileIdle = true;
+ long timeBetweenEvictionRunsMillis = 8;
+ byte whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
+ boolean lifo = false;
+
+ GenericKeyedObjectPool pool = new GenericKeyedObjectPool();
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_ACTIVE, pool.getMaxActive());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_WAIT, pool.getMaxWait());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+ pool.getMinEvictableIdleTimeMillis());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+ pool.getNumTestsPerEvictionRun());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,
+ pool.getTestOnBorrow());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,
+ pool.getTestOnReturn());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE,
+ pool.getTestWhileIdle());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+ pool.getTimeBetweenEvictionRunsMillis());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,
+ pool.getWhenExhaustedAction());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
+
+ GenericKeyedObjectPool.Config config = new GenericKeyedObjectPool.Config();
+ config.lifo = lifo;
+ config.maxActive = maxActive;
+ config.maxIdle = maxIdle;
+ config.minIdle = minIdle;
+ config.maxTotal = maxTotal;
+ config.maxWait = maxWait;
+ config.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
+ config.numTestsPerEvictionRun = numTestsPerEvictionRun;
+ config.testOnBorrow = testOnBorrow;
+ config.testOnReturn = testOnReturn;
+ config.testWhileIdle = testWhileIdle;
+ config.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
+ config.whenExhaustedAction = whenExhaustedAction;
+ pool = new GenericKeyedObjectPool(null, config);
+ assertEquals(maxActive, pool.getMaxActive());
+ assertEquals(maxIdle, pool.getMaxIdle());
+ assertEquals(maxWait, pool.getMaxWait());
+ assertEquals(minIdle, pool.getMinIdle());
+ assertEquals(maxTotal, pool.getMaxTotal());
+ assertEquals(minEvictableIdleTimeMillis,
+ pool.getMinEvictableIdleTimeMillis());
+ assertEquals(numTestsPerEvictionRun, pool.getNumTestsPerEvictionRun());
+ assertEquals(testOnBorrow,pool.getTestOnBorrow());
+ assertEquals(testOnReturn,pool.getTestOnReturn());
+ assertEquals(testWhileIdle,pool.getTestWhileIdle());
+ assertEquals(timeBetweenEvictionRunsMillis,
+ pool.getTimeBetweenEvictionRunsMillis());
+ assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
+ assertEquals(lifo, pool.getLifo());
+
+ pool = new GenericKeyedObjectPool(null, maxActive);
+ assertEquals(maxActive, pool.getMaxActive());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_WAIT, pool.getMaxWait());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+ pool.getMinEvictableIdleTimeMillis());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+ pool.getNumTestsPerEvictionRun());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,
+ pool.getTestOnBorrow());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,
+ pool.getTestOnReturn());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE,
+ pool.getTestWhileIdle());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+ pool.getTimeBetweenEvictionRunsMillis());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,
+ pool.getWhenExhaustedAction());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
+
+ pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction, maxWait);
+ assertEquals(maxActive, pool.getMaxActive());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
+ assertEquals(maxWait, pool.getMaxWait());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+ pool.getMinEvictableIdleTimeMillis());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+ pool.getNumTestsPerEvictionRun());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,
+ pool.getTestOnBorrow());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,
+ pool.getTestOnReturn());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE,
+ pool.getTestWhileIdle());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+ pool.getTimeBetweenEvictionRunsMillis());
+ assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
+
+ pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction,
+ maxWait, testOnBorrow, testOnReturn);
+ assertEquals(maxActive, pool.getMaxActive());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
+ assertEquals(maxWait, pool.getMaxWait());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+ pool.getMinEvictableIdleTimeMillis());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+ pool.getNumTestsPerEvictionRun());
+ assertEquals(testOnBorrow,pool.getTestOnBorrow());
+ assertEquals(testOnReturn,pool.getTestOnReturn());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE,
+ pool.getTestWhileIdle());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+ pool.getTimeBetweenEvictionRunsMillis());
+ assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
+
+ pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction,
+ maxWait, maxIdle);
+ assertEquals(maxActive, pool.getMaxActive());
+ assertEquals(maxIdle, pool.getMaxIdle());
+ assertEquals(maxWait, pool.getMaxWait());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+ pool.getMinEvictableIdleTimeMillis());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+ pool.getNumTestsPerEvictionRun());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,
+ pool.getTestOnBorrow());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,
+ pool.getTestOnReturn());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE,
+ pool.getTestWhileIdle());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+ pool.getTimeBetweenEvictionRunsMillis());
+ assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
+
+ pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction,
+ maxWait, maxIdle, testOnBorrow, testOnReturn);
+ assertEquals(maxActive, pool.getMaxActive());
+ assertEquals(maxIdle, pool.getMaxIdle());
+ assertEquals(maxWait, pool.getMaxWait());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+ pool.getMinEvictableIdleTimeMillis());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+ pool.getNumTestsPerEvictionRun());
+ assertEquals(testOnBorrow, pool.getTestOnBorrow());
+ assertEquals(testOnReturn, pool.getTestOnReturn());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE,
+ pool.getTestWhileIdle());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+ pool.getTimeBetweenEvictionRunsMillis());
+ assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
+
+ pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction,
+ maxWait, maxIdle, testOnBorrow, testOnReturn,
+ timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
+ minEvictableIdleTimeMillis, testWhileIdle);
+ assertEquals(maxActive, pool.getMaxActive());
+ assertEquals(maxIdle, pool.getMaxIdle());
+ assertEquals(maxWait, pool.getMaxWait());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+ assertEquals(minEvictableIdleTimeMillis,
+ pool.getMinEvictableIdleTimeMillis());
+ assertEquals(numTestsPerEvictionRun,
+ pool.getNumTestsPerEvictionRun());
+ assertEquals(testOnBorrow, pool.getTestOnBorrow());
+ assertEquals(testOnReturn, pool.getTestOnReturn());
+ assertEquals(testWhileIdle,
+ pool.getTestWhileIdle());
+ assertEquals(timeBetweenEvictionRunsMillis,
+ pool.getTimeBetweenEvictionRunsMillis());
+ assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
+
+ pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction,
+ maxWait, maxIdle, maxTotal, testOnBorrow, testOnReturn,
+ timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
+ minEvictableIdleTimeMillis, testWhileIdle);
+ assertEquals(maxActive, pool.getMaxActive());
+ assertEquals(maxIdle, pool.getMaxIdle());
+ assertEquals(maxWait, pool.getMaxWait());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
+ assertEquals(maxTotal, pool.getMaxTotal());
+ assertEquals(minEvictableIdleTimeMillis,
+ pool.getMinEvictableIdleTimeMillis());
+ assertEquals(numTestsPerEvictionRun,
+ pool.getNumTestsPerEvictionRun());
+ assertEquals(testOnBorrow, pool.getTestOnBorrow());
+ assertEquals(testOnReturn, pool.getTestOnReturn());
+ assertEquals(testWhileIdle,
+ pool.getTestWhileIdle());
+ assertEquals(timeBetweenEvictionRunsMillis,
+ pool.getTimeBetweenEvictionRunsMillis());
+ assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
+
+ pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction,
+ maxWait, maxIdle, maxTotal, minIdle, testOnBorrow, testOnReturn,
+ timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
+ minEvictableIdleTimeMillis, testWhileIdle);
+ assertEquals(maxActive, pool.getMaxActive());
+ assertEquals(maxIdle, pool.getMaxIdle());
+ assertEquals(maxWait, pool.getMaxWait());
+ assertEquals(minIdle, pool.getMinIdle());
+ assertEquals(maxTotal, pool.getMaxTotal());
+ assertEquals(minEvictableIdleTimeMillis,
+ pool.getMinEvictableIdleTimeMillis());
+ assertEquals(numTestsPerEvictionRun,
+ pool.getNumTestsPerEvictionRun());
+ assertEquals(testOnBorrow, pool.getTestOnBorrow());
+ assertEquals(testOnReturn, pool.getTestOnReturn());
+ assertEquals(testWhileIdle,
+ pool.getTestWhileIdle());
+ assertEquals(timeBetweenEvictionRunsMillis,
+ pool.getTimeBetweenEvictionRunsMillis());
+ assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
+ assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
+
+ pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction,
+ maxWait, maxIdle, maxTotal, minIdle, testOnBorrow, testOnReturn,
+ timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
+ minEvictableIdleTimeMillis, testWhileIdle, lifo);
+ assertEquals(maxActive, pool.getMaxActive());
+ assertEquals(maxIdle, pool.getMaxIdle());
+ assertEquals(maxWait, pool.getMaxWait());
+ assertEquals(minIdle, pool.getMinIdle());
+ assertEquals(maxTotal, pool.getMaxTotal());
+ assertEquals(minEvictableIdleTimeMillis,
+ pool.getMinEvictableIdleTimeMillis());
+ assertEquals(numTestsPerEvictionRun,
+ pool.getNumTestsPerEvictionRun());
+ assertEquals(testOnBorrow, pool.getTestOnBorrow());
+ assertEquals(testOnReturn, pool.getTestOnReturn());
+ assertEquals(testWhileIdle,
+ pool.getTestWhileIdle());
+ assertEquals(timeBetweenEvictionRunsMillis,
+ pool.getTimeBetweenEvictionRunsMillis());
+ assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
+ assertEquals(lifo, pool.getLifo());
+ }
class TestThread implements Runnable {
java.util.Random _random = new java.util.Random();
Modified: commons/proper/pool/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/xdocs/changes.xml?rev=605782&r1=605781&r2=605782&view=diff
==============================================================================
--- commons/proper/pool/trunk/xdocs/changes.xml (original)
+++ commons/proper/pool/trunk/xdocs/changes.xml Wed Dec 19 17:32:20 2007
@@ -109,6 +109,11 @@
GenericKeyedObjectPool. Made getNumIdle synchronized in
StackKeyedObjectPool.
</action>
+ <action dev="psteitz" type="fix" issue="POOL-116">
+ Fixed an error in the GenericKeyedObjectPool constructor that takes
+ a Config instance as a parameter. The minIdle setting in the Config
+ was being ignored by the constructor.
+ </action>
</release>
<release version="1.3" date="2006-pending" description="1.x bugfix release">