commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sandy...@apache.org
Subject svn commit: r390349 - in /jakarta/commons/proper/pool/trunk/src: java/org/apache/commons/pool/composite/ test/org/apache/commons/pool/ test/org/apache/commons/pool/composite/ test/org/apache/commons/pool/impl/
Date Fri, 31 Mar 2006 06:59:56 GMT
Author: sandymac
Date: Thu Mar 30 22:59:54 2006
New Revision: 390349

URL: http://svn.apache.org/viewcvs?rev=390349&view=rev
Log:
Created unit tests for ObjectPoolFactory and implementations.

Added:
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPoolFactory.java
  (with props)
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeObjectPoolFactory.java
  (with props)
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPoolFactory.java
  (with props)
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java
  (with props)
Modified:
    jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/composite/CompositeKeyedObjectPoolFactory.java
    jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/composite/CompositeObjectPoolFactory.java
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/PerformanceTest.java
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestAll.java
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestIdleEvictorLender.java
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestAll.java

Modified: jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/composite/CompositeKeyedObjectPoolFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/composite/CompositeKeyedObjectPoolFactory.java?rev=390349&r1=390348&r2=390349&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/composite/CompositeKeyedObjectPoolFactory.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/composite/CompositeKeyedObjectPoolFactory.java
Thu Mar 30 22:59:54 2006
@@ -334,11 +334,11 @@
     /**
      * Set the type of tracking for active objects while they are borrowed from the pool.
      *
-     * @param trackerPolicy type of tracking for active objects.
-     * @throws IllegalArgumentException when <code>trackerPolicy</code> is <code>null</code>.
+     * @param trackingPolicy type of tracking for active objects.
+     * @throws IllegalArgumentException when <code>trackingPolicy</code> is <code>null</code>.
      */
