commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sandy...@apache.org
Subject svn commit: r390797 - in /jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite: TestCompositeKeyedObjectPoolFactory.java TestCompositeObjectPoolFactory.java
Date Sun, 02 Apr 2006 08:00:49 GMT
Author: sandymac
Date: Sun Apr  2 00:00:47 2006
New Revision: 390797

URL: http://svn.apache.org/viewcvs?rev=390797&view=rev
Log:
More unit tests.

Modified:
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeKeyedObjectPoolFactory.java
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeObjectPoolFactory.java

Modified: 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=390797&r1=390796&r2=390797&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeKeyedObjectPoolFactory.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeKeyedObjectPoolFactory.java
Sun Apr  2 00:00:47 2006
@@ -16,11 +16,17 @@
 
 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;
+import org.apache.commons.pool.KeyedObjectPoolFactory;
+import org.apache.commons.pool.KeyedPoolableObjectFactory;
+import org.apache.commons.pool.MethodCallPoolableObjectFactory;
+import org.apache.commons.pool.PoolUtils;
+import org.apache.commons.pool.PoolableObjectFactory;
+import org.apache.commons.pool.TestKeyedObjectPoolFactory;
+import org.apache.commons.pool.impl.StackObjectPoolFactory;
+
+import java.util.Random;
 
 /**
  * Tests for {@link CompositeKeyedObjectPoolFactory}.
@@ -29,6 +35,8 @@
  * @version $Revision$ $Date$
  */
 public class TestCompositeKeyedObjectPoolFactory extends TestKeyedObjectPoolFactory {
+    private final Random rnd = new Random();
+
     public TestCompositeKeyedObjectPoolFactory(final String name) {
         super(name);
     }
@@ -39,5 +47,99 @@
 
     protected KeyedObjectPoolFactory makeFactory(final KeyedPoolableObjectFactory objectFactory)
throws UnsupportedOperationException {
         return new CompositeKeyedObjectPoolFactory(objectFactory);
+    }
+
+    public void testConstructors() throws Exception {
+        CompositeKeyedObjectPoolFactory factory = new CompositeKeyedObjectPoolFactory(createObjectFactory());
+        factory.createPool().close();
+
+        try {
+            new CompositeKeyedObjectPoolFactory((KeyedPoolableObjectFactory)null);
+            fail();
+        } catch (IllegalArgumentException iae) {
+            // expected
+        }
+
+        try {
+            new CompositeKeyedObjectPoolFactory((CompositeObjectPoolFactory)null);
+            fail();
+        } catch (IllegalArgumentException iae) {
+            // expected
+        }
+        factory = new CompositeKeyedObjectPoolFactory(new CompositeObjectPoolFactory(new
MethodCallPoolableObjectFactory()));
+        factory.createPool().close();
+
+        try {
+            new CompositeKeyedObjectPoolFactory((PoolableObjectFactory)null);
+            fail();
+        } catch (IllegalArgumentException iae) {
+            // expected
+        }
+        factory = new CompositeKeyedObjectPoolFactory(new MethodCallPoolableObjectFactory());
+        factory.createPool().close();
+    }
+
+    public void testStaticCreatePool() {
+        assertNotNull(CompositeKeyedObjectPoolFactory.createPool(new StackObjectPoolFactory()));
+        try {
+            CompositeKeyedObjectPoolFactory.createPool(null);
+            fail();
+        } catch (IllegalArgumentException iae) {
+            // expected
+        }
+    }
+
+    public void testFactory() {
+        CompositeKeyedObjectPoolFactory factory = (CompositeKeyedObjectPoolFactory)makeFactory();
+        try {
+            factory.setFactory(null);
+            fail();
+        } catch (IllegalArgumentException iae) {
+            // expected
+        }
+
+        factory.setFactory(new MethodCallPoolableObjectFactory());
+        assertNotNull(factory.getFactory());
+        assertNull(factory.getKeyedFactory());
+    }
+
+    public void testKeyedFactory() {
+        CompositeKeyedObjectPoolFactory factory = (CompositeKeyedObjectPoolFactory)makeFactory();
+        try {
+            factory.setKeyedFactory(null);
+            fail();
+        } catch (IllegalArgumentException iae) {
+            // expected
+        }
+
+        factory.setKeyedFactory(PoolUtils.adapt(new MethodCallPoolableObjectFactory()));
+        assertNotNull(factory.getKeyedFactory());
+        assertNull(factory.getFactory());
+    }
+
+    public void testClone() throws CloneNotSupportedException {
+        CompositeKeyedObjectPoolFactory f1 = (CompositeKeyedObjectPoolFactory)makeFactory();
+        f1.setBorrowPolicy(BorrowPolicy.SOFT_FIFO);
+        f1.setEvictIdleMillis(rnd.nextLong());
+        f1.setEvictInvalidFrequencyMillis(rnd.nextLong());
+        f1.setExhaustionPolicy(ExhaustionPolicy.FAIL);
+        f1.setLimitPolicy(LimitPolicy.FAIL);
+        f1.setMaxActivePerKey(rnd.nextInt());
+        f1.setMaxIdlePerKey(rnd.nextInt());
+        f1.setMaxWaitMillis(rnd.nextInt());
+        f1.setTrackingPolicy(TrackingPolicy.REFERENCE);
+        f1.setValidateOnReturn(rnd.nextBoolean());
+        CompositeKeyedObjectPoolFactory f2 = (CompositeKeyedObjectPoolFactory)f1.clone();
+
+        assertEquals(f1.getBorrowPolicy(), f2.getBorrowPolicy());
+        assertEquals(f1.getEvictIdleMillis(), f2.getEvictIdleMillis());
+        assertEquals(f1.getEvictInvalidFrequencyMillis(), f2.getEvictInvalidFrequencyMillis());
+        assertEquals(f1.getExhaustionPolicy(), f2.getExhaustionPolicy());
+        assertEquals(f1.getLimitPolicy(), f2.getLimitPolicy());
+        assertEquals(f1.getMaxActivePerKey(), f2.getMaxActivePerKey());
+        assertEquals(f1.getMaxIdlePerKey(), f2.getMaxIdlePerKey());
+        assertEquals(f1.getMaxWaitMillis(), f2.getMaxWaitMillis());
+        assertEquals(f1.getTrackingPolicy(), f2.getTrackingPolicy());
+        assertEquals(f1.isValidateOnReturn(), f2.isValidateOnReturn());
     }
 }

