You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2012/05/05 12:13:22 UTC

svn commit: r1334378 - /commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java

Author: sebb
Date: Sat May  5 10:13:22 2012
New Revision: 1334378

URL: http://svn.apache.org/viewvc?rev=1334378&view=rev
Log:
Add ctor tests, including null factory
TODO determine why JMX cannot find creationStackTrace

Modified:
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java

Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java?rev=1334378&r1=1334377&r2=1334378&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java Sat May  5 10:13:22 2012
@@ -31,15 +31,16 @@ import java.util.Random;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import javax.management.AttributeNotFoundException;
 import javax.management.MBeanServer;
 import javax.management.Notification;
 import javax.management.NotificationListener;
 import javax.management.ObjectName;
 
 import org.apache.commons.pool2.BasePoolableObjectFactory;
+import org.apache.commons.pool2.PoolableObjectFactory;
 import org.apache.commons.pool2.ObjectPool;
 import org.apache.commons.pool2.PoolUtils;
-import org.apache.commons.pool2.PoolableObjectFactory;
 import org.apache.commons.pool2.TestBaseObjectPool;
 import org.apache.commons.pool2.VisitTracker;
 import org.apache.commons.pool2.VisitTrackerFactory;
@@ -100,13 +101,103 @@ public class TestGenericObjectPool exten
             // Clean these up ready for the next test
             msg.append(name.toString());
             msg.append(" created via\n");
-            msg.append(mbs.getAttribute(name, "creationStackTrace"));
+            try {
+                msg.append(mbs.getAttribute(name, "creationStackTrace"));
+            } catch (AttributeNotFoundException e) {
+                msg.append(e.getMessage());
+            }
             msg.append('\n');
             mbs.unregisterMBean(name);
         }
         Assert.assertEquals(msg.toString(), 0, registeredPoolCount);
     }
 
