commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwaldh...@apache.org
Subject cvs commit: jakarta-commons/pool/src/test/org/apache/commons/pool TestKeyedObjectPool.java
Date Fri, 07 Mar 2003 20:28:36 GMT
rwaldhoff    2003/03/07 12:28:36

  Modified:    pool/src/test/org/apache/commons/pool/impl
                        TestStackKeyedObjectPool.java
                        TestGenericObjectPool.java TestStackObjectPool.java
                        TestGenericKeyedObjectPool.java
               pool/src/java/org/apache/commons/pool/impl
                        GenericObjectPool.java StackObjectPool.java
               pool/src/java/org/apache/commons/pool BaseObjectPool.java
               pool/src/test/org/apache/commons/pool
                        TestKeyedObjectPool.java
  Log:
  more tests
  
  Revision  Changes    Path
  1.8       +134 -21   jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java
  
  Index: TestStackKeyedObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestStackKeyedObjectPool.java	30 Nov 2002 09:14:01 -0000	1.7
  +++ TestStackKeyedObjectPool.java	7 Mar 2003 20:28:35 -0000	1.8
  @@ -63,6 +63,7 @@
   
   import java.util.BitSet;
   import java.util.HashMap;
  +import java.util.NoSuchElementException;
   
   import junit.framework.Test;
   import junit.framework.TestCase;
  @@ -85,23 +86,7 @@
       }
   
       protected KeyedObjectPool makeEmptyPool(int mincapacity) {
  -        StackKeyedObjectPool pool = new StackKeyedObjectPool(
  -            new KeyedPoolableObjectFactory()  {
  -                HashMap map = new HashMap();
  -                public Object makeObject(Object key) { 
  -                    int counter = 0;
  -                    Integer Counter = (Integer)(map.get(key));
  -                    if(null != Counter) {
  -                        counter = Counter.intValue();
  -                    }
  -                    map.put(key,new Integer(counter + 1));                       
  -                    return String.valueOf(key) + String.valueOf(counter); 
  -                }
  -                public void destroyObject(Object key, Object obj) { }
  -                public boolean validateObject(Object key, Object obj) { return true; }
  -                public void activateObject(Object key, Object obj) { }
  -                public void passivateObject(Object key, Object obj) { }
  -            }, mincapacity);
  +        StackKeyedObjectPool pool = new StackKeyedObjectPool(new SimpleFactory(),mincapacity);
           return pool;
       }
       
  @@ -197,4 +182,132 @@
           pool.clear();        
       }
       
  +    public void testVariousConstructors() throws Exception {
  +        {
  +            StackKeyedObjectPool pool = new StackKeyedObjectPool();
  +        }
  +        {
  +            StackKeyedObjectPool pool = new StackKeyedObjectPool(10);
  +        }
  +        {
  +            StackKeyedObjectPool pool = new StackKeyedObjectPool(10,5);
  +        }
  +        {
  +            StackKeyedObjectPool pool = new StackKeyedObjectPool(null);
  +        }
  +        {
  +            StackKeyedObjectPool pool = new StackKeyedObjectPool(null,10);
  +        }
  +        {
  +            StackKeyedObjectPool pool = new StackKeyedObjectPool(null,10,5);
  +        }
  +    }
  +        
  +    public void testBorrowFromEmptyPoolWithNullFactory() throws Exception {
  +        KeyedObjectPool pool = new StackKeyedObjectPool();
  +        try {
  +            pool.borrowObject("x");
  +            fail("Expected NoSuchElementException");
  +        } catch(NoSuchElementException e) {
  +            // expected
  +        }
  +    }
  +    
  +    public void testSetFactory() throws Exception {
  +        KeyedObjectPool pool = new StackKeyedObjectPool();
  +        try {
  +            pool.borrowObject("x");
  +            fail("Expected NoSuchElementException");
  +        } catch(NoSuchElementException e) {
  +            // expected
  +        }
  +        pool.setFactory(new SimpleFactory());
  +        Object obj = pool.borrowObject("x");
  +        assertNotNull(obj);
  +        pool.returnObject("x",obj);
  +    }
  +
  +    public void testCantResetFactoryWithActiveObjects() throws Exception {
  +        KeyedObjectPool pool = new StackKeyedObjectPool();
  +        pool.setFactory(new SimpleFactory());
  +        Object obj = pool.borrowObject("x");
  +        assertNotNull(obj);
  +
  +        try {
  +            pool.setFactory(new SimpleFactory());
  +            fail("Expected IllegalStateException");
  +        } catch(IllegalStateException e) {
  +            // expected
  +        }        
  +    }
  +    
  +    public void testCanResetFactoryWithoutActiveObjects() throws Exception {
  +        KeyedObjectPool pool = new StackKeyedObjectPool();
  +        {
  +            pool.setFactory(new SimpleFactory());
  +            Object obj = pool.borrowObject("x");        
  +            assertNotNull(obj);
  +            pool.returnObject("x",obj);
  +        }
  +        {
  +            pool.setFactory(new SimpleFactory());
  +            Object obj = pool.borrowObject("x");        
  +            assertNotNull(obj);
  +            pool.returnObject("x",obj);
  +        }
  +    }
  +
  +    public void testBorrowReturnWithSometimesInvalidObjects() throws Exception {
  +        KeyedObjectPool pool = new StackKeyedObjectPool();
  +        pool.setFactory(
  +            new KeyedPoolableObjectFactory() {
  +                int counter = 0;
  +                public Object makeObject(Object key) { return new Integer(counter++); }
  +                public void destroyObject(Object key, Object obj) { }
  +                public boolean validateObject(Object key, Object obj) {
  +                    if(obj instanceof Integer) {
  +                        return ((((Integer)obj).intValue() % 2) == 1);
  +                    } else {
  +                        return false;
  +                    }
  +                }
  +                public void activateObject(Object key, Object obj) { }
  +                public void passivateObject(Object key, Object obj) { 
  +                    if(obj instanceof Integer) {
  +                        if((((Integer)obj).intValue() % 3) == 0) {
  +                            throw new RuntimeException("Couldn't passivate");
  +                        }
  +                    } else {
  +                        throw new RuntimeException("Couldn't passivate");
  +                    }
  +                }
  +            }
  +        );
  +
  +        Object[] obj = new Object[10];
  +        for(int i=0;i<10;i++) {
  +            obj[i] = pool.borrowObject("key");
  +        }
  +        for(int i=0;i<10;i++) {
  +            pool.returnObject("key",obj[i]);
  +        }
  +        assertEquals(3,pool.getNumIdle("key"));
  +    }
  + 
  +    class SimpleFactory implements KeyedPoolableObjectFactory {
  +        HashMap map = new HashMap();
  +        public Object makeObject(Object key) { 
  +            int counter = 0;
  +            Integer Counter = (Integer)(map.get(key));
  +            if(null != Counter) {
  +                counter = Counter.intValue();
  +            }
  +            map.put(key,new Integer(counter + 1));                       
  +            return String.valueOf(key) + String.valueOf(counter); 
  +        }
  +        public void destroyObject(Object key, Object obj) { }
  +        public boolean validateObject(Object key, Object obj) { return true; }
  +        public void activateObject(Object key, Object obj) { }
  +        public void passivateObject(Object key, Object obj) { }
  +    }
   }
  
  
  
  1.10      +104 -25   jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
  
  Index: TestGenericObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestGenericObjectPool.java	5 Mar 2003 19:22:52 -0000	1.9
  +++ TestGenericObjectPool.java	7 Mar 2003 20:28:36 -0000	1.10
  @@ -61,6 +61,8 @@
   
   package org.apache.commons.pool.impl;
   
  +import java.util.NoSuchElementException;
  +
   import junit.framework.Test;
   import junit.framework.TestSuite;
   
  @@ -82,15 +84,7 @@
       }
   
       protected ObjectPool makeEmptyPool(int mincap) {
  -       GenericObjectPool pool = new GenericObjectPool(
  -            new PoolableObjectFactory()  {
  -                int counter = 0;
  -                public Object makeObject() { return String.valueOf(counter++); }
  -                public void destroyObject(Object obj) { }
  -                public boolean validateObject(Object obj) { return true; }
  -                public void activateObject(Object obj) { }
  -                public void passivateObject(Object obj) { }
  -            });
  +       GenericObjectPool pool = new GenericObjectPool(new SimpleFactory());
           pool.setMaxActive(mincap);
           pool.setMaxIdle(mincap);
           return pool;
  @@ -102,15 +96,7 @@
   
       public void setUp() throws Exception {
           super.setUp();
  -        pool = new GenericObjectPool(
  -            new PoolableObjectFactory()  {
  -                int counter = 0;
  -                public Object makeObject() { return String.valueOf(counter++); }
  -                public void destroyObject(Object obj) { }
  -                public boolean validateObject(Object obj) { return true; }
  -                public void activateObject(Object obj) { }
  -                public void passivateObject(Object obj) { }
  -            });
  +        pool = new GenericObjectPool(new SimpleFactory());
       }
   
       public void tearDown() throws Exception {
  @@ -159,12 +145,97 @@
           pool.borrowObject();
           try {
               pool.borrowObject();
  -            fail("Shouldn't get here.");
  -        } catch(java.util.NoSuchElementException e) {
  +            fail("Expected NoSuchElementException");
  +        } catch(NoSuchElementException e) {
  +            // expected
  +        }
  +    }
  +
  +    public void testInvalidWhenExhaustedAction() throws Exception {
  +        try {
  +            pool.setWhenExhaustedAction(Byte.MAX_VALUE);
  +            fail("Expected IllegalArgumentException");
  +        } catch(IllegalArgumentException e) {
  +            // expected
  +        }
  +
  +        try {
  +            ObjectPool pool = new GenericObjectPool(
  +                new SimpleFactory(),
  +                GenericObjectPool.DEFAULT_MAX_ACTIVE, 
  +                Byte.MAX_VALUE,
  +                GenericObjectPool.DEFAULT_MAX_WAIT, 
  +                GenericObjectPool.DEFAULT_MAX_IDLE,
  +                false,
  +                false,
  +                GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
  +                GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
  +                GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
  +                false
  +            );
  +            fail("Expected IllegalArgumentException");
  +        } catch(IllegalArgumentException e) {
               // expected
           }
       }
   
  +    public void testSettersAndGetters() throws Exception {
  +        GenericObjectPool pool = new GenericObjectPool();
  +        {
  +            pool.setFactory(new SimpleFactory());
  +        }
  +        {
  +            pool.setMaxActive(123);
  +            assertEquals(123,pool.getMaxActive());
  +        }
  +        {
  +            pool.setMaxIdle(12);
  +            assertEquals(12,pool.getMaxIdle());
  +        }
  +        {
  +            pool.setMaxWait(1234L);
  +            assertEquals(1234L,pool.getMaxWait());
  +        }
  +        {
  +            pool.setMinEvictableIdleTimeMillis(12345L);
  +            assertEquals(12345L,pool.getMinEvictableIdleTimeMillis());
  +        }
  +        {
  +            pool.setNumTestsPerEvictionRun(11);
  +            assertEquals(11,pool.getNumTestsPerEvictionRun());
  +        }
  +        {
  +            pool.setTestOnBorrow(true);
  +            assertTrue(pool.getTestOnBorrow());
  +            pool.setTestOnBorrow(false);
  +            assertTrue(!pool.getTestOnBorrow());
  +        }
  +        {
  +            pool.setTestOnReturn(true);
  +            assertTrue(pool.getTestOnReturn());
  +            pool.setTestOnReturn(false);
  +            assertTrue(!pool.getTestOnReturn());
  +        }
  +        {
  +            pool.setTestWhileIdle(true);
  +            assertTrue(pool.getTestWhileIdle());
  +            pool.setTestWhileIdle(false);
  +            assertTrue(!pool.getTestWhileIdle());
  +        }
  +        {
  +            pool.setTimeBetweenEvictionRunsMillis(11235L);
  +            assertEquals(11235L,pool.getTimeBetweenEvictionRunsMillis());
  +        }
  +        {
  +            pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
  +            assertEquals(GenericObjectPool.WHEN_EXHAUSTED_BLOCK,pool.getWhenExhaustedAction());
  +            pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_FAIL);
  +            assertEquals(GenericObjectPool.WHEN_EXHAUSTED_FAIL,pool.getWhenExhaustedAction());
  +            pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
  +            assertEquals(GenericObjectPool.WHEN_EXHAUSTED_GROW,pool.getWhenExhaustedAction());
  +        }
  +    }
  +
       public void testEviction() throws Exception {
           pool.setMaxIdle(500);
           pool.setMaxActive(500);
  @@ -214,7 +285,6 @@
           assertEquals("Should be zero idle, found " + pool.getNumIdle(),0,pool.getNumIdle());
       }
   
  -
       public void testThreaded1() throws Exception {
           pool.setMaxActive(15);
           pool.setMaxIdle(15);
  @@ -304,6 +374,15 @@
       }
       
       private GenericObjectPool pool = null;
  +
  +    static class SimpleFactory implements PoolableObjectFactory {
  +        int counter = 0;
  +        public Object makeObject() { return String.valueOf(counter++); }
  +        public void destroyObject(Object obj) { }
  +        public boolean validateObject(Object obj) { return true; }
  +        public void activateObject(Object obj) { }
  +        public void passivateObject(Object obj) { }
  +    }
   }
   
   
  
  
  
  1.8       +37 -7     jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java
  
  Index: TestStackObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestStackObjectPool.java	7 Mar 2003 15:18:21 -0000	1.7
  +++ TestStackObjectPool.java	7 Mar 2003 20:28:36 -0000	1.8
  @@ -193,13 +193,21 @@
                   public void destroyObject(Object obj) { }
                   public boolean validateObject(Object obj) {
                       if(obj instanceof Integer) {
  -                        return ((((Integer)obj).intValue() % 2) == 0);
  +                        return ((((Integer)obj).intValue() % 2) == 1);
                       } else {
                           return false;
                       }
                   }
                   public void activateObject(Object obj) { }
  -                public void passivateObject(Object obj) { }
  +                public void passivateObject(Object obj) { 
  +                    if(obj instanceof Integer) {
  +                        if((((Integer)obj).intValue() % 3) == 0) {
  +                            throw new RuntimeException("Couldn't passivate");
  +                        }
  +                    } else {
  +                        throw new RuntimeException("Couldn't passivate");
  +                    }
  +                }
               }
           );
   
  @@ -210,9 +218,31 @@
           for(int i=0;i<10;i++) {
               pool.returnObject(obj[i]);
           }
  -        assertEquals(5,pool.getNumIdle());
  +        assertEquals(3,pool.getNumIdle());
       }
       
  +    public void testVariousConstructors() throws Exception {
  +        {
  +            StackObjectPool pool = new StackObjectPool();
  +        }
  +        {
  +            StackObjectPool pool = new StackObjectPool(10);
  +        }
  +        {
  +            StackObjectPool pool = new StackObjectPool(10,5);
  +        }
  +        {
  +            StackObjectPool pool = new StackObjectPool(null);
  +        }
  +        {
  +            StackObjectPool pool = new StackObjectPool(null,10);
  +        }
  +        {
  +            StackObjectPool pool = new StackObjectPool(null,10,5);
  +        }
  +    }
  +
  +        
       static class SimpleFactory implements PoolableObjectFactory {
           int counter = 0;
           public Object makeObject() { return String.valueOf(counter++); }
  
  
  
  1.11      +76 -17    jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java
  
  Index: TestGenericKeyedObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TestGenericKeyedObjectPool.java	5 Mar 2003 19:22:53 -0000	1.10
  +++ TestGenericKeyedObjectPool.java	7 Mar 2003 20:28:36 -0000	1.11
  @@ -62,6 +62,7 @@
   package org.apache.commons.pool.impl;
   
   import java.util.HashMap;
  +import java.util.NoSuchElementException;
   
   import junit.framework.Test;
   import junit.framework.TestSuite;
  @@ -101,7 +102,7 @@
                   public void activateObject(Object key, Object obj) { }
                   public void passivateObject(Object key, Object obj) { }
               }
  -            );
  +        );
           pool.setMaxActive(mincapacity);
           pool.setMaxIdle(mincapacity);
           return pool;
  @@ -119,16 +120,7 @@
   
       public void setUp() throws Exception {
           super.setUp();
  -        pool = new GenericKeyedObjectPool(
  -            new KeyedPoolableObjectFactory()  {
  -                int counter = 0;
  -                public Object makeObject(Object key) { return String.valueOf(key) + String.valueOf(counter++);
}
  -                public void destroyObject(Object key, Object obj) { }
  -                public boolean validateObject(Object key, Object obj) { return true; }
  -                public void activateObject(Object key, Object obj) { }
  -                public void passivateObject(Object key, Object obj) { }
  -            }
  -            );
  +        pool = new GenericKeyedObjectPool(new SimpleFactory());
       }
       
       public void tearDown() throws Exception {
  @@ -226,12 +218,69 @@
           pool.borrowObject("");
           try {
               pool.borrowObject("");
  -            fail("Shouldn't get here.");
  -        } catch(java.util.NoSuchElementException e) {
  +            fail("Expected NoSuchElementException");
  +        } catch(NoSuchElementException e) {
               // expected
           }
       }
   
  +    public void testSettersAndGetters() throws Exception {
  +        GenericKeyedObjectPool pool = new GenericKeyedObjectPool();
  +        {
  +            pool.setFactory(new SimpleFactory());
  +        }
  +        {
  +            pool.setMaxActive(123);
  +            assertEquals(123,pool.getMaxActive());
  +        }
  +        {
  +            pool.setMaxIdle(12);
  +            assertEquals(12,pool.getMaxIdle());
  +        }
  +        {
  +            pool.setMaxWait(1234L);
  +            assertEquals(1234L,pool.getMaxWait());
  +        }
  +        {
  +            pool.setMinEvictableIdleTimeMillis(12345L);
  +            assertEquals(12345L,pool.getMinEvictableIdleTimeMillis());
  +        }
  +        {
  +            pool.setNumTestsPerEvictionRun(11);
  +            assertEquals(11,pool.getNumTestsPerEvictionRun());
  +        }
  +        {
  +            pool.setTestOnBorrow(true);
  +            assertTrue(pool.getTestOnBorrow());
  +            pool.setTestOnBorrow(false);
  +            assertTrue(!pool.getTestOnBorrow());
  +        }
  +        {
  +            pool.setTestOnReturn(true);
  +            assertTrue(pool.getTestOnReturn());
  +            pool.setTestOnReturn(false);
  +            assertTrue(!pool.getTestOnReturn());
  +        }
  +        {
  +            pool.setTestWhileIdle(true);
  +            assertTrue(pool.getTestWhileIdle());
  +            pool.setTestWhileIdle(false);
  +            assertTrue(!pool.getTestWhileIdle());
  +        }
  +        {
  +            pool.setTimeBetweenEvictionRunsMillis(11235L);
  +            assertEquals(11235L,pool.getTimeBetweenEvictionRunsMillis());
  +        }
  +        {
  +            pool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK);
  +            assertEquals(GenericObjectPool.WHEN_EXHAUSTED_BLOCK,pool.getWhenExhaustedAction());
  +            pool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL);
  +            assertEquals(GenericObjectPool.WHEN_EXHAUSTED_FAIL,pool.getWhenExhaustedAction());
  +            pool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW);
  +            assertEquals(GenericObjectPool.WHEN_EXHAUSTED_GROW,pool.getWhenExhaustedAction());
  +        }
  +    }
  +
       public void testEviction() throws Exception {
           pool.setMaxIdle(500);
           pool.setMaxActive(500);
  @@ -411,6 +460,16 @@
               _complete = true;
           }
       }
  +
  +    static class SimpleFactory implements KeyedPoolableObjectFactory {
  +        int counter = 0;
  +        public Object makeObject(Object key) { return String.valueOf(key) + String.valueOf(counter++);
}
  +        public void destroyObject(Object key, Object obj) { }
  +        public boolean validateObject(Object key, Object obj) { return true; }
  +        public void activateObject(Object key, Object obj) { }
  +        public void passivateObject(Object key, Object obj) { }
  +    }
  +
   }
   
   
  
  
  
  1.15      +5 -6      jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
  
  Index: GenericObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericObjectPool.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- GenericObjectPool.java	7 Mar 2003 15:18:20 -0000	1.14
  +++ GenericObjectPool.java	7 Mar 2003 20:28:36 -0000	1.15
  @@ -967,8 +967,7 @@
           long tstamp;
   
           ObjectTimestampPair(Object val) {
  -            value = val;
  -            tstamp = System.currentTimeMillis();
  +            this(val,System.currentTimeMillis());
           }
   
           ObjectTimestampPair(Object val, long time) {
  
  
  
  1.10      +14 -14    jakarta-commons/pool/src/java/org/apache/commons/pool/impl/StackObjectPool.java
  
  Index: StackObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/StackObjectPool.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- StackObjectPool.java	7 Mar 2003 15:18:20 -0000	1.9
  +++ StackObjectPool.java	7 Mar 2003 20:28:36 -0000	1.10
  @@ -102,8 +102,8 @@
        * using {@link #returnObject(java.lang.Object)}
        * before they can be {@link #borrowObject borrowed}.
        */
  -    public StackObjectPool(int max) {
  -        this((PoolableObjectFactory)null,max,DEFAULT_INIT_SLEEPING_CAPACITY);
  +    public StackObjectPool(int maxIdle) {
  +        this((PoolableObjectFactory)null,maxIdle,DEFAULT_INIT_SLEEPING_CAPACITY);
       }
   
       /**
  @@ -112,8 +112,8 @@
        * using {@link #returnObject(java.lang.Object)}
        * before they can be {@link #borrowObject borrowed}.
        */
  -    public StackObjectPool(int max, int init) {
  -        this((PoolableObjectFactory)null,max,init);
  +    public StackObjectPool(int maxIdle, int initIdleCapacity) {
  +        this((PoolableObjectFactory)null,maxIdle,initIdleCapacity);
       }
   
       /**
  @@ -134,8 +134,8 @@
        * @param factory the {@link PoolableObjectFactory} used to populate the pool
        * @param max cap on the number of "sleeping" instances in the pool
        */
  -    public StackObjectPool(PoolableObjectFactory factory, int max) {
  -        this(factory,max,DEFAULT_INIT_SLEEPING_CAPACITY);
  +    public StackObjectPool(PoolableObjectFactory factory, int maxIdle) {
  +        this(factory,maxIdle,DEFAULT_INIT_SLEEPING_CAPACITY);
       }
   
       /**
  @@ -146,14 +146,14 @@
        * at least <i>init</i> instances.
        *
        * @param factory the {@link PoolableObjectFactory} used to populate the pool
  -     * @param max cap on the number of "sleeping" instances in the pool
  +     * @param maxIdle cap on the number of "sleeping" instances in the pool
        * @param init initial size of the pool (this specifies the size of the container,
        *             it does not cause the pool to be pre-populated.)
        */
  -    public StackObjectPool(PoolableObjectFactory factory, int max, int init) {
  +    public StackObjectPool(PoolableObjectFactory factory, int maxIdle, int initIdleCapacity)
{
           _factory = factory;
  -        _maxSleeping = (max < 0 ? DEFAULT_MAX_SLEEPING : max);
  -        int initcapacity = (init < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : init);
  +        _maxSleeping = (maxIdle < 0 ? DEFAULT_MAX_SLEEPING : maxIdle);
  +        int initcapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY :
initIdleCapacity);
           _pool = new Stack();
           _pool.ensureCapacity( initcapacity > _maxSleeping ? _maxSleeping : initcapacity);
       }
  
  
  
  1.9       +7 -7      jakarta-commons/pool/src/java/org/apache/commons/pool/BaseObjectPool.java
  
  Index: BaseObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/BaseObjectPool.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- BaseObjectPool.java	7 Mar 2003 15:18:21 -0000	1.8
  +++ BaseObjectPool.java	7 Mar 2003 20:28:36 -0000	1.9
  @@ -107,12 +107,12 @@
           throw new UnsupportedOperationException();
       }
       
  -    protected boolean isClosed() {
  +    protected final boolean isClosed() {
           return closed;
       }
       
  -    protected void assertOpen() throws IllegalStateException {
  -        if(closed) {
  +    protected final void assertOpen() throws IllegalStateException {
  +        if(isClosed()) {
               throw new IllegalStateException("Pool not open");
           }
       }
  
  
  
  1.3       +7 -4      jakarta-commons/pool/src/test/org/apache/commons/pool/TestKeyedObjectPool.java
  
  Index: TestKeyedObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/test/org/apache/commons/pool/TestKeyedObjectPool.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestKeyedObjectPool.java	5 Mar 2003 19:17:08 -0000	1.2
  +++ TestKeyedObjectPool.java	7 Mar 2003 20:28:36 -0000	1.3
  @@ -161,6 +161,9 @@
           _pool.returnObject(keya,obj0);
           assertEquals(0,_pool.getNumActive(keya));
           assertEquals(2,_pool.getNumIdle(keya));
  +        
  +        assertEquals(0,_pool.getNumActive("xyzzy12345"));
  +        assertEquals(0,_pool.getNumIdle("xyzzy12345"));
       }
   
       public void testNumActiveNumIdle2() throws Exception {
  
  
  

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