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/impl TestStackKeyedObjectPool.java
Date Wed, 05 Jun 2002 22:02:22 GMT
rwaldhoff    2002/06/05 15:02:22

  Modified:    pool/src/java/org/apache/commons/pool/impl
                        StackKeyedObjectPool.java
               pool/src/test/org/apache/commons/pool/impl
                        TestStackKeyedObjectPool.java
  Log:
  fix concurrent modification bug in StackKeyedObjectPool, and add a test that demonstrates
  
  Revision  Changes    Path
  1.5       +11 -5     jakarta-commons/pool/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java
  
  Index: StackKeyedObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- StackKeyedObjectPool.java	1 May 2002 06:33:01 -0000	1.4
  +++ StackKeyedObjectPool.java	5 Jun 2002 22:02:22 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java,v
1.4 2002/05/01 06:33:01 rwaldhoff Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/05/01 06:33:01 $
  + * $Header: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java,v
1.5 2002/06/05 22:02:22 rwaldhoff Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/06/05 22:02:22 $
    *
    * ====================================================================
    *
  @@ -81,7 +81,7 @@
    * artificial limits.
    *
    * @author Rodney Waldhoff
  - * @version $Id: StackKeyedObjectPool.java,v 1.4 2002/05/01 06:33:01 rwaldhoff Exp $
  + * @version $Id: StackKeyedObjectPool.java,v 1.5 2002/06/05 22:02:22 rwaldhoff Exp $
    */
   public class StackKeyedObjectPool extends BaseKeyedObjectPool implements KeyedObjectPool
{
       /**
  @@ -248,7 +248,9 @@
       public synchronized void clear() {
           Iterator it = _pools.keySet().iterator();
           while(it.hasNext()) {
  -            clear(it.next());
  +            Object key = it.next();
  +            Stack stack = (Stack)(_pools.get(key));
  +            destroyStack(key,stack);
           }
           _totIdle = 0;
           _pools.clear();
  @@ -257,6 +259,10 @@
   
       public synchronized void clear(Object key) {
           Stack stack = (Stack)(_pools.remove(key));
  +        destroyStack(key,stack);
  +    }
  +
  +    private synchronized void destroyStack(Object key,Stack stack) {
           if(null == stack) {
               return;
           } else {
  
  
  
  1.4       +28 -4     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestStackKeyedObjectPool.java	1 May 2002 06:33:02 -0000	1.3
  +++ TestStackKeyedObjectPool.java	5 Jun 2002 22:02:22 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java,v
1.3 2002/05/01 06:33:02 rwaldhoff Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/05/01 06:33:02 $
  + * $Header: /home/cvs/jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java,v
1.4 2002/06/05 22:02:22 rwaldhoff Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/06/05 22:02:22 $
    *
    * ====================================================================
    *
  @@ -66,7 +66,7 @@
   
   /**
    * @author Rodney Waldhoff
  - * @version $Id: TestStackKeyedObjectPool.java,v 1.3 2002/05/01 06:33:02 rwaldhoff Exp
$
  + * @version $Id: TestStackKeyedObjectPool.java,v 1.4 2002/06/05 22:02:22 rwaldhoff Exp
$
    */
   public class TestStackKeyedObjectPool extends TestCase {
       public TestStackKeyedObjectPool(String testName) {
  @@ -209,6 +209,30 @@
           assertEquals(0,pool.getNumIdle(""));
           Object obj2 = pool.borrowObject("");
           assertEquals("2",obj2);
  +    }
  +
  +    public void testCloseBug() throws Exception {
  +        {
  +            Object obj0 = pool.borrowObject("");
  +            Object obj1 = pool.borrowObject("");
  +            assertEquals(2,pool.getNumActive(""));
  +            assertEquals(0,pool.getNumIdle(""));
  +            pool.returnObject("",obj1);
  +            pool.returnObject("",obj0);
  +            assertEquals(0,pool.getNumActive(""));
  +            assertEquals(2,pool.getNumIdle(""));
  +        }
  +        {
  +            Object obj0 = pool.borrowObject("2");
  +            Object obj1 = pool.borrowObject("2");
  +            assertEquals(2,pool.getNumActive("2"));
  +            assertEquals(0,pool.getNumIdle("2"));
  +            pool.returnObject("2",obj1);
  +            pool.returnObject("2",obj0);
  +            assertEquals(0,pool.getNumActive("2"));
  +            assertEquals(2,pool.getNumIdle("2"));
  +        }
  +        pool.close();
       }
   
       public void testIdleCap() throws Exception {
  
  
  

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


Mime
View raw message