-    public void setTrackingPolicy(final TrackingPolicy trackerPolicy) throws IllegalArgumentException
{
-        factory.setTrackingPolicy(trackerPolicy);
+    public void setTrackingPolicy(final TrackingPolicy trackingPolicy) throws IllegalArgumentException
{
+        factory.setTrackingPolicy(trackingPolicy);
     }
 
     /**

Modified: jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/composite/CompositeObjectPoolFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/composite/CompositeObjectPoolFactory.java?rev=390349&r1=390348&r2=390349&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/composite/CompositeObjectPoolFactory.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/composite/CompositeObjectPoolFactory.java
Thu Mar 30 22:59:54 2006
@@ -198,7 +198,7 @@
     /**
      * Configured {@link Tracker} type.
      */
-    private TrackingPolicy trackerPolicy = TrackingPolicy.SIMPLE;
+    private TrackingPolicy trackingPolicy = TrackingPolicy.SIMPLE;
 
     /**
      * Should the object pool validate borrowed objects when they are returned.
@@ -352,7 +352,7 @@
 
         final int maxActive = config.maxActive;
         if (maxActive > 0) {
-            if (TrackingPolicy.NULL.equals(config.trackerPolicy)) {
+            if (TrackingPolicy.NULL.equals(config.trackingPolicy)) {
                 throw new IllegalStateException("Using the NULL tracker and limiting pool
size is not valid.");
             }
             final LimitPolicy limitPolicy = config.limitPolicy;
@@ -382,17 +382,17 @@
      */
     private static Tracker getTracker(final FactoryConfig config) {
         final Tracker tracker;
-        final TrackingPolicy trackerPolicy = config.trackerPolicy;
-        if (TrackingPolicy.SIMPLE.equals(trackerPolicy)) {
+        final TrackingPolicy trackingPolicy = config.trackingPolicy;
+        if (TrackingPolicy.SIMPLE.equals(trackingPolicy)) {
             tracker = new SimpleTracker();
-        } else if (TrackingPolicy.NULL.equals(trackerPolicy)) {
+        } else if (TrackingPolicy.NULL.equals(trackingPolicy)) {
             tracker = new NullTracker();
-        } else if (TrackingPolicy.REFERENCE.equals(trackerPolicy)) {
+        } else if (TrackingPolicy.REFERENCE.equals(trackingPolicy)) {
             tracker = new ReferenceTracker();
-        } else if (TrackingPolicy.DEBUG.equals(trackerPolicy)) {
+        } else if (TrackingPolicy.DEBUG.equals(trackingPolicy)) {
             tracker = new DebugTracker();
         } else {
-            throw new IllegalStateException("No clue what this tracking type is: " + trackerPolicy);
+            throw new IllegalStateException("No clue what this tracking type is: " + trackingPolicy);
         }
         return tracker;
     }
@@ -596,22 +596,22 @@
      * @return Type of tracking for active objects while they are borrowed from the pool.
      */
     public TrackingPolicy getTrackingPolicy() {
-        return trackerPolicy;
+        return trackingPolicy;
     }
 
     /**
      * Set the type of tracking for active objects while they are borrowed from the pool.
      *
-     * @param trackerPolicy type of tracking for active objects.
-     * @throws IllegalArgumentException when <code>trackerPolicy</code> is <code>null</code>.
+     * @param trackingPolicy type of tracking for active objects.
+     * @throws IllegalArgumentException when <code>trackingPolicy</code> is <code>null</code>.
      */
-    public void setTrackingPolicy(final TrackingPolicy trackerPolicy) throws IllegalArgumentException
{
-        if (trackerPolicy == null) {
+    public void setTrackingPolicy(final TrackingPolicy trackingPolicy) throws IllegalArgumentException
{
+        if (trackingPolicy == null) {
             throw new IllegalArgumentException("tracker type must not be null.");
         }
         synchronized (lock){
             config = null;
-            this.trackerPolicy = trackerPolicy;
+            this.trackingPolicy = trackingPolicy;
         }
     }
 
@@ -740,8 +740,8 @@
         /** @see CompositeObjectPoolFactory#maxWaitMillis */
         private final int maxWaitMillis;
 
-        /** @see CompositeObjectPoolFactory#trackerPolicy */
-        private final TrackingPolicy trackerPolicy;
+        /** @see CompositeObjectPoolFactory#trackingPolicy */
+        private final TrackingPolicy trackingPolicy;
 
         /** @see CompositeObjectPoolFactory#validateOnReturn */
         private final boolean validateOnReturn;
@@ -763,7 +763,7 @@
 
         FactoryConfig(final PoolableObjectFactory factory, final BorrowPolicy borrowPolicy,
                       final ExhaustionPolicy exhaustionPolicy, final int maxIdle, final int
maxActive,
-                      final LimitPolicy limitPolicy, final int maxWaitMillis, final TrackingPolicy
trackerPolicy,
+                      final LimitPolicy limitPolicy, final int maxWaitMillis, final TrackingPolicy
trackingPolicy,
                       final boolean validateOnReturn, final long evictIdleMillis,
                       final long evictInvalidFrequencyMillis) {
             this.factory = factory;
@@ -773,7 +773,7 @@
             this.maxActive = maxActive;
             this.limitPolicy = limitPolicy;
             this.maxWaitMillis = maxWaitMillis;
-            this.trackerPolicy = trackerPolicy;
+            this.trackingPolicy = trackingPolicy;
             this.validateOnReturn = validateOnReturn;
             this.evictIdleMillis = evictIdleMillis;
             this.evictInvalidFrequencyMillis = evictInvalidFrequencyMillis;
@@ -793,7 +793,7 @@
                     sb.append(", maxWaitMillis=").append(maxWaitMillis);
                 }
             }
-            sb.append(", trackerPolicy=").append(trackerPolicy);
+            sb.append(", trackingPolicy=").append(trackingPolicy);
             sb.append(", validateOnReturn=").append(validateOnReturn);
             if (evictIdleMillis > 0) {
                 sb.append(", evictIdleMillis=").append(evictIdleMillis);

Added: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPoolFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPoolFactory.java?rev=390349&view=auto
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPoolFactory.java
(added)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPoolFactory.java
Thu Mar 30 22:59:54 2006
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.pool;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for all {@link ObjectPoolFactory}.
+ *
+ * @author Sandy McArthur
+ * @version $Revision$ $Date$
+ */
+public abstract class TestObjectPoolFactory extends TestCase {
+    protected TestObjectPoolFactory(final String name) {
+        super(name);
+    }
+
+    /**
+     * @throws UnsupportedOperationException when this is unsupported by this PoolableObjectFactory
type.
+     */
+    protected ObjectPoolFactory makeFactory() throws UnsupportedOperationException {
+        return makeFactory(new MethodCallPoolableObjectFactory());
+    }
+
+    /**
+     * @throws UnsupportedOperationException when this is unsupported by this PoolableObjectFactory
type.
+     */
+    protected abstract ObjectPoolFactory makeFactory(PoolableObjectFactory objectFactory)
throws UnsupportedOperationException;
+
+    public void testCreatePool() throws Exception {
+        final ObjectPoolFactory factory;
+        try {
+            factory = makeFactory();
+        } catch (UnsupportedOperationException uoe) {
+            return;
+        }
+        final ObjectPool pool = factory.createPool();
+        pool.close();
+    }
+
+    public void testToString() {
+        final ObjectPoolFactory factory;
+        try {
+            factory = makeFactory();
+        } catch (UnsupportedOperationException uoe) {
+            return;
+        }
+        factory.toString();
+    }
+}

Propchange: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPoolFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPoolFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/PerformanceTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/PerformanceTest.java?rev=390349&r1=390348&r2=390349&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/PerformanceTest.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/PerformanceTest.java
Thu Mar 30 22:59:54 2006
@@ -101,7 +101,7 @@
                 }
                 poolFactory.setLimitPolicy((LimitPolicy)limitIter.next());
             }
-            poolFactory.setTrackerType((TrackingPolicy)trackingIter.next());
+            poolFactory.setTrackingPolicy((TrackingPolicy)trackingIter.next());
         }
         poolFactory.setValidateOnReturn(((Boolean)validateIter.next()).booleanValue());
 
@@ -496,7 +496,7 @@
             compositeFactory.setBorrowPolicy(BorrowPolicy.FIFO);
             compositeFactory.setExhaustionPolicy(ExhaustionPolicy.GROW);
             compositeFactory.setLimitPolicy(LimitPolicy.FAIL);
-            compositeFactory.setTrackerType(TrackingPolicy.SIMPLE);
+            compositeFactory.setTrackingPolicy(TrackingPolicy.SIMPLE);
 
             genericConfig.minIdle = 0;
             genericConfig.testOnBorrow = true;

Modified: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestAll.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestAll.java?rev=390349&r1=390348&r2=390349&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestAll.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestAll.java
Thu Mar 30 22:59:54 2006
@@ -64,7 +64,7 @@
         suite.addTest(TestCompositeObjectPool.suite());
         suite.addTest(TestCompositeKeyedObjectPool.suite());
         suite.addTest(TestCompositeKeyedObjectPool2.suite());
-        //suite.addTest(TestCompositeObjectPoolFactory.suite());
+        suite.addTest(TestCompositeObjectPoolFactory.suite());
         //suite.addTest(TestCompositeKeyedObjectPoolFactory.suite());
         return suite;
     }

