commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sandy...@apache.org
Subject svn commit: r390581 - in /jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl: TestGenericObjectPoolFactory.java TestStackObjectPoolFactory.java
Date Sat, 01 Apr 2006 03:10:23 GMT
Author: sandymac
Date: Fri Mar 31 19:10:23 2006
New Revision: 390581

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

Modified:
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPoolFactory.java
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java

Modified: 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=390581&r1=390580&r2=390581&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPoolFactory.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPoolFactory.java
Fri Mar 31 19:10:23 2006
@@ -19,9 +19,12 @@
 import org.apache.commons.pool.TestObjectPoolFactory;
 import org.apache.commons.pool.ObjectPoolFactory;
 import org.apache.commons.pool.PoolableObjectFactory;
+import org.apache.commons.pool.MethodCallPoolableObjectFactory;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import java.util.NoSuchElementException;
+
 /**
  * Tests for {@link GenericObjectPoolFactory}.
  *
@@ -39,5 +42,150 @@
 
     protected ObjectPoolFactory makeFactory(final PoolableObjectFactory objectFactory) throws
UnsupportedOperationException {
         return new GenericObjectPoolFactory(objectFactory);
+    }
+
+    public void testConstructors() throws Exception {
+        GenericObjectPoolFactory factory = new GenericObjectPoolFactory(new MethodCallPoolableObjectFactory());
+        GenericObjectPool pool;
+        factory.createPool().close();
+
+        final GenericObjectPool.Config config = new GenericObjectPool.Config();
+        config.maxActive = 1;
+        config.maxIdle = 2;
+        config.maxWait = 3;
+        config.minIdle = 4;
+        config.minEvictableIdleTimeMillis = 5;
+        config.numTestsPerEvictionRun = 6;
+        config.softMinEvictableIdleTimeMillis = 7;
+        config.testOnBorrow = true;
+        config.testOnReturn = false;
+        config.testWhileIdle = true;
+        config.timeBetweenEvictionRunsMillis = 8;
+        config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
+        factory = new GenericObjectPoolFactory(new MethodCallPoolableObjectFactory(), config);
+        pool = (GenericObjectPool)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(7, pool.getSoftMinEvictableIdleTimeMillis());
+        assertEquals(true, pool.getTestOnBorrow());
+        assertEquals(false, pool.getTestOnReturn());
+        assertEquals(true, pool.getTestWhileIdle());
+        assertEquals(8, pool.getTimeBetweenEvictionRunsMillis());
+        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
+        pool.borrowObject();
+        pool.close();
+
+
+        factory = new GenericObjectPoolFactory(new MethodCallPoolableObjectFactory(), 1);
+        pool = (GenericObjectPool)factory.createPool();
+        assertEquals(1, pool.getMaxActive());
+        pool.borrowObject();
+        pool.close();
+
+
+        factory = new GenericObjectPoolFactory(new MethodCallPoolableObjectFactory(), 1,
GenericObjectPool.WHEN_EXHAUSTED_BLOCK, 125);
+        pool = (GenericObjectPool)factory.createPool();
+        assertEquals(1, pool.getMaxActive());
+        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_BLOCK, pool.getWhenExhaustedAction());
+        assertEquals(125, pool.getMaxWait());
+        pool.borrowObject();
+        long startTime = System.currentTimeMillis();
+        try {
+            pool.borrowObject();
+            fail();
+        } catch (NoSuchElementException nsee) {
+            // expected
+        }
+        long delay = System.currentTimeMillis() - startTime;
+        assertTrue("delay: " + delay, delay > 100);
+        pool.close();
+
+
+        factory = new GenericObjectPoolFactory(new MethodCallPoolableObjectFactory(), 1,
GenericObjectPool.WHEN_EXHAUSTED_GROW, 2, true, false);
+        pool = (GenericObjectPool)factory.createPool();
+        assertEquals(1, pool.getMaxActive());
+        assertEquals(2, pool.getMaxWait());
+        assertEquals(true, pool.getTestOnBorrow());
+        assertEquals(false, pool.getTestOnReturn());
+        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
+        pool.borrowObject();
+        pool.close();
+
+
+        factory = new GenericObjectPoolFactory(new MethodCallPoolableObjectFactory(), 1,
GenericObjectPool.WHEN_EXHAUSTED_GROW, 2, 3);
+        pool = (GenericObjectPool)factory.createPool();
+        assertEquals(1, pool.getMaxActive());
+        assertEquals(2, pool.getMaxWait());
+        assertEquals(3, pool.getMaxIdle());
+        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
+        pool.borrowObject();
+        pool.close();
+
+
+        factory = new GenericObjectPoolFactory(new MethodCallPoolableObjectFactory(), 1,
GenericObjectPool.WHEN_EXHAUSTED_GROW, 2, 3, true, false);
+        pool = (GenericObjectPool)factory.createPool();
+        assertEquals(1, pool.getMaxActive());
+        assertEquals(2, pool.getMaxWait());
+        assertEquals(3, pool.getMaxIdle());
+        assertEquals(true, pool.getTestOnBorrow());
+        assertEquals(false, pool.getTestOnReturn());
+        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
+        pool.borrowObject();
+        pool.close();
+
+
+        factory = new GenericObjectPoolFactory(new MethodCallPoolableObjectFactory(), 1,
GenericObjectPool.WHEN_EXHAUSTED_GROW, 2, 3, true, false, 4, 5, 6, false);
+        pool = (GenericObjectPool)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(GenericObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
+        pool.borrowObject();
+        pool.close();
+
+
+        factory = new GenericObjectPoolFactory(new MethodCallPoolableObjectFactory(), 1,
GenericObjectPool.WHEN_EXHAUSTED_GROW, 2, 3, 4, true, false, 5, 6, 7, true);
+        pool = (GenericObjectPool)factory.createPool();
+        assertEquals(1, pool.getMaxActive());
+        assertEquals(2, pool.getMaxWait());
+        assertEquals(3, pool.getMaxIdle());
+        assertEquals(4, pool.getMinIdle());
+        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(GenericObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
+        pool.borrowObject();
+        pool.close();
+
+
+        factory = new GenericObjectPoolFactory(new MethodCallPoolableObjectFactory(), 1,
GenericObjectPool.WHEN_EXHAUSTED_GROW, 2, 3, 4, true, false, 5, 6, 7, true, 8);
+        pool = (GenericObjectPool)factory.createPool();
+        assertEquals(1, pool.getMaxActive());
+        assertEquals(2, pool.getMaxWait());
+        assertEquals(3, pool.getMaxIdle());
+        assertEquals(4, pool.getMinIdle());
+        assertEquals(5, pool.getTimeBetweenEvictionRunsMillis());
+        assertEquals(6, pool.getNumTestsPerEvictionRun());
+        assertEquals(7, pool.getMinEvictableIdleTimeMillis());
+        assertEquals(8, pool.getSoftMinEvictableIdleTimeMillis());
+        assertEquals(true, pool.getTestOnBorrow());
+        assertEquals(false, pool.getTestOnReturn());
+        assertEquals(true, pool.getTestWhileIdle());
+        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
+        pool.borrowObject();
+        pool.close();
     }
 }

Modified: 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=390581&r1=390580&r2=390581&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java
Fri Mar 31 19:10:23 2006
@@ -19,9 +19,12 @@
 import org.apache.commons.pool.TestObjectPoolFactory;
 import org.apache.commons.pool.ObjectPoolFactory;
 import org.apache.commons.pool.PoolableObjectFactory;
+import org.apache.commons.pool.MethodCallPoolableObjectFactory;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import java.util.NoSuchElementException;
+
 /**
  * Tests for {@link StackObjectPoolFactory}.
  *
@@ -39,5 +42,30 @@
 
     protected ObjectPoolFactory makeFactory(final PoolableObjectFactory objectFactory) throws
UnsupportedOperationException {
         return new StackObjectPoolFactory(objectFactory);
+    }
+
+    public void testConstructors() throws Exception {
+        StackObjectPoolFactory factory = new StackObjectPoolFactory();
+        factory.createPool().close();
+
+        
+        factory = new StackObjectPoolFactory(1);
+        StackObjectPool pool = (StackObjectPool)factory.createPool();
+        pool.close();
+
+
+        factory = new StackObjectPoolFactory(1, 1);
+        pool = (StackObjectPool)factory.createPool();
+        pool.close();
+
+
+        factory = new StackObjectPoolFactory(new MethodCallPoolableObjectFactory(), 1);
+        pool = (StackObjectPool)factory.createPool();
+        Object a = pool.borrowObject();
+        Object b = pool.borrowObject();
+        pool.returnObject(a);
+        pool.returnObject(b);
+        assertEquals(1, pool.getNumIdle());
+        pool.close();
     }
 }



---------------------------------------------------------------------
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