You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2010/10/12 22:04:22 UTC
svn commit: r1021905 -
/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java
Author: sebb
Date: Tue Oct 12 20:04:22 2010
New Revision: 1021905
URL: http://svn.apache.org/viewvc?rev=1021905&view=rev
Log:
Provide a basic factory
Modified:
commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java
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=1021905&r1=1021904&r2=1021905&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 Tue Oct 12 20:04:22 2010
@@ -23,6 +23,7 @@ import java.util.HashMap;
import java.util.NoSuchElementException;
import java.util.Random;
+import org.apache.commons.pool.BaseKeyedPoolableObjectFactory;
import org.apache.commons.pool.KeyedObjectPool;
import org.apache.commons.pool.KeyedPoolableObjectFactory;
import org.apache.commons.pool.TestBaseKeyedObjectPool;
@@ -967,6 +968,14 @@ public class TestGenericKeyedObjectPool
}
}
+ public void testConstructorsNoFactory() {
+ try {
+ new GenericKeyedObjectPool<Object,Object>(null);
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+
public void testConstructors() {
// Make constructor arguments all different from defaults
@@ -984,7 +993,13 @@ public class TestGenericKeyedObjectPool
WhenExhaustedAction whenExhaustedAction = WhenExhaustedAction.GROW;
boolean lifo = false;
- GenericKeyedObjectPool<Object,Object> pool = new GenericKeyedObjectPool<Object,Object>();
+ KeyedPoolableObjectFactory<Object,Object> factory = new BaseKeyedPoolableObjectFactory<Object,Object>() {
+ @Override
+ public Object makeObject(Object key) throws Exception {
+ return null;
+ }
+ };
+ GenericKeyedObjectPool<Object,Object> pool = new GenericKeyedObjectPool<Object,Object>(factory);
assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_ACTIVE, pool.getMaxActive());
assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_WAIT, pool.getMaxWait());
@@ -1020,7 +1035,7 @@ public class TestGenericKeyedObjectPool
config.testWhileIdle = testWhileIdle;
config.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
config.whenExhaustedAction = whenExhaustedAction;
- pool = new GenericKeyedObjectPool<Object,Object>(null, config);
+ pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
assertEquals(maxActive, pool.getMaxActive());
assertEquals(maxIdle, pool.getMaxIdle());
assertEquals(maxWait, pool.getMaxWait());
@@ -1037,7 +1052,7 @@ public class TestGenericKeyedObjectPool
assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
assertEquals(lifo, pool.getLifo());
- pool = new GenericKeyedObjectPool<Object,Object>(null, maxActive);
+ pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive);
assertEquals(maxActive, pool.getMaxActive());
assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_WAIT, pool.getMaxWait());
@@ -1059,7 +1074,7 @@ public class TestGenericKeyedObjectPool
pool.getWhenExhaustedAction());
assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
- pool = new GenericKeyedObjectPool<Object,Object>(null, maxActive, whenExhaustedAction, maxWait);
+ pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive, whenExhaustedAction, maxWait);
assertEquals(maxActive, pool.getMaxActive());
assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
assertEquals(maxWait, pool.getMaxWait());
@@ -1080,7 +1095,7 @@ public class TestGenericKeyedObjectPool
assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
- pool = new GenericKeyedObjectPool<Object,Object>(null, maxActive, whenExhaustedAction,
+ pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive, whenExhaustedAction,
maxWait, testOnBorrow, testOnReturn);
assertEquals(maxActive, pool.getMaxActive());
assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
@@ -1100,7 +1115,7 @@ public class TestGenericKeyedObjectPool
assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
- pool = new GenericKeyedObjectPool<Object,Object>(null, maxActive, whenExhaustedAction,
+ pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive, whenExhaustedAction,
maxWait, maxIdle);
assertEquals(maxActive, pool.getMaxActive());
assertEquals(maxIdle, pool.getMaxIdle());
@@ -1122,7 +1137,7 @@ public class TestGenericKeyedObjectPool
assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
- pool = new GenericKeyedObjectPool<Object,Object>(null, maxActive, whenExhaustedAction,
+ pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive, whenExhaustedAction,
maxWait, maxIdle, testOnBorrow, testOnReturn);
assertEquals(maxActive, pool.getMaxActive());
assertEquals(maxIdle, pool.getMaxIdle());
@@ -1142,7 +1157,7 @@ public class TestGenericKeyedObjectPool
assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
- pool = new GenericKeyedObjectPool<Object,Object>(null, maxActive, whenExhaustedAction,
+ pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive, whenExhaustedAction,
maxWait, maxIdle, testOnBorrow, testOnReturn,
timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
minEvictableIdleTimeMillis, testWhileIdle);
@@ -1164,7 +1179,7 @@ public class TestGenericKeyedObjectPool
assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
- pool = new GenericKeyedObjectPool<Object,Object>(null, maxActive, whenExhaustedAction,
+ pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive, whenExhaustedAction,
maxWait, maxIdle, maxTotal, testOnBorrow, testOnReturn,
timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
minEvictableIdleTimeMillis, testWhileIdle);
@@ -1186,7 +1201,7 @@ public class TestGenericKeyedObjectPool
assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
- pool = new GenericKeyedObjectPool<Object,Object>(null, maxActive, whenExhaustedAction,
+ pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive, whenExhaustedAction,
maxWait, maxIdle, maxTotal, minIdle, testOnBorrow, testOnReturn,
timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
minEvictableIdleTimeMillis, testWhileIdle);
@@ -1208,7 +1223,7 @@ public class TestGenericKeyedObjectPool
assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
- pool = new GenericKeyedObjectPool<Object,Object>(null, maxActive, whenExhaustedAction,
+ pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive, whenExhaustedAction,
maxWait, maxIdle, maxTotal, minIdle, testOnBorrow, testOnReturn,
timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
minEvictableIdleTimeMillis, testWhileIdle, lifo);