You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sa...@apache.org on 2006/04/02 09:15:33 UTC

svn commit: r390793 - in /jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool: ./ composite/ impl/

Author: sandymac
Date: Sat Apr  1 23:15:31 2006
New Revision: 390793

URL: http://svn.apache.org/viewcvs?rev=390793&view=rev
Log:
Unit tests for KeyedObjectPoolFactory implementations.

Added:
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPoolFactory.java   (with props)
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeKeyedObjectPoolFactory.java   (with props)
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPoolFactory.java   (with props)
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPoolFactory.java   (with props)
Modified:
    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/impl/TestAll.java

Added: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPoolFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPoolFactory.java?rev=390793&view=auto
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPoolFactory.java (added)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPoolFactory.java Sat Apr  1 23:15:31 2006
@@ -0,0 +1,68 @@
+/*
+ * 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;
+
+/**
+ * Tests for all {@link KeyedObjectPoolFactory}s.
+ *
+ * @author Sandy McArthur
+ * @version $Revision$ $Date$
+ */
+public abstract class TestKeyedObjectPoolFactory extends TestCase {
+    protected TestKeyedObjectPoolFactory(final String name) {
+        super(name);
+    }
+
+    /**
+     * @throws UnsupportedOperationException when this is unsupported by this KeyedPoolableObjectFactory type.
+     */
+    protected KeyedObjectPoolFactory makeFactory() throws UnsupportedOperationException {
+        return makeFactory(createObjectFactory());
+    }
+
+    /**
+     * @throws UnsupportedOperationException when this is unsupported by this KeyedPoolableObjectFactory type.
+     */
+    protected abstract KeyedObjectPoolFactory makeFactory(KeyedPoolableObjectFactory objectFactory) throws UnsupportedOperationException;
+
+    protected static KeyedPoolableObjectFactory createObjectFactory() {
+        return PoolUtils.adapt(new MethodCallPoolableObjectFactory());
+    }
+
+    public void testCreatePool() throws Exception {
+        final KeyedObjectPoolFactory factory;
+        try {
+            factory = makeFactory();
+        } catch (UnsupportedOperationException uoe) {
+            return;
+        }
+        final KeyedObjectPool pool = factory.createPool();
+        pool.close();
+    }
+
+    public void testToString() {
+        final KeyedObjectPoolFactory factory;
+        try {
+            factory = makeFactory();
+        } catch (UnsupportedOperationException uoe) {
+            return;
+        }
+        factory.toString();
+    }
+}

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

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

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=390793&r1=390792&r2=390793&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 Sat Apr  1 23:15:31 2006
@@ -65,7 +65,7 @@
         suite.addTest(TestCompositeKeyedObjectPool.suite());
         suite.addTest(TestCompositeKeyedObjectPool2.suite());
         suite.addTest(TestCompositeObjectPoolFactory.suite());
-        //suite.addTest(TestCompositeKeyedObjectPoolFactory.suite());
+        suite.addTest(TestCompositeKeyedObjectPoolFactory.suite());
         return suite;
     }
 

Added: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeKeyedObjectPoolFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeKeyedObjectPoolFactory.java?rev=390793&view=auto
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeKeyedObjectPoolFactory.java (added)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeKeyedObjectPoolFactory.java Sat Apr  1 23:15:31 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.composite;
+
+import org.apache.commons.pool.TestKeyedObjectPoolFactory;
+import org.apache.commons.pool.KeyedObjectPoolFactory;
+import org.apache.commons.pool.KeyedPoolableObjectFactory;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Tests for {@link CompositeKeyedObjectPoolFactory}.
+ *
+ * @author Sandy McArthur
+ * @version $Revision$ $Date$
+ */
+public class TestCompositeKeyedObjectPoolFactory extends TestKeyedObjectPoolFactory {
+    public TestCompositeKeyedObjectPoolFactory(final String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestCompositeKeyedObjectPoolFactory.class);
+    }
+
+    protected KeyedObjectPoolFactory makeFactory(final KeyedPoolableObjectFactory objectFactory) throws UnsupportedOperationException {
+        return new CompositeKeyedObjectPoolFactory(objectFactory);
+    }
+}

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

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

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=390793&r1=390792&r2=390793&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 Sat Apr  1 23:15:31 2006
@@ -44,6 +44,8 @@
         // Pool Factory tests
         suite.addTest(TestGenericObjectPoolFactory.suite());
         suite.addTest(TestStackObjectPoolFactory.suite());
+        suite.addTest(TestGenericKeyedObjectPoolFactory.suite());
+        suite.addTest(TestStackKeyedObjectPoolFactory.suite());
         return suite;
     }
 

