commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1139666 - in /commons/proper/pool/trunk/src: changes/ java/org/apache/commons/pool2/ java/org/apache/commons/pool2/impl/ test/org/apache/commons/pool2/ test/org/apache/commons/pool2/impl/ test/org/apache/commons/pool2/performance/
Date Sat, 25 Jun 2011 23:25:49 GMT
Author: markt
Date: Sat Jun 25 23:25:49 2011
New Revision: 1139666

URL: http://svn.apache.org/viewvc?rev=1139666&view=rev
Log:
Remove setFactory() from GOP.

Modified:
    commons/proper/pool/trunk/src/changes/changes.xml
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/BaseObjectPool.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/ObjectPool.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/PoolUtils.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolFactory.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/SoftReferenceObjectPool.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestBaseObjectPool.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestPoolUtils.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPool.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPoolFactory.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/performance/PerformanceTest.java

Modified: commons/proper/pool/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/changes/changes.xml?rev=1139666&r1=1139665&r2=1139666&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/changes/changes.xml (original)
+++ commons/proper/pool/trunk/src/changes/changes.xml Sat Jun 25 23:25:49 2011
@@ -64,6 +64,9 @@
     <action dev="markt" type="fix" issue="POOL-121">
       Provide a name for the eviction timer thread.
     </action>
+    <action dev="markt" type="update">
+      Remove setFactory() method from GOP.
+    </action>
   </release>
   <release version="1.5.6" date="2011-04-03" description="This is a patch release, including