Added: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeObjectPoolFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeObjectPoolFactory.java?rev=390349&view=auto
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeObjectPoolFactory.java
(added)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeObjectPoolFactory.java
Thu Mar 30 22:59:54 2006
@@ -0,0 +1,348 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.pool.composite;
+
+import org.apache.commons.pool.TestObjectPoolFactory;
+import org.apache.commons.pool.ObjectPoolFactory;
+import org.apache.commons.pool.PoolableObjectFactory;
+import org.apache.commons.pool.ObjectPool;
+import org.apache.commons.pool.MethodCallPoolableObjectFactory;
+import org.apache.commons.pool.BasePoolableObjectFactory;
+import org.apache.commons.pool.MethodCall;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import java.util.NoSuchElementException;
+import java.util.List;
+import java.util.LinkedList;
+import java.util.ArrayList;
+
+/**
+ * Tests for {@link CompositeObjectPoolFactory}.
+ *
+ * @author Sandy McArthur
+ * @version $Revision$ $Date$
+ */
+public class TestCompositeObjectPoolFactory extends TestObjectPoolFactory {
+    private static final long FUZZ = 5L;
+
+    public TestCompositeObjectPoolFactory(final String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestCompositeObjectPoolFactory.class);
+    }
+
+    protected ObjectPoolFactory makeFactory(final PoolableObjectFactory objectFactory) throws
UnsupportedOperationException {
+        return new CompositeObjectPoolFactory(objectFactory);
+    }
+
+    public void testCreatePoolWithNullConfig() {
+        try {
+            CompositeObjectPoolFactory.createPool(null);
+            fail("Expected an IllegalArgumentException when factory config is null.");
+        } catch (IllegalArgumentException iae) {
+            // expected
+        }
+    }
+
+    public void testBorrowPolicyNull() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        copf.setBorrowPolicy(BorrowPolicy.NULL);
+
+        final ObjectPool pool = copf.createPool();
+
+        Object a = pool.borrowObject();
+        pool.returnObject(a);
+        Object b = pool.borrowObject();
+        assertNotSame("BorrowPolicy.NULL should not return previously borrowed objects.",
a, b);
+    }
+
+    public void testBorrowPolicyNullWithExhaustionFail() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        copf.setBorrowPolicy(BorrowPolicy.NULL);
+        copf.setExhaustionPolicy(ExhaustionPolicy.FAIL);
+
+        try {
+            copf.createPool();
+            fail("Cannot create a pool with both BorrowPolicy.NULL and ExhaustionPolicy.FAIL.");
+        } catch (IllegalStateException ise) {
+            // expected
+        }
+    }
+
+    public void testBorrowPolicyFifo() throws Exception {
+        testBorrowPolicyFifo(BorrowPolicy.FIFO);
+    }
+
+    public void testBorrowPolicySoftFifo() throws Exception {
+        testBorrowPolicyFifo(BorrowPolicy.SOFT_FIFO);
+    }
+
+    private void testBorrowPolicyFifo(final BorrowPolicy policy) throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        copf.setBorrowPolicy(policy);
+
+        final ObjectPool pool = copf.createPool();
+
+        Object a = pool.borrowObject();
+        Object b = pool.borrowObject();
+        pool.returnObject(a);
+        pool.returnObject(b);
+        Object aa = pool.borrowObject();
+        Object bb = pool.borrowObject();
+        assertSame(a, aa);
+        assertSame(b, bb);
+    }
+
+    public void testBorrowPolicyLifo() throws Exception {
+        testBorrowPolicyLifo(BorrowPolicy.LIFO);
+    }
+
+    public void testBorrowPolicySoftLifo() throws Exception {
+        testBorrowPolicyLifo(BorrowPolicy.SOFT_LIFO);
+    }
+
+    private void testBorrowPolicyLifo(final BorrowPolicy policy) throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        copf.setBorrowPolicy(policy);
+
+        final ObjectPool pool = copf.createPool();
+
+        Object a = pool.borrowObject();
+        Object b = pool.borrowObject();
+        pool.returnObject(a);
+        pool.returnObject(b);
+        Object aa = pool.borrowObject();
+        Object bb = pool.borrowObject();
+        assertSame(a, bb);
+        assertSame(b, aa);
+    }
+
+    public void testExhaustionPolicyFail() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        copf.setExhaustionPolicy(ExhaustionPolicy.FAIL);
+        final ObjectPool pool = copf.createPool();
+
+        try {
+            pool.borrowObject();
+            fail("new pools should be empty and fail with ExhaustionPolicy.FAIL.");
+        } catch (NoSuchElementException nsee) {
+            // expected
+        }
+
+        pool.addObject();
+        pool.borrowObject();
+    }
+
+    public void testExhaustionPolicyGrow() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        copf.setExhaustionPolicy(ExhaustionPolicy.GROW);
+        final ObjectPool pool = copf.createPool();
+
+        assertEquals(0, pool.getNumIdle());
+        pool.borrowObject();
+    }
+
+    public void testLimitPolicyFail() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        copf.setMaxActive(1);
+        copf.setLimitPolicy(LimitPolicy.FAIL);
+        copf.setMaxWaitMillis(1000);
+        final ObjectPool pool = copf.createPool();
+
+        Object a = pool.borrowObject();
+        long startTime = System.currentTimeMillis();
+        try {
+            pool.borrowObject();
+            fail();
+        } catch (NoSuchElementException nsee) {
+            // expected
+        }
+        assertTrue("borrowObject shouldn't take long to fail.", startTime + 1000 - FUZZ >
System.currentTimeMillis());
+
+        pool.returnObject(a);
+        pool.borrowObject();
+    }
+
+    public void testLimitPolicyWait() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        copf.setMaxActive(1);
+        copf.setLimitPolicy(LimitPolicy.WAIT);
+        copf.setMaxWaitMillis(1000);
+        final ObjectPool pool = copf.createPool();
+
+        Object a = pool.borrowObject();
+        long startTime = System.currentTimeMillis();
+        try {
+            pool.borrowObject();
+            fail();
+        } catch (NoSuchElementException nsee) {
+            // expected
+        }
+        assertTrue("borrowObject shouldn't take a while to fail.", startTime + 1000 - FUZZ
< System.currentTimeMillis());
+
+        pool.returnObject(a);
+        pool.borrowObject();
+    }
+
+    public void testTrackingPolicyNull() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        copf.setTrackingPolicy(TrackingPolicy.NULL);
+        final ObjectPool pool = copf.createPool();
+
+        assertTrue(pool.getNumActive() < 0);
+        Object a = pool.borrowObject();
+        assertTrue(pool.getNumActive() < 0);
+        pool.returnObject(a);
+        assertTrue(pool.getNumActive() < 0);
+    }
+
+    public void testTrackingPolicySimple() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        copf.setTrackingPolicy(TrackingPolicy.SIMPLE);
+        final ObjectPool pool = copf.createPool();
+
+        assertEquals(0, pool.getNumActive());
+        Object a = pool.borrowObject();
+        assertEquals(1, pool.getNumActive());
+        pool.returnObject(a);
+        assertEquals(0, pool.getNumActive());
+    }
+
+    public void testTrackingPolicyReference() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory(new
BasePoolableObjectFactory() {
+            public Object makeObject() throws Exception {
+                return new Object();
+            }
+        });
+        copf.setTrackingPolicy(TrackingPolicy.REFERENCE);
+        final ObjectPool pool = copf.createPool();
+
+        assertEquals(0, pool.getNumActive());
+        Object a = pool.borrowObject();
+        assertEquals(1, pool.getNumActive());
+        a = null;
+        List garbage = new LinkedList();
+        Runtime runtime = Runtime.getRuntime();
+        while (pool.getNumActive() > 0) {
+            try {
+                garbage.add(new byte[Math.min(1024 * 1024, (int)runtime.freeMemory()/2)]);
+            } catch (OutOfMemoryError oome) {
+                System.gc();
+            }
+            System.gc();
+        }
+        garbage.clear();
+        System.gc();
+        assertEquals(0, pool.getNumActive());
+    }
+
+    public void testTrackingPolicyDebug() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory(new
BasePoolableObjectFactory() {
+            public Object makeObject() throws Exception {
+                return new Object();
+            }
+        });
+        copf.setTrackingPolicy(TrackingPolicy.DEBUG);
+        final ObjectPool pool = copf.createPool();
+
+        assertEquals(0, pool.getNumActive());
+        Object a = pool.borrowObject();
+        assertEquals(1, pool.getNumActive());
+        a = null;
+        List garbage = new LinkedList();
+        Runtime runtime = Runtime.getRuntime();
+        while (pool.getNumActive() > 0) {
+            try {
+                garbage.add(new byte[Math.min(1024 * 1024, (int)runtime.freeMemory()/2)]);
+            } catch (OutOfMemoryError oome) {
+                System.gc();
+            }
+            System.gc();
+        }
+        garbage.clear();
+        System.gc();
+        assertEquals(0, pool.getNumActive());
+    }
+
+    public void testMaxIdle() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        copf.setMaxIdle(5);
+        final ObjectPool pool = copf.createPool();
+
+        for (int i=1; i<10; i++) {
+            pool.addObject();
+            assertEquals(Math.min(5, i), pool.getNumIdle());
+        }
+    }
+
+    public void testValidateOnReturn() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        copf.setValidateOnReturn(true);
+        final CompositeObjectPool pool = (CompositeObjectPool)copf.createPool();
+        final MethodCallPoolableObjectFactory factory = (MethodCallPoolableObjectFactory)pool.getFactory();
+
+        final Object a = pool.borrowObject();
+        factory.getMethodCalls().clear();
+        pool.returnObject(a);
+
+        final List expectedMethods = new ArrayList();
+        expectedMethods.add(new MethodCall("validateObject", a).returned(Boolean.TRUE));
+        expectedMethods.add(new MethodCall("passivateObject", a));
+        assertEquals(expectedMethods, factory.getMethodCalls());
+    }
+
+    public void testEvictIdleMillis() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        copf.setEvictIdleMillis(50L);
+        final ObjectPool pool = copf.createPool();
+
+        pool.addObject();
+        Thread.sleep(75L);
+        assertEquals(0, pool.getNumIdle());
+    }
+
+    public void testEvictInvalidFrequencyMillis() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        copf.setEvictInvalidFrequencyMillis(50L);
+        final CompositeObjectPool pool = (CompositeObjectPool)copf.createPool();
+        final MethodCallPoolableObjectFactory factory = (MethodCallPoolableObjectFactory)pool.getFactory();
+
+        pool.addObject();
+        Thread.sleep(75L);
+        assertEquals(1, pool.getNumIdle());
+        factory.setValid(false);
+        Thread.sleep(75L);
+        assertEquals(0, pool.getNumIdle());
+    }
+
+    public void testToString() {
+        super.testToString();
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        copf.toString();
+        copf.setMaxActive(1);
+        copf.toString();
+        copf.setLimitPolicy(LimitPolicy.WAIT);
+        copf.toString();
+        copf.setEvictIdleMillis(1);
+        copf.toString();
+        copf.setEvictInvalidFrequencyMillis(1);
+        copf.toString();
+    }
+}