+    @Test(expected=IllegalArgumentException.class)
+    public void testConstructorNullFactory() {
+        // add dummy assert (won't be invoked because of IAE) to avoid "unused" warning
+        assertNotNull(new GenericObjectPool<String>(null));
+        // TODO this currently causes tearDown to report an error
+        // Looks like GOP needs to call close() or jmxUnregister() before throwing IAE
+    }
+
+    @Test(timeout=60000)
+    public void testConstructors() throws Exception {
+
+        // Make constructor arguments all different from defaults
+        int minIdle = 2;
+        long maxWait = 3;
+        int maxIdle = 4;
+        int maxTotal = 5;
+        long minEvictableIdleTimeMillis = 6;
+        int numTestsPerEvictionRun = 7;
+        boolean testOnBorrow = true;
+        boolean testOnReturn = true;
+        boolean testWhileIdle = true;
+        long timeBetweenEvictionRunsMillis = 8;
+        boolean blockWhenExhausted = false;
+        boolean lifo = false;
+        PoolableObjectFactory<Object> factory = new BasePoolableObjectFactory<Object>() { 
+            @Override
+            public Object makeObject() throws Exception {
+                return null;
+            }
+        };   
+
+        GenericObjectPool<Object> pool =
+            new GenericObjectPool<Object>(factory);
+        assertEquals(GenericObjectPoolConfig.DEFAULT_MAX_IDLE, pool.getMaxIdle());
+        assertEquals(GenericObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS, pool.getMaxWaitMillis());
+        assertEquals(GenericObjectPoolConfig.DEFAULT_MIN_IDLE, pool.getMinIdle());
+        assertEquals(GenericObjectPoolConfig.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+        assertEquals(GenericObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+                pool.getMinEvictableIdleTimeMillis());
+        assertEquals(GenericObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+                pool.getNumTestsPerEvictionRun());
+        assertEquals(GenericObjectPoolConfig.DEFAULT_TEST_ON_BORROW,
+                pool.getTestOnBorrow());
+        assertEquals(GenericObjectPoolConfig.DEFAULT_TEST_ON_RETURN,
+                pool.getTestOnReturn());
+        assertEquals(GenericObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE,
+                pool.getTestWhileIdle());
+        assertEquals(GenericObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+                pool.getTimeBetweenEvictionRunsMillis());
+        assertEquals(GenericObjectPoolConfig.DEFAULT_BLOCK_WHEN_EXHAUSTED,
+                pool.getBlockWhenExhausted());
+        assertEquals(GenericObjectPoolConfig.DEFAULT_LIFO, pool.getLifo());
+        pool.close();
+
+        GenericObjectPoolConfig config =
+                new GenericObjectPoolConfig();
+        config.setLifo(lifo);
+        config.setMaxIdle(maxIdle);
+        config.setMinIdle(minIdle);
+        config.setMaxTotal(maxTotal);
+        config.setMaxWaitMillis(maxWait);
+        config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
+        config.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
+        config.setTestOnBorrow(testOnBorrow);
+        config.setTestOnReturn(testOnReturn);
+        config.setTestWhileIdle(testWhileIdle);
+        config.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
+        config.setBlockWhenExhausted(blockWhenExhausted);
+        pool = new GenericObjectPool<Object>(factory, config);
+        assertEquals(maxIdle, pool.getMaxIdle());
+        assertEquals(maxWait, pool.getMaxWaitMillis());
+        assertEquals(minIdle, pool.getMinIdle());
+        assertEquals(maxTotal, pool.getMaxTotal());
+        assertEquals(minEvictableIdleTimeMillis,
+                pool.getMinEvictableIdleTimeMillis());
+        assertEquals(numTestsPerEvictionRun, pool.getNumTestsPerEvictionRun());
+        assertEquals(testOnBorrow,pool.getTestOnBorrow());
+        assertEquals(testOnReturn,pool.getTestOnReturn());
+        assertEquals(testWhileIdle,pool.getTestWhileIdle());
+        assertEquals(timeBetweenEvictionRunsMillis,
+                pool.getTimeBetweenEvictionRunsMillis());
+        assertEquals(blockWhenExhausted,pool.getBlockWhenExhausted());
+        assertEquals(lifo, pool.getLifo());
+        pool.close();
+    }
+
     @Test(timeout=60000)
     public void testWhenExhaustedFail() throws Exception {
         pool.setMaxTotal(1);



Re: svn commit: r1334378 - /commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java

Posted by Mark Thomas <ma...@apache.org>.
On 05/05/2012 11:20, sebb AT ASF wrote:
> On 5 May 2012 11:13,  <se...@apache.org> wrote:
>> Author: sebb
>> Date: Sat May  5 10:13:22 2012
>> New Revision: 1334378
>>
>> URL: http://svn.apache.org/viewvc?rev=1334378&view=rev
>> Log:
>> Add ctor tests, including null factory
>> TODO determine why JMX cannot find creationStackTrace
> 
> I had to update tearDown because it was failing to find the attribute.
> 
> Not sure why this is the case. Does not seem to be able to find any attributes.

Bizarre. I've fixed this but the case for the attributes isn't what I
would expect at all. Just checked the javax.management docs and this is
an intended. Oh well...

Mark

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


Re: svn commit: r1334378 - /commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java

Posted by sebb AT ASF <se...@apache.org>.
On 5 May 2012 11:13,  <se...@apache.org> wrote:
> Author: sebb
> Date: Sat May  5 10:13:22 2012
> New Revision: 1334378
>
> URL: http://svn.apache.org/viewvc?rev=1334378&view=rev
> Log:
> Add ctor tests, including null factory
> TODO determine why JMX cannot find creationStackTrace

I had to update tearDown because it was failing to find the attribute.

Not sure why this is the case. Does not seem to be able to find any attributes.

> Modified:
>    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
>
> Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
> URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java?rev=1334378&r1=1334377&r2=1334378&view=diff
> ==============================================================================
> --- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java (original)
> +++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java Sat May  5 10:13:22 2012
> @@ -31,15 +31,16 @@ import java.util.Random;
>  import java.util.Set;
>  import java.util.concurrent.atomic.AtomicInteger;
>
> +import javax.management.AttributeNotFoundException;
>  import javax.management.MBeanServer;
>  import javax.management.Notification;
>  import javax.management.NotificationListener;
>  import javax.management.ObjectName;
>
>  import org.apache.commons.pool2.BasePoolableObjectFactory;
> +import org.apache.commons.pool2.PoolableObjectFactory;
>  import org.apache.commons.pool2.ObjectPool;
>  import org.apache.commons.pool2.PoolUtils;
> -import org.apache.commons.pool2.PoolableObjectFactory;
>  import org.apache.commons.pool2.TestBaseObjectPool;
>  import org.apache.commons.pool2.VisitTracker;
>  import org.apache.commons.pool2.VisitTrackerFactory;
> @@ -100,13 +101,103 @@ public class TestGenericObjectPool exten
>             // Clean these up ready for the next test
>             msg.append(name.toString());
>             msg.append(" created via\n");
> -            msg.append(mbs.getAttribute(name, "creationStackTrace"));
> +            try {
> +                msg.append(mbs.getAttribute(name, "creationStackTrace"));
> +            } catch (AttributeNotFoundException e) {
> +                msg.append(e.getMessage());
> +            }
>             msg.append('\n');
>             mbs.unregisterMBean(name);
>         }

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