Modified: 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=390797&r1=390796&r2=390797&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeObjectPoolFactory.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/composite/TestCompositeObjectPoolFactory.java
Sun Apr  2 00:00:47 2006
@@ -61,6 +61,16 @@
         }
     }
 
+    public void testBorrowPolicy() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        try {
+            copf.setBorrowPolicy(null);
+            fail();
+        } catch (IllegalArgumentException iae) {
+            // expected
+        }
+    }
+
     public void testBorrowPolicyNull() throws Exception {
         final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
         copf.setBorrowPolicy(BorrowPolicy.NULL);
@@ -134,6 +144,16 @@
         assertSame(b, aa);
     }
 
+    public void testExhaustionPolicy() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        try {
+            copf.setExhaustionPolicy(null);
+            fail();
+        } catch (IllegalArgumentException iae) {
+            // expected
+        }
+    }
+
     public void testExhaustionPolicyFail() throws Exception {
         final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
         copf.setExhaustionPolicy(ExhaustionPolicy.FAIL);
@@ -159,6 +179,16 @@
         pool.borrowObject();
     }
 
+    public void testLimitPolicy() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        try {
+            copf.setLimitPolicy(null);
+            fail();
+        } catch (IllegalArgumentException iae) {
+            // expected
+        }
+    }
+
     public void testLimitPolicyFail() throws Exception {
         final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
         copf.setMaxActive(1);
@@ -201,6 +231,16 @@
         pool.borrowObject();
     }
 
+    public void testTrackingPolicy() throws Exception {
+        final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
+        try {
+            copf.setTrackingPolicy(null);
+            fail();
+        } catch (IllegalArgumentException iae) {
+            // expected
+        }
+    }
+
     public void testTrackingPolicyNull() throws Exception {
         final CompositeObjectPoolFactory copf = (CompositeObjectPoolFactory)makeFactory();
         copf.setTrackingPolicy(TrackingPolicy.NULL);
@@ -330,6 +370,17 @@
         factory.setValid(false);
         Thread.sleep(75L);
         assertEquals(0, pool.getNumIdle());
+    }
+
+    public void testSetFactory() {
+        CompositeObjectPoolFactory factory = (CompositeObjectPoolFactory)makeFactory();
+
+        try {
+            factory.setFactory(null);
+            fail();
+        } catch (IllegalArgumentException iae) {
+            // expected
+        }
     }
 
     public void testToString() {



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