Propchange: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeObjectPoolFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeObjectPoolFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestIdleEvictorLender.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestIdleEvictorLender.java?rev=390349&r1=390348&r2=390349&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestIdleEvictorLender.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestIdleEvictorLender.java
Thu Mar 30 22:59:54 2006
@@ -53,7 +53,7 @@
     }
 
     public void testIdleEviction() throws Exception {
-        IdleEvictorLender lender = createLender(50L);
+        IdleEvictorLender lender = createLender(75L);
         CompositeObjectPool cop = createPool(lender);
 
         cop.addObject();
@@ -65,7 +65,7 @@
 
         // Test when IdleEvictorLender delegates to another EvictorLender
         lender = new IdleEvictorLender(new InvalidEvictorLender(new FifoLender()));
-        lender.setIdleTimeoutMillis(50L);
+        lender.setIdleTimeoutMillis(75L);
         cop = createPool(lender);
 
         cop.addObject();
@@ -77,7 +77,7 @@
 
         // Test when another EvictorLender delegates to IdleEvictorLender
         lender = new IdleEvictorLender(new FifoLender());
-        lender.setIdleTimeoutMillis(50L);
+        lender.setIdleTimeoutMillis(75L);
         cop = createPool(new InvalidEvictorLender(lender));
 
         cop.addObject();

Modified: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestAll.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestAll.java?rev=390349&r1=390348&r2=390349&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestAll.java (original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestAll.java Thu
Mar 30 22:59:54 2006
@@ -39,7 +39,11 @@
         suite.addTest(TestGenericObjectPool.suite());
         suite.addTest(TestGenericKeyedObjectPool.suite());
         suite.addTest(TestSoftReferenceObjectPool.suite());
-        suite.addTest(TestSoftRefOutOfMemory.suite()); // isn't reliable
+        suite.addTest(TestSoftRefOutOfMemory.suite()); // isn't reliable?
+
+        // Pool Factory tests
+        suite.addTest(TestGenericObjectPoolFactory.suite());
+        suite.addTest(TestStackObjectPoolFactory.suite());
         return suite;
     }
 

Added: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPoolFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPoolFactory.java?rev=390349&view=auto
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPoolFactory.java
(added)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPoolFactory.java
Thu Mar 30 22:59:54 2006
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.pool.impl;
+
+import org.apache.commons.pool.TestObjectPoolFactory;
+import org.apache.commons.pool.ObjectPoolFactory;
+import org.apache.commons.pool.PoolableObjectFactory;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Tests for {@link GenericObjectPoolFactory}.
+ *
+ * @author Sandy McArthur
+ * @version $Revision$ $Date$
+ */
+public class TestGenericObjectPoolFactory extends TestObjectPoolFactory {
+    public TestGenericObjectPoolFactory(final String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestGenericObjectPoolFactory.class);
+    }
+
+    protected ObjectPoolFactory makeFactory(final PoolableObjectFactory objectFactory) throws
UnsupportedOperationException {
+        return new GenericObjectPoolFactory(objectFactory);
+    }
+}

Propchange: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPoolFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPoolFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java?rev=390349&view=auto
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java
(added)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java
Thu Mar 30 22:59:54 2006
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.pool.impl;
+
+import org.apache.commons.pool.TestObjectPoolFactory;
+import org.apache.commons.pool.ObjectPoolFactory;
+import org.apache.commons.pool.PoolableObjectFactory;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Tests for {@link StackObjectPoolFactory}.
+ *
+ * @author Sandy McArthur
+ * @version $Revision$ $Date$
+ */
+public class TestStackObjectPoolFactory extends TestObjectPoolFactory {
+    public TestStackObjectPoolFactory(final String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestStackObjectPoolFactory.class);
+    }
+
+    protected ObjectPoolFactory makeFactory(final PoolableObjectFactory objectFactory) throws
UnsupportedOperationException {
+        return new StackObjectPoolFactory(objectFactory);
+    }
+}

Propchange: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message