Added: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPoolFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPoolFactory.java?rev=390793&view=auto
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPoolFactory.java (added)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPoolFactory.java Sat Apr  1 23:15:31 2006
@@ -0,0 +1,165 @@
+/*
+ * 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.TestKeyedObjectPoolFactory;
+import org.apache.commons.pool.KeyedObjectPoolFactory;
+import org.apache.commons.pool.KeyedPoolableObjectFactory;
+import org.apache.commons.pool.MethodCallPoolableObjectFactory;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import java.util.NoSuchElementException;
+
+/**
+ * Tests for {@link GenericKeyedObjectPoolFactory}.
+ *
+ * @author Sandy McArthur
+ * @version $Revision$ $Date$
+ */
+public class TestGenericKeyedObjectPoolFactory extends TestKeyedObjectPoolFactory {
+    public TestGenericKeyedObjectPoolFactory(final String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestGenericKeyedObjectPoolFactory.class);
+    }
+
+    protected KeyedObjectPoolFactory makeFactory(final KeyedPoolableObjectFactory objectFactory) {
+        return new GenericKeyedObjectPoolFactory(objectFactory);
+    }
+
+    public void testConstructors() throws Exception {
+        GenericKeyedObjectPoolFactory factory = new GenericKeyedObjectPoolFactory(createObjectFactory());
+        factory.createPool().close();
+        GenericKeyedObjectPool pool;
+
+
+        final GenericKeyedObjectPool.Config config = new GenericKeyedObjectPool.Config();
+        config.maxActive = 1;
+        config.maxIdle = 2;
+        config.maxWait = 3;
+        config.minIdle = 4;
+        config.minEvictableIdleTimeMillis = 5;
+        config.numTestsPerEvictionRun = 6;
+        config.testOnBorrow = true;
+        config.testOnReturn = false;
+        config.testWhileIdle = true;
+        config.timeBetweenEvictionRunsMillis = 8;
+        config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
+        factory = new GenericKeyedObjectPoolFactory(createObjectFactory(), config);
+        pool = (GenericKeyedObjectPool)factory.createPool();
+        assertEquals(1, pool.getMaxActive());
+        assertEquals(2, pool.getMaxIdle());
+        assertEquals(3, pool.getMaxWait());
+        assertEquals(4, pool.getMinIdle());
+        assertEquals(5, pool.getMinEvictableIdleTimeMillis());
+        assertEquals(6, pool.getNumTestsPerEvictionRun());
+        assertEquals(true, pool.getTestOnBorrow());
+        assertEquals(false, pool.getTestOnReturn());
+        assertEquals(true, pool.getTestWhileIdle());
+        assertEquals(8, pool.getTimeBetweenEvictionRunsMillis());
+        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
+        pool.close();
+
+
+        factory = new GenericKeyedObjectPoolFactory(createObjectFactory(), 1);
+        pool = (GenericKeyedObjectPool)factory.createPool();
+        assertEquals(1, pool.getMaxActive());
+        pool.close();
+
+
+        factory = new GenericKeyedObjectPoolFactory(createObjectFactory(), 1, GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK, 125);
+        pool = (GenericKeyedObjectPool)factory.createPool();
+        assertEquals(1, pool.getMaxActive());
+        assertEquals(GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK, pool.getWhenExhaustedAction());
+        assertEquals(125, pool.getMaxWait());
+        pool.close();
+
+
+        factory = new GenericKeyedObjectPoolFactory(createObjectFactory(), 1, GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 2, true, false);
+        pool = (GenericKeyedObjectPool)factory.createPool();
+        assertEquals(1, pool.getMaxActive());
+        assertEquals(2, pool.getMaxWait());
+        assertEquals(true, pool.getTestOnBorrow());
+        assertEquals(false, pool.getTestOnReturn());
+        assertEquals(GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
+        pool.close();
+
+
+        factory = new GenericKeyedObjectPoolFactory(createObjectFactory(), 1, GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 2, 3);
+        pool = (GenericKeyedObjectPool)factory.createPool();
+        assertEquals(1, pool.getMaxActive());
+        assertEquals(2, pool.getMaxWait());
+        assertEquals(3, pool.getMaxIdle());
+        assertEquals(GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
+        pool.close();
+
+
+        factory = new GenericKeyedObjectPoolFactory(createObjectFactory(), 1, GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 2, 3, 4);
+        pool = (GenericKeyedObjectPool)factory.createPool();
+        assertEquals(1, pool.getMaxActive());
+        assertEquals(2, pool.getMaxWait());
+        assertEquals(3, pool.getMaxIdle());
+        assertEquals(4, pool.getMaxTotal());
+        assertEquals(GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
+        pool.close();
+
+
+        factory = new GenericKeyedObjectPoolFactory(createObjectFactory(), 1, GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 2, 3, true, false);
+        pool = (GenericKeyedObjectPool)factory.createPool();
+        assertEquals(1, pool.getMaxActive());
+        assertEquals(2, pool.getMaxWait());
+        assertEquals(3, pool.getMaxIdle());
+        assertEquals(true, pool.getTestOnBorrow());
+        assertEquals(false, pool.getTestOnReturn());
+        assertEquals(GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
+        pool.close();
+
+
+        factory = new GenericKeyedObjectPoolFactory(createObjectFactory(), 1, GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 2, 3, true, false, 4, 5, 6, false);
+        pool = (GenericKeyedObjectPool)factory.createPool();
+        assertEquals(1, pool.getMaxActive());
+        assertEquals(2, pool.getMaxWait());
+        assertEquals(3, pool.getMaxIdle());
+        assertEquals(4, pool.getTimeBetweenEvictionRunsMillis());
+        assertEquals(5, pool.getNumTestsPerEvictionRun());
+        assertEquals(6, pool.getMinEvictableIdleTimeMillis());
+        assertEquals(true, pool.getTestOnBorrow());
+        assertEquals(false, pool.getTestOnReturn());
+        assertEquals(false, pool.getTestWhileIdle());
+        assertEquals(GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
+        pool.close();
+
+
+        factory = new GenericKeyedObjectPoolFactory(createObjectFactory(), 1, GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 2, 3, 4, true, false, 5, 6, 7, true);
+        pool = (GenericKeyedObjectPool)factory.createPool();
+        assertEquals(1, pool.getMaxActive());
+        assertEquals(2, pool.getMaxWait());
+        assertEquals(3, pool.getMaxIdle());
+        assertEquals(4, pool.getMaxTotal());
+        assertEquals(5, pool.getTimeBetweenEvictionRunsMillis());
+        assertEquals(6, pool.getNumTestsPerEvictionRun());
+        assertEquals(7, pool.getMinEvictableIdleTimeMillis());
+        assertEquals(true, pool.getTestOnBorrow());
+        assertEquals(false, pool.getTestOnReturn());
+        assertEquals(true, pool.getTestWhileIdle());
+        assertEquals(GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
+        pool.close();
+    }
+}

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

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

Added: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPoolFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPoolFactory.java?rev=390793&view=auto
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPoolFactory.java (added)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPoolFactory.java Sat Apr  1 23:15:31 2006
@@ -0,0 +1,75 @@
+/*
+ * 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.TestKeyedObjectPoolFactory;
+import org.apache.commons.pool.KeyedObjectPoolFactory;
+import org.apache.commons.pool.KeyedPoolableObjectFactory;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Tests for {@link StackKeyedObjectPoolFactory}.
+ *
+ * @author Sandy McArthur
+ * @version $Revision$ $Date$
+ */
+public class TestStackKeyedObjectPoolFactory extends TestKeyedObjectPoolFactory {
+    public TestStackKeyedObjectPoolFactory(final String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestStackKeyedObjectPoolFactory.class);
+    }
+
+    protected KeyedObjectPoolFactory makeFactory(final KeyedPoolableObjectFactory objectFactory) throws UnsupportedOperationException {
+        return new StackKeyedObjectPoolFactory(objectFactory);
+    }
+
+    public void testConstructors() throws Exception {
+        StackKeyedObjectPoolFactory factory = new StackKeyedObjectPoolFactory();
+        factory.createPool().close();
+
+        factory = new StackKeyedObjectPoolFactory(1);
+        StackKeyedObjectPool pool = (StackKeyedObjectPool)factory.createPool();
+        assertEquals(1,pool._maxSleeping);
+        pool.close();
+
+        factory = new StackKeyedObjectPoolFactory(1, 2);
+        pool = (StackKeyedObjectPool)factory.createPool();
+        assertEquals(1,pool._maxSleeping);
+        assertEquals(2,pool._initSleepingCapacity);
+        pool.close();
+
+        factory = new StackKeyedObjectPoolFactory(createObjectFactory());
+        pool = (StackKeyedObjectPool)factory.createPool();
+        pool.close();
+
+        factory = new StackKeyedObjectPoolFactory(createObjectFactory(),  1);
+        pool = (StackKeyedObjectPool)factory.createPool();
+        assertEquals(1,pool._maxSleeping);
+        pool.close();
+
+        factory = new StackKeyedObjectPoolFactory(createObjectFactory(),  1, 2);
+        pool = (StackKeyedObjectPool)factory.createPool();
+        assertEquals(1,pool._maxSleeping);
+        assertEquals(2,pool._initSleepingCapacity);
+        pool.close();
+
+    }
+}

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

Propchange: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPoolFactory.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