bugfixes only.">
     <action dev="markt" type="fix" issue="POOL-179" due-to="Axel Grossmann">

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/BaseObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/BaseObjectPool.java?rev=1139666&r1=1139665&r2=1139666&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/BaseObjectPool.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/BaseObjectPool.java Sat Jun
25 23:25:49 2011
@@ -108,21 +108,6 @@ public abstract class BaseObjectPool<T> 
     }
 
     /**
-     * Not supported in this base implementation.
-     * Always throws an {@link UnsupportedOperationException},
-     * subclasses should override this behavior.
-     * 
-     * @param factory the PoolableObjectFactory
-     * @throws UnsupportedOperationException
-     * @throws IllegalStateException
-     * @deprecated to be removed in pool 2.0
-     */
-    @Deprecated
-    public void setFactory(PoolableObjectFactory<T> factory) throws IllegalStateException,
UnsupportedOperationException {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
      * Has this pool instance been closed.
      * @return <code>true</code> when this pool has been closed.
      */

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/ObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/ObjectPool.java?rev=1139666&r1=1139665&r2=1139666&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/ObjectPool.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/ObjectPool.java Sat Jun 25
23:25:49 2011
@@ -175,17 +175,4 @@ public interface ObjectPool<T> {
      * @throws Exception <strong>deprecated</strong>: implementations should
silently fail if not all resources can be freed.
      */
     void close() throws Exception;
-
-    /**
-     * Sets the {@link PoolableObjectFactory factory} this pool uses
-     * to create new instances (optional operation). Trying to change
-     * the <code>factory</code> after a pool has been used will frequently
-     * throw an {@link UnsupportedOperationException}. It is up to the pool
-     * implementation to determine when it is acceptable to call this method.
-     *
-     * @param factory the {@link PoolableObjectFactory} used to create new instances.
-     * @throws IllegalStateException when the factory cannot be set at this time
-     * @throws UnsupportedOperationException if this implementation does not support the
operation
-     */
-    void setFactory(PoolableObjectFactory<T> 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=1139666&r1=1139665&r2=1139666&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 Sat Jun 25
23:25:49 2011
@@ -700,19 +700,6 @@ public final class PoolUtils {
         }
 
         /**
-         * Sets the factory used by the pool.
-         * 
-         * @param factory new PoolableObjectFactory
-         * @deprecated to be removed in pool 2.0
-         */
-        @Deprecated
-        public void setFactory(final PoolableObjectFactory<T> factory) throws IllegalStateException,
UnsupportedOperationException {
-            synchronized (lock) {
-                pool.setFactory(factory);
-            }
-        }
-
-        /**
          * {@inheritDoc}
          */
         @Override
@@ -1250,15 +1237,6 @@ public final class PoolUtils {
 
         /**
          * {@inheritDoc}
-         * @deprecated to be removed in pool 2.0
-         */
-        @Deprecated
-        public void setFactory(final PoolableObjectFactory<T> factory) throws IllegalStateException,
UnsupportedOperationException {
-            pool.setFactory(factory);
-        }
-
-        /**
-         * {@inheritDoc}
          */
         @Override
         public String toString() {

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java?rev=1139666&r1=1139665&r2=1139666&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java
Sat Jun 25 23:25:49 2011
@@ -171,12 +171,13 @@ public class GenericObjectPool<T> extend
     /**
      * Create a new <tt>GenericObjectPool</tt> with default properties.
      */
-    public GenericObjectPool() {
-        this(new GenericObjectPoolConfig<T>());
+    public GenericObjectPool(PoolableObjectFactory<T> factory) {
+        this(factory, new GenericObjectPoolConfig<T>());
     }
 
-    public GenericObjectPool(GenericObjectPoolConfig<T> config) {
-        this.factory = config.getFactory();
+    public GenericObjectPool(PoolableObjectFactory<T> factory,
+            GenericObjectPoolConfig<T> config) {
+        this.factory = factory;
         this.lifo = config.getLifo();
         this.maxTotal = config.getMaxTotal();
         this.maxIdle = config.getMaxIdle();
@@ -931,33 +932,6 @@ public class GenericObjectPool<T> extend
     }
 
     /**
-      * <p>Sets the 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
-     *            the {@link PoolableObjectFactory} used to create new
-     *            instances.
-      * @throws IllegalStateException if the factory has already been set
-     */
-    @Override
-    public void setFactory(PoolableObjectFactory<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");
-        }
-    }
-
-    /**
      * <p>
      * Perform <code>numTests</code> idle object eviction tests, evicting
      * examined objects that meet the criteria for eviction. If
@@ -1381,8 +1355,7 @@ public class GenericObjectPool<T> extend
     private volatile boolean lifo = GenericObjectPoolConfig.DEFAULT_LIFO;
 
     /** My {@link PoolableObjectFactory}. */
-    private volatile PoolableObjectFactory<T> factory;
-    final private Object factoryLock = new Object();
+    final private PoolableObjectFactory<T> factory;
 
     /**
      * My idle object eviction {@link TimerTask}, if any.

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java?rev=1139666&r1=1139665&r2=1139666&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java
(original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java
Sat Jun 25 23:25:49 2011
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.pool2.impl;
 
-import org.apache.commons.pool2.PoolableObjectFactory;
-
 /**
  * A simple "struct" encapsulating the configuration for a
  * {@link GenericObjectPool}.
@@ -49,8 +47,6 @@ public class GenericObjectPoolConfig<T> 
     public static final int DEFAULT_MIN_IDLE = 0;
 
     
-    private PoolableObjectFactory<T> factory = null;
-
     private long softMinEvictableIdleTimeMillis =
         DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
 
@@ -61,15 +57,6 @@ public class GenericObjectPoolConfig<T> 
     private int minIdle = DEFAULT_MIN_IDLE;
 
 
-    public PoolableObjectFactory<T> getFactory() {
-        return factory;
-    }
-
-    public void setFactory(PoolableObjectFactory<T> factory) {
-        this.factory = factory;
-    }
-
-
     public long getSoftMinEvictableIdleTimeMillis() {
         return softMinEvictableIdleTimeMillis;
     }

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolFactory.java?rev=1139666&r1=1139665&r2=1139666&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolFactory.java
(original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolFactory.java
Sat Jun 25 23:25:49 2011
@@ -19,6 +19,7 @@ package org.apache.commons.pool2.impl;
 
 import org.apache.commons.pool2.ObjectPool;
 import org.apache.commons.pool2.ObjectPoolFactory;
+import org.apache.commons.pool2.PoolableObjectFactory;
 
 /**
  * A factory for creating {@link GenericObjectPool} instances from a provided
@@ -31,6 +32,7 @@ import org.apache.commons.pool2.ObjectPo
 
 public class GenericObjectPoolFactory<T> implements ObjectPoolFactory<T> {
 
+    private PoolableObjectFactory<T> factory;
     private GenericObjectPoolConfig<T> config;
 
 
@@ -42,11 +44,21 @@ public class GenericObjectPoolFactory<T>
      *                  passed by value. Subsequent changes to config will not
      *                  be reflected in this factory or the pools it creates.
      */
-    public GenericObjectPoolFactory(GenericObjectPoolConfig<T> config) {
+    public GenericObjectPoolFactory(PoolableObjectFactory<T> factory,
+            GenericObjectPoolConfig<T> config) {
+        this.factory = factory;
         this.config = config.clone();
     }
 
     
+    public PoolableObjectFactory<T> getFactory() {
+        return factory;
+    }
+    
+    public void setFactory(PoolableObjectFactory<T> factory) {
+        this.factory = factory;
+    }
+
     /**
      * Obtain the configuration currently used by the factory allowing the
      * current settings to be viewed and changed.
@@ -75,6 +87,6 @@ public class GenericObjectPoolFactory<T>
      * @return A pool configured with the current property settings
      */
     public ObjectPool<T> createPool() {
-        return new GenericObjectPool<T>(config);
+        return new GenericObjectPool<T>(factory, config);
     }
 }

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/SoftReferenceObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/SoftReferenceObjectPool.java?rev=1139666&r1=1139665&r2=1139666&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/SoftReferenceObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/SoftReferenceObjectPool.java
Sat Jun 25 23:25:49 2011
@@ -43,21 +43,6 @@ import org.apache.commons.pool2.Poolable
  */
 public class SoftReferenceObjectPool<T> extends BaseObjectPool<T> {
     /**
-     * Create a <code>SoftReferenceObjectPool</code> without a factory.
-     * {@link #setFactory(PoolableObjectFactory) setFactory} should be called
-     * before any attempts to use the pool are made.
-     * Generally speaking you should prefer the {@link #SoftReferenceObjectPool(PoolableObjectFactory)}
constructor.
-     *
-     * @see #SoftReferenceObjectPool(PoolableObjectFactory)
-     * @deprecated to be removed in pool 2.0.  Use {@link #SoftReferenceObjectPool(PoolableObjectFactory)}.
-     */
-    @Deprecated
-    public SoftReferenceObjectPool() {
-        _pool = new ArrayList<SoftReference<T>>();
-        _factory = null;
-    }
-
-    /**
      * Create a <code>SoftReferenceObjectPool</code> with the specified factory.
      *
      * @param factory object factory to use.
@@ -67,25 +52,6 @@ public class SoftReferenceObjectPool<T> 
         _factory = factory;
     }
 
-    /**
-     * Create a <code>SoftReferenceObjectPool</code> with the specified factory
and initial idle object count.
-     *
-     * @param factory object factory to use.
-     * @param initSize initial size to attempt to prefill the pool.
-     * @throws Exception when there is a problem prefilling the pool.
-     * @throws IllegalArgumentException when <code>factory</code> is <code>null</code>.
-     * @deprecated because this is a SoftReference pool, prefilled idle obejects may be garbage
collected before they are used.
-     *      To be removed in Pool 2.0.
-     */
-    @Deprecated
-    public SoftReferenceObjectPool(PoolableObjectFactory<T> factory, int initSize)
throws Exception, IllegalArgumentException {
-        if (factory == null) {
-            throw new IllegalArgumentException("factory required to prefill the pool.");
-        }
-        _pool = new ArrayList<SoftReference<T>>(initSize);
-        _factory = factory;
-        PoolUtils.prefill(this, initSize);
-    }
 
     /**
      * <p>Borrow an object from the pool.  If there are no idle instances available
in the pool, the configured
@@ -314,29 +280,7 @@ public class SoftReferenceObjectPool<T> 
         clear();
     }
 
-    /**
-     * Sets the {@link PoolableObjectFactory factory} this pool uses
-     * to create new instances. Trying to change
-     * the <code>factory</code> while there are borrowed objects will
-     * throw an {@link IllegalStateException}.
-     *
-     * @param factory the {@link PoolableObjectFactory} used to create new instances.
-     * @throws IllegalStateException when the factory cannot be set at this time
-     * @deprecated to be removed in pool 2.0
-     */
-    @Override
-    @Deprecated
-    public synchronized void setFactory(PoolableObjectFactory<T> factory) throws IllegalStateException
{
-        assertOpen();
-        if(0 < getNumActive()) {
-            throw new IllegalStateException("Objects are already active");
-        } else {
-            clear();
-            _factory = factory;
-        }
-    }
-
-    /**
+     /**
      * If any idle objects were garbage collected, remove their
      * {@link Reference} wrappers from the idle object pool.
      */

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestBaseObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestBaseObjectPool.java?rev=1139666&r1=1139665&r2=1139666&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestBaseObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestBaseObjectPool.java Sat
Jun 25 23:25:49 2011
@@ -108,13 +108,6 @@ public class TestBaseObjectPool extends 
         } catch(UnsupportedOperationException e) {
             // expected
         }
-
-        try {
-            pool.setFactory(null);
-            fail("Expected UnsupportedOperationException");
-        } catch(UnsupportedOperationException e) {
-            // expected
-        }
     }
 
     @Test

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=1139666&r1=1139665&r2=1139666&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 Sat Jun
25 23:25:49 2011
@@ -81,8 +81,7 @@ public class TestPoolUtils {
 
         // Test that the minIdle check doesn't add too many idle objects
         final PoolableObjectFactory<Object> pof = createProxy(PoolableObjectFactory.class,
calledMethods);
-        final ObjectPool<Object> op = new GenericObjectPool<Object>();
-        op.setFactory(pof);
+        final ObjectPool<Object> op = new GenericObjectPool<Object>(pof);
         PoolUtils.checkMinIdle(op, 2, 100);
         Thread.sleep(400);
         assertEquals(2, op.getNumIdle());
@@ -669,13 +668,12 @@ public class TestPoolUtils {
         op.getNumIdle();
         op.invalidateObject(new Object());
         op.returnObject(new Object());
-        op.setFactory(createProxy(PoolableObjectFactory.class, (List<String>)null));
         op.toString();
 
         final List<String> expectedMethods = Arrays.asList(new String[] {
                 "addObject", "borrowObject", "clear", "close",
                 "getNumActive", "getNumIdle", "invalidateObject",
-                "returnObject", "setFactory", "toString"
+                "returnObject", "toString"
         });
         return expectedMethods;
     }

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPool.java?rev=1139666&r1=1139665&r2=1139666&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPool.java
Sat Jun 25 23:25:49 2011
@@ -47,17 +47,17 @@ public class TestGenericObjectPool exten
 
     @Override
     protected ObjectPool<Object> makeEmptyPool(int mincap) {
-       GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-       pool.setFactory(new SimpleFactory());
+       GenericObjectPool<Object> pool =
+           new GenericObjectPool<Object>(new SimpleFactory());
        pool.setMaxTotal(mincap);
        pool.setMaxIdle(mincap);
        return pool;
     }
 
     @Override
-    protected ObjectPool<Object> makeEmptyPool(final PoolableObjectFactory<Object>
factory) {
-        GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-        pool.setFactory(factory);
+    protected ObjectPool<Object> makeEmptyPool(
+            final PoolableObjectFactory<Object> factory) {
+        GenericObjectPool<Object> pool = new GenericObjectPool<Object>(factory);
         return pool;
     }
 
@@ -68,8 +68,7 @@ public class TestGenericObjectPool exten
 
     @Before
     public void setUp() throws Exception {
-        pool = new GenericObjectPool<Object>();
-        pool.setFactory(new SimpleFactory());
+        pool = new GenericObjectPool<Object>(new SimpleFactory());
     }
 
     @After
@@ -170,8 +169,7 @@ public class TestGenericObjectPool exten
         SimpleFactory factory = new SimpleFactory();
         factory.setMakeLatency(300);
         factory.setMaxTotal(2);
-        GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-        pool.setFactory(factory);
+        GenericObjectPool<Object> pool = new GenericObjectPool<Object>(factory);
         pool.setMaxTotal(2);
         pool.setMinIdle(1);
         pool.borrowObject(); // numActive = 1, numIdle = 0
@@ -200,8 +198,8 @@ public class TestGenericObjectPool exten
     public void checkEvict(boolean lifo) throws Exception {
         // yea this is hairy but it tests all the code paths in GOP.evict()
         final SimpleFactory factory = new SimpleFactory();
-        final GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-        pool.setFactory(factory);
+        final GenericObjectPool<Object> pool =
+            new GenericObjectPool<Object>(factory);
         pool.setSoftMinEvictableIdleTimeMillis(10);
         pool.setMinIdle(2);
         pool.setTestWhileIdle(true);
@@ -238,8 +236,8 @@ public class TestGenericObjectPool exten
     
     private void checkEvictionOrder(boolean lifo) throws Exception {
         SimpleFactory factory = new SimpleFactory();
-        GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-        pool.setFactory(factory);
+        GenericObjectPool<Object> pool =
+            new GenericObjectPool<Object>(factory);
         pool.setNumTestsPerEvictionRun(2);
         pool.setMinEvictableIdleTimeMillis(100);
         pool.setLifo(lifo);
@@ -257,8 +255,7 @@ public class TestGenericObjectPool exten
         
         // Two eviction runs in sequence
         factory = new SimpleFactory();
-        pool = new GenericObjectPool<Object>();
-        pool.setFactory(factory);
+        pool = new GenericObjectPool<Object>(factory);
         pool.setNumTestsPerEvictionRun(2);
         pool.setMinEvictableIdleTimeMillis(100);
         pool.setLifo(lifo);
@@ -283,8 +280,8 @@ public class TestGenericObjectPool exten
     
     private void checkEvictorVisiting(boolean lifo) throws Exception {
         VisitTrackerFactory<Object> factory = new VisitTrackerFactory<Object>();
-        GenericObjectPool<VisitTracker<Object>> pool = new GenericObjectPool<VisitTracker<Object>>();
-        pool.setFactory(factory);
+        GenericObjectPool<VisitTracker<Object>> pool =
+            new GenericObjectPool<VisitTracker<Object>>(factory);
         pool.setNumTestsPerEvictionRun(2);
         pool.setMinEvictableIdleTimeMillis(-1);
         pool.setTestWhileIdle(true);
@@ -316,8 +313,7 @@ public class TestGenericObjectPool exten
         } 
 
         factory = new VisitTrackerFactory<Object>();
-        pool = new GenericObjectPool<VisitTracker<Object>>();
-        pool.setFactory(factory);
+        pool = new GenericObjectPool<VisitTracker<Object>>(factory);
         pool.setNumTestsPerEvictionRun(3);
         pool.setMinEvictableIdleTimeMillis(-1);
         pool.setTestWhileIdle(true);
@@ -361,8 +357,7 @@ public class TestGenericObjectPool exten
         for (int i = 0; i < 4; i++) {
             pool.setNumTestsPerEvictionRun(smallPrimes[i]);
             for (int j = 0; j < 5; j++) {
-                pool = new GenericObjectPool<VisitTracker<Object>>();
-                pool.setFactory(factory);
+                pool = new GenericObjectPool<VisitTracker<Object>>(factory);
                 pool.setNumTestsPerEvictionRun(3);
                 pool.setMinEvictableIdleTimeMillis(-1);
                 pool.setTestWhileIdle(true);
@@ -404,8 +399,7 @@ public class TestGenericObjectPool exten
     @Test
     public void testExceptionOnPassivateDuringReturn() throws Exception {
         SimpleFactory factory = new SimpleFactory();        
-        GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-        pool.setFactory(factory);
+        GenericObjectPool<Object> pool = new GenericObjectPool<Object>(factory);
         Object obj = pool.borrowObject();
         factory.setThrowExceptionOnPassivate(true);
         pool.returnObject(obj);
@@ -417,8 +411,7 @@ public class TestGenericObjectPool exten
     public void testExceptionOnDestroyDuringBorrow() throws Exception {
         SimpleFactory factory = new SimpleFactory(); 
         factory.setThrowExceptionOnDestroy(true);
-        GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-        pool.setFactory(factory);
+        GenericObjectPool<Object> pool = new GenericObjectPool<Object>(factory);
         pool.setTestOnBorrow(true);
         pool.borrowObject();
         factory.setValid(false); // Make validation fail on next borrow attempt
@@ -436,8 +429,7 @@ public class TestGenericObjectPool exten
     public void testExceptionOnDestroyDuringReturn() throws Exception {
         SimpleFactory factory = new SimpleFactory(); 
         factory.setThrowExceptionOnDestroy(true);
-        GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-        pool.setFactory(factory);
+        GenericObjectPool<Object> pool = new GenericObjectPool<Object>(factory);
         pool.setTestOnReturn(true);
         Object obj1 = pool.borrowObject();
         pool.borrowObject();
@@ -450,8 +442,7 @@ public class TestGenericObjectPool exten
     @Test
     public void testExceptionOnActivateDuringBorrow() throws Exception {
         SimpleFactory factory = new SimpleFactory(); 
-        GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-        pool.setFactory(factory);
+        GenericObjectPool<Object> pool = new GenericObjectPool<Object>(factory);
         Object obj1 = pool.borrowObject();
         Object obj2 = pool.borrowObject();
         pool.returnObject(obj1);
@@ -479,22 +470,6 @@ public class TestGenericObjectPool exten
     }
 
     @Test
-    /**
-     * Verify that once the factory is set, it cannot be reset.
-     * This is a change in behavior as of Pool 2.0
-     */
-    public void testSetFactoryAlreadySet() throws Exception {
-        GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-        pool.setFactory(new SimpleFactory());
-        try {
-            pool.setFactory(new SimpleFactory());
-            fail("Expected IllegalStateException");
-        } catch(IllegalStateException e) {
-            // expected
-        }
-    }
-
-    @Test
     public void testNegativeMaxTotal() throws Exception {
         pool.setMaxTotal(-1);
         pool.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
@@ -596,8 +571,7 @@ public class TestGenericObjectPool exten
         
         SimpleFactory factory = new SimpleFactory();
         factory.setMaxTotal(maxTotal);
-        GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-        pool.setFactory(factory);
+        GenericObjectPool<Object> pool = new GenericObjectPool<Object>(factory);
         pool.setMaxTotal(maxTotal);
         pool.setWhenExhaustedAction(WhenExhaustedAction.BLOCK);
         pool.setTimeBetweenEvictionRunsMillis(-1);
@@ -668,10 +642,8 @@ public class TestGenericObjectPool exten
 
     @Test
     public void testSettersAndGetters() throws Exception {
-        GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-        {
-            pool.setFactory(new SimpleFactory());
-        }
+        GenericObjectPool<Object> pool =
+            new GenericObjectPool<Object>(new SimpleFactory());
         {
             pool.setMaxTotal(123);
             assertEquals(123,pool.getMaxTotal());
@@ -728,28 +700,18 @@ public class TestGenericObjectPool exten
     
     @Test
     public void testDefaultConfiguration() throws Exception {
-        GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
+        SimpleFactory factory = new SimpleFactory();
+        GenericObjectPool<Object> pool =
+            new GenericObjectPool<Object>(factory);
         assertConfiguration(new GenericObjectPoolConfig<Object>(),pool);
     }
 
     @Test
-    public void testConstructors() throws Exception {
-        {
-            GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-            assertConfiguration(new GenericObjectPoolConfig<Object>(),pool);
-        }
-        {
-            GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-            pool.setFactory(new SimpleFactory());
-            assertConfiguration(new GenericObjectPoolConfig<Object>(),pool);
-        }
-    }
-
-    @Test
     public void testSetConfig() throws Exception {
         GenericObjectPoolConfig<Object> expected =
             new GenericObjectPoolConfig<Object>();
-        GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
+        GenericObjectPool<Object> pool =
+            new GenericObjectPool<Object>(new SimpleFactory());
         assertConfiguration(expected,pool);
         expected.setMaxTotal(2);
         expected.setMaxIdle(3);
@@ -767,8 +729,8 @@ public class TestGenericObjectPool exten
 
     @Test
     public void testDebugInfo() throws Exception {
-        GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-        pool.setFactory(new SimpleFactory());
+        GenericObjectPool<Object> pool =
+            new GenericObjectPool<Object>(new SimpleFactory());
         pool.setMaxIdle(3);
         assertNotNull(pool.debugInfo());
         Object obj = pool.borrowObject();
@@ -908,8 +870,8 @@ public class TestGenericObjectPool exten
             }
         }
         
-        GenericObjectPool<TimeTest> pool = new GenericObjectPool<TimeTest>();
-        pool.setFactory(new TimeTest());
+        GenericObjectPool<TimeTest> pool =
+            new GenericObjectPool<TimeTest>(new TimeTest());
         
         pool.setMaxIdle(5);
         pool.setMaxTotal(5);
@@ -1068,8 +1030,7 @@ public class TestGenericObjectPool exten
         factory.setDestroyLatency(100);  // Destroy takes 100 ms
         factory.setMaxTotal(maxTotal); // (makes - destroys) bound
         factory.setValidationEnabled(true);
-        pool = new GenericObjectPool<Object>();
-        pool.setFactory(factory);
+        pool = new GenericObjectPool<Object>(factory);
         pool.setMaxTotal(maxTotal);
         pool.setMaxIdle(-1);
         pool.setTestOnReturn(true);
@@ -1262,15 +1223,6 @@ public class TestGenericObjectPool exten
         pool.returnObject(obj);
         assertEquals("should be one idle", 1, pool.getNumIdle());
         assertEquals("should be zero active", 0, pool.getNumActive());
-
-        ObjectPool<Object> op = new GenericObjectPool<Object>();
-        try {
-            op.addObject();
-            fail("Expected IllegalStateException when there is no factory.");
-        } catch (IllegalStateException ise) {
-            //expected
-        }
-        op.close();
     }
     
     protected GenericObjectPool<Object> pool = null;
@@ -1518,10 +1470,9 @@ public class TestGenericObjectPool exten
     public void testBrokenFactoryShouldNotBlockPool() {
         int maxTotal = 1;
         
-        GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
         SimpleFactory factory = new SimpleFactory();
         factory.setMaxTotal(maxTotal);
-        pool.setFactory(factory);
+        GenericObjectPool<Object> pool = new GenericObjectPool<Object>(factory);
         pool.setMaxTotal(maxTotal);
         pool.setWhenExhaustedAction(WhenExhaustedAction.BLOCK);
         pool.setTestOnBorrow(true);
@@ -1618,8 +1569,7 @@ public class TestGenericObjectPool exten
         final long holdTime = 2 * maxWait; // how long to hold connection
         final int threads = 10; // number of threads to grab the object initially
         SimpleFactory factory = new SimpleFactory();
-        GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-        pool.setFactory(factory);
+        GenericObjectPool<Object> pool = new GenericObjectPool<Object>(factory);
         pool.setWhenExhaustedAction(WhenExhaustedAction.BLOCK);
         pool.setMaxWait(maxWait);
         pool.setMaxTotal(threads);
@@ -1672,8 +1622,7 @@ public class TestGenericObjectPool exten
     @Test
     public void testMakeConcurrentWithReturn() throws Exception {
         SimpleFactory factory = new SimpleFactory();
-        GenericObjectPool<Object> pool = new GenericObjectPool<Object>(); 
-        pool.setFactory(factory);
+        GenericObjectPool<Object> pool = new GenericObjectPool<Object>(factory);

         pool.setTestOnBorrow(true);
         factory.setValid(true);
         // Borrow and return an instance, with a short wait

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPoolFactory.java?rev=1139666&r1=1139665&r2=1139666&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPoolFactory.java
(original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPoolFactory.java
Sat Jun 25 23:25:49 2011
@@ -42,8 +42,7 @@ public class TestGenericObjectPoolFactor
         
         GenericObjectPoolConfig<Object> config =
             new GenericObjectPoolConfig<Object>();
-        config.setFactory(objectFactory);
-        return new GenericObjectPoolFactory<Object>(config);
+        return new GenericObjectPoolFactory<Object>(objectFactory, config);
     }
 
     @Test
@@ -63,10 +62,10 @@ public class TestGenericObjectPoolFactor
         config.setLifo(false);
         config.setTimeBetweenEvictionRunsMillis(8);
         config.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
-        config.setFactory(new MethodCallPoolableObjectFactory());
 
         GenericObjectPoolFactory<Object> factory =
-            new GenericObjectPoolFactory<Object>(config);
+            new GenericObjectPoolFactory<Object>(
+                    new MethodCallPoolableObjectFactory(), config);
         GenericObjectPool<Object> pool =
             (GenericObjectPool<Object>) factory.createPool();
 

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool2/performance/PerformanceTest.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/performance/PerformanceTest.java?rev=1139666&r1=1139665&r2=1139666&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool2/performance/PerformanceTest.java
(original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool2/performance/PerformanceTest.java
Sat Jun 25 23:25:49 2011
@@ -111,8 +111,7 @@ public class PerformanceTest {
         
         SleepingObjectFactory factory = new SleepingObjectFactory();
         if (logLevel >= 4) { factory.setDebug(true); } 
-        pool = new GenericObjectPool<Integer>();
-        pool.setFactory(factory);
+        pool = new GenericObjectPool<Integer>(factory);
         pool.setMaxTotal(maxTotal);
         pool.setMaxIdle(maxIdle);
         pool.setTestOnBorrow(true);



Mime
View raw message