Author: markt
Date: Thu Jul 7 19:01:20 2011
New Revision: 1143977
URL: http://svn.apache.org/viewvc?rev=1143977&view=rev
Log:
Remove setFactory from GKOP
Modified:
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/BaseKeyedObjectPool.java
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/KeyedObjectPool.java
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/PoolUtils.java
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolFactory.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestBaseKeyedObjectPool.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestPoolUtils.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPoolFactory.java
Modified:
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/BaseKeyedObjectPool.java
URL:
http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/BaseKeyedObjectPool.java?rev=1143977&r1=1143976&r2=1143977&view=diff
==============================================================================
---
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/BaseKeyedObjectPool.java
(original)
+++
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/BaseKeyedObjectPool.java
Thu Jul 7 19:01:20 2011
@@ -128,18 +128,6 @@ public abstract class BaseKeyedObjectPoo
}
/**
- * Not supported in this base implementation.
- * Always throws an {@link UnsupportedOperationException},
- * subclasses should override this behavior.
- * @param factory the new KeyedPoolableObjectFactory
- * @deprecated to be removed in pool 2.0
- */
- @Deprecated
- public void setFactory(KeyedPoolableObjectFactory<K,V> factory) throws
IllegalStateException, UnsupportedOperationException {
- throw new UnsupportedOperationException();
- }
-
- /**
* Has this pool instance been closed.
* @return <code>true</code> when this pool has been closed.
* @since Pool 1.4
Modified:
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/KeyedObjectPool.java
URL:
http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/KeyedObjectPool.java?rev=1143977&r1=1143976&r2=1143977&view=diff
==============================================================================
---
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/KeyedObjectPool.java
(original)
+++
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/KeyedObjectPool.java
Thu Jul 7 19:01:20 2011
@@ -215,15 +215,4 @@ public interface KeyedObjectPool<K,V> {
* @throws Exception
*/
void close() throws Exception;
-
- /**
- * Sets the {@link KeyedPoolableObjectFactory factory} the pool uses
- * to create new instances (optional operation).
- * Once set, the factory cannot be changed.
- *
- * @param factory the {@link KeyedPoolableObjectFactory} used to create
new instances.
- * @throws IllegalStateException when the factory has already been set
- * @throws UnsupportedOperationException when this implementation doesn't
support the operation
- */
- void setFactory(KeyedPoolableObjectFactory<K,V> factory) throws
IllegalStateException, UnsupportedOperationException;
}
Modified:
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/PoolUtils.java
URL:
http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/PoolUtils.java?rev=1143977&r1=1143976&r2=1143977&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/PoolUtils.java
(original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/PoolUtils.java
Thu Jul 7 19:01:20 2011
@@ -856,19 +856,6 @@ public final class PoolUtils {
}
/**
- * Sets the object factory used by the pool.
- *
- * @param factory KeyedPoolableObjectFactory used by the pool
- * @deprecated to be removed in pool 2.0
- */
- @Deprecated
- public void setFactory(final KeyedPoolableObjectFactory<K,V> factory)
throws IllegalStateException, UnsupportedOperationException {
- synchronized (lock) {
- keyedPool.setFactory(factory);
- }
- }
-
- /**
* {@inheritDoc}
*/
@Override
@@ -1409,15 +1396,6 @@ public final class PoolUtils {
}
/**
- * {@inheritDoc}
- * @deprecated to be removed in pool 2.0
- */
- @Deprecated
- public void setFactory(final KeyedPoolableObjectFactory<K,V> factory)
throws IllegalStateException, UnsupportedOperationException {
- keyedPool.setFactory(factory);
- }
-
- /**
* Returns the underlying pool
*
* @return the keyed pool that this ErodingKeyedObjectPool wraps
Modified:
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
URL:
http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java?rev=1143977&r1=1143976&r2=1143977&view=diff
==============================================================================
---
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
(original)
+++
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
Thu Jul 7 19:01:20 2011
@@ -209,8 +209,8 @@ public class GenericKeyedObjectPool<K,T>
* Create a new <code>GenericKeyedObjectPool</code> using defaults and no
* factory.
*/
- public GenericKeyedObjectPool() {
- this(new GenericKeyedObjectPoolConfig<K, T>());
+ public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,T> factory) {
+ this(factory, new GenericKeyedObjectPoolConfig<K, T>());
}
/**
@@ -222,9 +222,10 @@ public class GenericKeyedObjectPool<K,T>
* the configuration object will not be reflected in the
* pool.
*/
- public GenericKeyedObjectPool(GenericKeyedObjectPoolConfig<K,T> config) {
+ public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,T> factory,
+ GenericKeyedObjectPoolConfig<K,T> config) {
// Copy the settings from the config
- this._factory = config.getFactory();
+ this._factory = factory;
this._lifo = config.getLifo();
this.maxIdlePerKey = config.getMaxIdlePerKey();
this._maxTotal = config.getMaxTotal();
@@ -1022,33 +1023,6 @@ public class GenericKeyedObjectPool<K,T>
startEvictor(-1L);
}
-
- /**
- * <p>Sets the keyed poolable object factory associated with this
pool.</p>
- *
- * <p>If this method is called when the factory has previously been set an
- * IllegalStateException is thrown.</p>
- *
- * @param factory KeyedPoolableObjectFactory to use when creating keyed
- * object pool instances
- * @throws IllegalStateException if the factory has already been set
- */
- @Override
- public void setFactory(KeyedPoolableObjectFactory<K,T> factory)
- throws IllegalStateException {
- if (this._factory == null) {
- synchronized (factoryLock) {
- if (this._factory == null) {
- this._factory = factory;
- } else {
- throw new IllegalStateException("Factory already set");
- }
- }
- } else {
- throw new IllegalStateException("Factory already set");
- }
- }
-
/**
* Clears oldest 15% of objects in pool. The method sorts the
@@ -1751,8 +1725,7 @@ public class GenericKeyedObjectPool<K,T>
private boolean _lifo = GenericKeyedObjectPoolConfig.DEFAULT_LIFO;
/** My {@link KeyedPoolableObjectFactory}. */
- private volatile KeyedPoolableObjectFactory<K,T> _factory = null;
- final private Object factoryLock = new Object();
+ final private KeyedPoolableObjectFactory<K,T> _factory;
/**
* My idle object eviction {@link TimerTask}, if any.
Modified:
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java
URL:
http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java?rev=1143977&r1=1143976&r2=1143977&view=diff
==============================================================================
---
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java
(original)
+++
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java
Thu Jul 7 19:01:20 2011
@@ -16,8 +16,6 @@
*/
package org.apache.commons.pool2.impl;
-import org.apache.commons.pool2.KeyedPoolableObjectFactory;
-
/**
* A simple "struct" encapsulating the configuration for a
* {@link GenericKeyedObjectPool}.
@@ -54,19 +52,9 @@ public class GenericKeyedObjectPoolConfi
private int maxTotal = DEFAULT_MAX_TOTAL;
- private KeyedPoolableObjectFactory<K,T> factory = null;
-
public GenericKeyedObjectPoolConfig() {
}
- public KeyedPoolableObjectFactory<K,T> getFactory() {
- return factory;
- }
-
- public void setFactory(KeyedPoolableObjectFactory<K,T> factory) {
- this.factory = factory;
- }
-
public int getMaxTotal() {
return maxTotal;
}
Modified:
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolFactory.java
URL:
http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolFactory.java?rev=1143977&r1=1143976&r2=1143977&view=diff
==============================================================================
---
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolFactory.java
(original)
+++
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolFactory.java
Thu Jul 7 19:01:20 2011
@@ -19,6 +19,7 @@ package org.apache.commons.pool2.impl;
import org.apache.commons.pool2.KeyedObjectPool;
import org.apache.commons.pool2.KeyedObjectPoolFactory;
+import org.apache.commons.pool2.KeyedPoolableObjectFactory;
/**
* A factory for creating {@link GenericKeyedObjectPool} instances from a
@@ -32,6 +33,7 @@ import org.apache.commons.pool2.KeyedObj
public class GenericKeyedObjectPoolFactory<K,T>
implements KeyedObjectPoolFactory<K,T> {
+ private KeyedPoolableObjectFactory<K,T> factory;
private GenericKeyedObjectPoolConfig<K, T> config;
/**
@@ -43,11 +45,21 @@ public class GenericKeyedObjectPoolFacto
* be reflected in this factory or the pools it creates.
*/
public GenericKeyedObjectPoolFactory(
+ KeyedPoolableObjectFactory<K,T> factory,
GenericKeyedObjectPoolConfig<K,T> config) {
+ this.factory = factory;
this.config = config.clone();
}
+ public KeyedPoolableObjectFactory<K,T> getFactory() {
+ return factory;
+ }
+
+ public void setFactory(KeyedPoolableObjectFactory<K,T> factory) {
+ this.factory = factory;
+ }
+
/**
* Obtain the configuration currently used by the factory allowing the
* current settings to be viewed and changed.
@@ -76,6 +88,6 @@ public class GenericKeyedObjectPoolFacto
* @return A pool configured with the current property settings
*/
public KeyedObjectPool<K,T> createPool() {
- return new GenericKeyedObjectPool<K,T>(config);
+ return new GenericKeyedObjectPool<K,T>(factory, config);
}
}
Modified:
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestBaseKeyedObjectPool.java
URL:
http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestBaseKeyedObjectPool.java?rev=1143977&r1=1143976&r2=1143977&view=diff
==============================================================================
---
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestBaseKeyedObjectPool.java
(original)
+++
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestBaseKeyedObjectPool.java
Thu Jul 7 19:01:20 2011
@@ -127,13 +127,6 @@ public class TestBaseKeyedObjectPool ext
// expected
}
- try {
- pool.setFactory(null);
- fail("Expected UnsupportedOperationException");
- } catch(UnsupportedOperationException e) {
- // expected
- }
-
pool.close(); // a no-op, probably should be remove
}
Modified:
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestPoolUtils.java
URL:
http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestPoolUtils.java?rev=1143977&r1=1143976&r2=1143977&view=diff
==============================================================================
---
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestPoolUtils.java
(original)
+++
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestPoolUtils.java
Thu Jul 7 19:01:20 2011
@@ -70,6 +70,7 @@ public class TestPoolUtils {
// expected
}
try {
+ @SuppressWarnings("unchecked")
final ObjectPool<Object> pool = createProxy(ObjectPool.class,
(List<String>)null);
PoolUtils.checkMinIdle(pool, -1, 1);
fail("PoolUtils.checkMinIdle(ObjectPool,,) must not accept
negative min idle values.");
@@ -80,6 +81,7 @@ public class TestPoolUtils {
final List<String> calledMethods = new ArrayList<String>();
// Test that the minIdle check doesn't add too many idle objects
+ @SuppressWarnings("unchecked")
final PoolableObjectFactory<Object> pof =
createProxy(PoolableObjectFactory.class, calledMethods);
final ObjectPool<Object> op = new GenericObjectPool<Object>(pof);
PoolUtils.checkMinIdle(op, 2, 100);
@@ -103,6 +105,7 @@ public class TestPoolUtils {
afe = null;
try {
calledMethods.clear();
+ @SuppressWarnings("unchecked")
final ObjectPool<Object> pool = createProxy(ObjectPool.class,
calledMethods);
final TimerTask task = PoolUtils.checkMinIdle(pool, 1,
CHECK_PERIOD); // checks minIdle immediately
@@ -135,6 +138,7 @@ public class TestPoolUtils {
// expected
}
try {
+ @SuppressWarnings("unchecked")
final KeyedObjectPool<Object,Object> pool =
createProxy(KeyedObjectPool.class, (List<String>)null);
PoolUtils.checkMinIdle(pool, (Object)null, 1, 1);
fail("PoolUtils.checkMinIdle(KeyedObjectPool,Object,int,long) must
not accept null keys.");
@@ -142,6 +146,7 @@ public class TestPoolUtils {
// expected
}
try {
+ @SuppressWarnings("unchecked")
final KeyedObjectPool<Object,Object> pool =
createProxy(KeyedObjectPool.class, (List<String>)null);
PoolUtils.checkMinIdle(pool, new Object(), -1, 1);
fail("PoolUtils.checkMinIdle(KeyedObjectPool,Object,int,long) must
not accept negative min idle values.");
@@ -153,9 +158,11 @@ public class TestPoolUtils {
final Object key = new Object();
// Test that the minIdle check doesn't add too many idle objects
- final KeyedPoolableObjectFactory<Object,Object> kpof =
createProxy(KeyedPoolableObjectFactory.class, calledMethods);
- final KeyedObjectPool<Object,Object> kop = new
GenericKeyedObjectPool<Object,Object>();
- kop.setFactory(kpof);
+ @SuppressWarnings("unchecked")
+ final KeyedPoolableObjectFactory<Object,Object> kpof =
+ createProxy(KeyedPoolableObjectFactory.class, calledMethods);
+ final KeyedObjectPool<Object,Object> kop =
+ new GenericKeyedObjectPool<Object,Object>(kpof);
PoolUtils.checkMinIdle(kop, key, 2, 100);
Thread.sleep(400);
assertEquals(2, kop.getNumIdle(key));
@@ -178,6 +185,7 @@ public class TestPoolUtils {
afe = null;
try {
calledMethods.clear();
+ @SuppressWarnings("unchecked")
final KeyedObjectPool<Object,Object> pool =
createProxy(KeyedObjectPool.class, calledMethods);
final TimerTask task = PoolUtils.checkMinIdle(pool, key, 1,
CHECK_PERIOD); // checks minIdle immediately
@@ -204,6 +212,7 @@ public class TestPoolUtils {
@Test
public void testCheckMinIdleKeyedObjectPoolKeys() throws Exception {
try {
+ @SuppressWarnings("unchecked")
final KeyedObjectPool<Object,Object> pool =
createProxy(KeyedObjectPool.class, (List<String>)null);
PoolUtils.checkMinIdle(pool, (Object)null, 1, 1);
fail("PoolUtils.checkMinIdle(KeyedObjectPool,Collection,int,long)
must not accept null keys.");
@@ -218,6 +227,7 @@ public class TestPoolUtils {
afe = null;
try {
final List<String> calledMethods = new ArrayList<String>();
+ @SuppressWarnings("unchecked")
final KeyedObjectPool<String,Object> pool =
createProxy(KeyedObjectPool.class, calledMethods);
final Collection<String> keys = new ArrayList<String>(2);
keys.add("one");
@@ -254,6 +264,7 @@ public class TestPoolUtils {
}
final List<String> calledMethods = new ArrayList<String>();
+ @SuppressWarnings("unchecked")
final ObjectPool<Object> pool = createProxy(ObjectPool.class,
calledMethods);
PoolUtils.prefill(pool, 0);
@@ -277,6 +288,7 @@ public class TestPoolUtils {
// expected
}
try {
+ @SuppressWarnings("unchecked")
final KeyedObjectPool<Object,Object> pool =
createProxy(KeyedObjectPool.class, (List<String>)null);
PoolUtils.prefill(pool, (Object)null, 1);
fail("PoolUtils.prefill(KeyedObjectPool,Object,int) must not
accept null key.");
@@ -285,6 +297,7 @@ public class TestPoolUtils {
}
final List<String> calledMethods = new ArrayList<String>();
+ @SuppressWarnings("unchecked")
final KeyedObjectPool<Object,Object> pool =
createProxy(KeyedObjectPool.class, calledMethods);
PoolUtils.prefill(pool, new Object(), 0);
@@ -302,6 +315,7 @@ public class TestPoolUtils {
@Test
public void testPrefillKeyedObjectPoolCollection() throws Exception {
try {
+ @SuppressWarnings("unchecked")
final KeyedObjectPool<String,String> pool =
createProxy(KeyedObjectPool.class, (List<String>)null);
PoolUtils.prefill(pool, (Collection<String>)null, 1);
fail("PoolUtils.prefill(KeyedObjectPool,Collection,int) must not
accept null keys.");
@@ -310,6 +324,7 @@ public class TestPoolUtils {
}
final List<String> calledMethods = new ArrayList<String>();
+ @SuppressWarnings("unchecked")
final KeyedObjectPool<String,Object> pool =
createProxy(KeyedObjectPool.class, calledMethods);
final Set<String> keys = new HashSet<String>();
@@ -338,6 +353,7 @@ public class TestPoolUtils {
}
final List<String> calledMethods = new ArrayList<String>();
+ @SuppressWarnings("unchecked")
final ObjectPool<Object> op = createProxy(ObjectPool.class,
calledMethods);
final ObjectPool<Object> sop = PoolUtils.synchronizedPool(op);
@@ -357,6 +373,7 @@ public class TestPoolUtils {
}
final List<String> calledMethods = new ArrayList<String>();
+ @SuppressWarnings("unchecked")
final KeyedObjectPool<Object,Object> kop =
createProxy(KeyedObjectPool.class, calledMethods);
final KeyedObjectPool<Object,Object> skop =
PoolUtils.synchronizedPool(kop);
@@ -376,6 +393,7 @@ public class TestPoolUtils {
}
final List<String> calledMethods = new ArrayList<String>();
+ @SuppressWarnings("unchecked")
final PoolableObjectFactory<Object> pof =
createProxy(PoolableObjectFactory.class, calledMethods);
@@ -396,6 +414,7 @@ public class TestPoolUtils {
}
final List<String> calledMethods = new ArrayList<String>();
+ @SuppressWarnings("unchecked")
final KeyedPoolableObjectFactory<Object,Object> kpof =
createProxy(KeyedPoolableObjectFactory.class, calledMethods);
@@ -444,7 +463,9 @@ public class TestPoolUtils {
// If the logic behind PoolUtils.erodingPool changes then this will
need to be tweaked.
float factor = 0.01f; // about ~9 seconds until first discard
- final ObjectPool<Object> pool =
PoolUtils.erodingPool(createProxy(ObjectPool.class, handler), factor);
+ @SuppressWarnings("unchecked")
+ final ObjectPool<Object> pool = PoolUtils.erodingPool(
+ createProxy(ObjectPool.class, handler), factor);
final List<String> expectedMethods = new ArrayList<String>();
assertEquals(expectedMethods, calledMethods);
@@ -536,6 +557,7 @@ public class TestPoolUtils {
// If the logic behind PoolUtils.erodingPool changes then this will
need to be tweaked.
float factor = 0.01f; // about ~9 seconds until first discard
+ @SuppressWarnings("unchecked")
final KeyedObjectPool<Object,Object> pool =
PoolUtils.erodingPool(createProxy(KeyedObjectPool.class, handler),
factor);
@@ -617,7 +639,9 @@ public class TestPoolUtils {
// If the logic behind PoolUtils.erodingPool changes then this will
need to be tweaked.
float factor = 0.01f; // about ~9 seconds until first discard
- final KeyedObjectPool<Object,Object> pool =
PoolUtils.erodingPool(createProxy(KeyedObjectPool.class, handler), factor,
true);
+ @SuppressWarnings("unchecked")
+ final KeyedObjectPool<Object,Object> pool = PoolUtils.erodingPool(
+ createProxy(KeyedObjectPool.class, handler), factor, true);
final List<String> expectedMethods = new ArrayList<String>();
assertEquals(expectedMethods, calledMethods);
@@ -690,13 +714,12 @@ public class TestPoolUtils {
kop.getNumIdle(null);
kop.invalidateObject(null, new Object());
kop.returnObject(null, new Object());
- kop.setFactory(createProxy(KeyedPoolableObjectFactory.class,
(List<String>)null));
kop.toString();
final List<String> expectedMethods = Arrays.asList(new String[] {
"addObject", "borrowObject", "clear", "clear", "close",
"getNumActive", "getNumActive", "getNumIdle", "getNumIdle",
"invalidateObject",
- "returnObject", "setFactory", "toString"
+ "returnObject", "toString"
});
return expectedMethods;
}
@@ -736,7 +759,9 @@ public class TestPoolUtils {
}
private static <T> T createProxy(final Class<T> clazz, final
InvocationHandler handler) {
- T ret = (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]
{ clazz }, handler);
+ @SuppressWarnings("unchecked")
+ T ret = (T) Proxy.newProxyInstance(
+ clazz.getClassLoader(), new Class[] { clazz }, handler);
return ret;
}
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=1143977&r1=1143976&r2=1143977&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
Thu Jul 7 19:01:20 2011
@@ -70,8 +70,7 @@ public class TestGenericKeyedObjectPool
};
GenericKeyedObjectPool<Object,Object> pool =
- new GenericKeyedObjectPool<Object,Object>();
- pool.setFactory(factory);
+ new GenericKeyedObjectPool<Object,Object>(factory);
pool.setMaxTotalPerKey(mincapacity);
pool.setMaxIdlePerKey(mincapacity);
return pool;
@@ -80,8 +79,7 @@ public class TestGenericKeyedObjectPool
@Override
protected KeyedObjectPool<Object,Object>
makeEmptyPool(KeyedPoolableObjectFactory<Object,Object> factory) {
GenericKeyedObjectPool<Object,Object> pool =
- new GenericKeyedObjectPool<Object,Object>();
- pool.setFactory(factory);
+ new GenericKeyedObjectPool<Object,Object>(factory);
return pool;
}
@@ -102,8 +100,8 @@ public class TestGenericKeyedObjectPool
@Before
public void setUp() throws Exception {
- pool = new GenericKeyedObjectPool<String,String>();
- pool.setFactory(new SimpleFactory<String>());
+ pool = new GenericKeyedObjectPool<String,String>(
+ new SimpleFactory<String>());
}
@Override
@@ -346,8 +344,8 @@ public class TestGenericKeyedObjectPool
@Test
public void testSettersAndGetters() throws Exception {
GenericKeyedObjectPool<String,String> pool =
- new GenericKeyedObjectPool<String,String>();
- pool.setFactory(new SimpleFactory<String>());
+ new GenericKeyedObjectPool<String,String>(
+ new SimpleFactory<String>());
{
pool.setMaxTotalPerKey(123);
assertEquals(123,pool.getMaxTotalPerKey());
@@ -540,8 +538,7 @@ public class TestGenericKeyedObjectPool
factory.setDestroyLatency(100); // Destroy takes 100 ms
factory.setMaxTotalPerKey(maxTotal); // (makes - destroys) bound
factory.setValidationEnabled(true);
- pool = new GenericKeyedObjectPool<String,String>();
- pool.setFactory(factory);
+ pool = new GenericKeyedObjectPool<String,String>(factory);
pool.setMaxTotal(maxTotal);
pool.setMaxIdlePerKey(-1);
pool.setTestOnReturn(true);
@@ -714,8 +711,8 @@ public class TestGenericKeyedObjectPool
private void checkEvictionOrder(boolean lifo) throws Exception {
SimpleFactory<Integer> factory = new SimpleFactory<Integer>();
- GenericKeyedObjectPool<Integer,String> pool = new
GenericKeyedObjectPool<Integer,String>();
- pool.setFactory(factory);
+ GenericKeyedObjectPool<Integer,String> pool =
+ new GenericKeyedObjectPool<Integer,String>(factory);
pool.setNumTestsPerEvictionRun(2);
pool.setMinEvictableIdleTimeMillis(100);
pool.setLifo(lifo);
@@ -837,8 +834,8 @@ public class TestGenericKeyedObjectPool
private void checkEvictorVisiting(boolean lifo) throws Exception {
VisitTrackerFactory<Integer> factory = new
VisitTrackerFactory<Integer>();
- GenericKeyedObjectPool<Integer,VisitTracker<Integer>> pool = new
GenericKeyedObjectPool<Integer,VisitTracker<Integer>>();
- pool.setFactory(factory);
+ GenericKeyedObjectPool<Integer,VisitTracker<Integer>> pool =
+ new GenericKeyedObjectPool<Integer,VisitTracker<Integer>>(factory);
pool.setNumTestsPerEvictionRun(2);
pool.setMinEvictableIdleTimeMillis(-1);
pool.setTestWhileIdle(true);
@@ -925,8 +922,8 @@ public class TestGenericKeyedObjectPool
// Can't use clear as some objects are still active so create
// a new pool
factory = new VisitTrackerFactory<Integer>();
- pool = new
GenericKeyedObjectPool<Integer,VisitTracker<Integer>>();
- pool.setFactory(factory);
+ pool = new
GenericKeyedObjectPool<Integer,VisitTracker<Integer>>(
+ factory);
pool.setMaxIdlePerKey(-1);
pool.setMaxTotalPerKey(-1);
pool.setNumTestsPerEvictionRun(smallPrimes[i]);
@@ -1021,7 +1018,8 @@ public class TestGenericKeyedObjectPool
WhenExhaustedAction whenExhaustedAction = WhenExhaustedAction.FAIL;
boolean lifo = false;
- GenericKeyedObjectPool<Object,Object> pool = new
GenericKeyedObjectPool<Object,Object>();
+ GenericKeyedObjectPool<Object,Object> pool =
+ new GenericKeyedObjectPool<Object,Object>(null);
assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL_PER_KEY,
pool.getMaxTotalPerKey());
assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE_PER_KEY,
pool.getMaxIdlePerKey());
assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_WAIT,
pool.getMaxWait());
@@ -1058,7 +1056,7 @@ public class TestGenericKeyedObjectPool
config.setTestWhileIdle(testWhileIdle);
config.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
config.setWhenExhaustedAction(whenExhaustedAction);
- pool = new GenericKeyedObjectPool<Object,Object>(config);
+ pool = new GenericKeyedObjectPool<Object,Object>(null, config);
assertEquals(maxTotalPerKey, pool.getMaxTotalPerKey());
assertEquals(maxIdle, pool.getMaxIdlePerKey());
assertEquals(maxWait, pool.getMaxWait());
@@ -1080,8 +1078,7 @@ public class TestGenericKeyedObjectPool
public void testExceptionOnPassivateDuringReturn() throws Exception {
SimpleFactory<String> factory = new SimpleFactory<String>();
GenericKeyedObjectPool<String,String> pool =
- new GenericKeyedObjectPool<String,String>();
- pool.setFactory(factory);
+ new GenericKeyedObjectPool<String,String>(factory);
String obj = pool.borrowObject("one");
factory.setThrowExceptionOnPassivate(true);
pool.returnObject("one", obj);
@@ -1095,8 +1092,7 @@ public class TestGenericKeyedObjectPool
factory.setThrowExceptionOnDestroy(true);
factory.setValidationEnabled(true);
GenericKeyedObjectPool<String,String> pool =
- new GenericKeyedObjectPool<String,String>();
- pool.setFactory(factory);
+ new GenericKeyedObjectPool<String,String>(factory);
pool.setTestOnBorrow(true);
pool.borrowObject("one");
factory.setValid(false); // Make validation fail on next borrow attempt
@@ -1118,8 +1114,7 @@ public class TestGenericKeyedObjectPool
factory.setThrowExceptionOnDestroy(true);
factory.setValidationEnabled(true);
GenericKeyedObjectPool<String,String> pool =
- new GenericKeyedObjectPool<String,String>();
- pool.setFactory(factory);
+ new GenericKeyedObjectPool<String,String>(factory);
pool.setTestOnReturn(true);
String obj1 = pool.borrowObject("one");
pool.borrowObject("one");
@@ -1135,8 +1130,7 @@ public class TestGenericKeyedObjectPool
public void testExceptionOnActivateDuringBorrow() throws Exception {
SimpleFactory<String> factory = new SimpleFactory<String>();
GenericKeyedObjectPool<String,String> pool =
- new GenericKeyedObjectPool<String,String>();
- pool.setFactory(factory);
+ new GenericKeyedObjectPool<String,String>(factory);
String obj1 = pool.borrowObject("one");
String obj2 = pool.borrowObject("one");
pool.returnObject("one", obj1);
@@ -1171,8 +1165,7 @@ public class TestGenericKeyedObjectPool
public void testBlockedKeyDoesNotBlockPool() throws Exception {
SimpleFactory<String> factory = new SimpleFactory<String>();
GenericKeyedObjectPool<String,String> pool =
- new GenericKeyedObjectPool<String,String>();
- pool.setFactory(factory);
+ new GenericKeyedObjectPool<String,String>(factory);
pool.setWhenExhaustedAction(WhenExhaustedAction.BLOCK);
pool.setMaxWait(5000);
pool.setMaxTotalPerKey(1);
@@ -1218,8 +1211,7 @@ public class TestGenericKeyedObjectPool
final int threadsPerKey = 5; // number of threads to grab the key
initially
SimpleFactory<String> factory = new SimpleFactory<String>();
GenericKeyedObjectPool<String,String> pool =
- new GenericKeyedObjectPool<String,String>();
- pool.setFactory(factory);
+ new GenericKeyedObjectPool<String,String>(factory);
pool.setWhenExhaustedAction(WhenExhaustedAction.BLOCK);
pool.setMaxWait(maxWait);
pool.setMaxTotalPerKey(threadsPerKey);
@@ -1273,8 +1265,7 @@ public class TestGenericKeyedObjectPool
// TODO Fix this. Can't use local pool since runTestThreads uses the
// protected pool field
GenericKeyedObjectPool<String,Waiter> pool =
- new GenericKeyedObjectPool<String,Waiter>();
- pool.setFactory(factory);
+ new GenericKeyedObjectPool<String,Waiter>(factory);
pool.setMaxTotalPerKey(5);
pool.setMaxTotal(8);
pool.setTestOnBorrow(true);
@@ -1291,8 +1282,7 @@ public class TestGenericKeyedObjectPool
// Make destroy have some latency so clearOldest takes some time
WaiterFactory<String> factory = new WaiterFactory<String>(0, 20, 0, 0,
0, 0, 50, 5, 0);
GenericKeyedObjectPool<String,Waiter> pool =
- new GenericKeyedObjectPool<String,Waiter>();
- pool.setFactory(factory);
+ new GenericKeyedObjectPool<String,Waiter>(factory);
pool.setMaxTotalPerKey(5);
pool.setMaxTotal(50);
pool.setLifo(false);
@@ -1317,23 +1307,6 @@ public class TestGenericKeyedObjectPool
pool.returnObject("1", waiter); // Will throw IllegalStateException
if dead
}
- /**
- * Test case for POOL-150.
- */
- @Test
- public void testPreparePoolNullFactory() throws Exception {
- GenericKeyedObjectPool<Object, Object> gkop =
- new GenericKeyedObjectPool<Object, Object>();
- gkop.setMinIdlePerKey(1);
- Exception e = null;
- try {
- gkop.preparePool("foo");
- } catch (IllegalStateException ise) {
- e = ise;
- }
- assertNotNull(e);
- }
-
/*
* 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/TestGenericKeyedObjectPoolFactory.java
URL:
http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPoolFactory.java?rev=1143977&r1=1143976&r2=1143977&view=diff
==============================================================================
---
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPoolFactory.java
(original)
+++
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPoolFactory.java
Thu Jul 7 19:01:20 2011
@@ -37,8 +37,8 @@ public class TestGenericKeyedObjectPoolF
final KeyedPoolableObjectFactory<Object,Object> objectFactory) {
GenericKeyedObjectPoolConfig<Object,Object> config =
new GenericKeyedObjectPoolConfig<Object,Object>();
- config.setFactory(objectFactory);
- return new GenericKeyedObjectPoolFactory<Object,Object>(config);
+ return new GenericKeyedObjectPoolFactory<Object,Object>(objectFactory,
+ config);
}
@Test
@@ -57,9 +57,9 @@ public class TestGenericKeyedObjectPoolF
config.setTimeBetweenEvictionRunsMillis(8);
config.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
config.setLifo(false);
- config.setFactory(createObjectFactory());
GenericKeyedObjectPoolFactory<Object,Object> factory =
- new GenericKeyedObjectPoolFactory<Object,Object>(config);
+ new GenericKeyedObjectPoolFactory<Object,Object>(
+ createObjectFactory(), config);
GenericKeyedObjectPool<Object,Object> pool =
(GenericKeyedObjectPool<Object,Object>)factory.createPool();
assertEquals(1, pool.getMaxTotalPerKey());