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 TestStackObjectPool.java
Date Sat, 30 Nov 2002 09:14:01 GMT
rwaldhoff    2002/11/30 01:14:01

  Modified:    pool/src/java/org/apache/commons/pool/impl
                        StackKeyedObjectPool.java StackObjectPool.java
               pool/src/test/org/apache/commons/pool/impl
                        TestStackKeyedObjectPool.java
                        TestStackObjectPool.java
  Log:
  allow null factories (once again) in Stack[Keyed]ObjectPool
  add tests that demonstrate
  
  Revision  Changes    Path
  1.7       +15 -11    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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StackKeyedObjectPool.java	30 Oct 2002 22:54:42 -0000	1.6
  +++ StackKeyedObjectPool.java	30 Nov 2002 09:14:00 -0000	1.7
  @@ -223,7 +223,9 @@
           _totActive--;
           Integer old = (Integer)(_activeCount.get(key));
           _activeCount.put(key,new Integer(old.intValue() - 1));
  -        _factory.destroyObject(key,obj);
  +        if(null != _factory) {
  +            _factory.destroyObject(key,obj);
  +        }
           notifyAll(); // _totalActive has changed
       }
   
  @@ -274,12 +276,14 @@
           if(null == stack) {
               return;
           } else {
  -            Enumeration enum = stack.elements();
  -            while(enum.hasMoreElements()) {
  -                try {
  -                    _factory.destroyObject(key,enum.nextElement());
  -                } catch(Exception e) {
  -                    // ignore error, keep destroying the rest
  +            if(null != _factory) {
  +                Enumeration enum = stack.elements();
  +                while(enum.hasMoreElements()) {
  +                    try {
  +                        _factory.destroyObject(key,enum.nextElement());
  +                    } catch(Exception e) {
  +                        // ignore error, keep destroying the rest
  +                    }
                   }
               }
               _totIdle -= stack.size();
  
  
  
  1.7       +17 -13    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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StackObjectPool.java	30 Oct 2002 22:54:42 -0000	1.6
  +++ StackObjectPool.java	30 Nov 2002 09:14:01 -0000	1.7
  @@ -174,16 +174,18 @@
   
       public void returnObject(Object obj) throws Exception {
           boolean success = true;
  -        if(!(_factory.validateObject(obj))) {
  -            success = false;
  -        } else {
  -            try {
  -                _factory.passivateObject(obj);
  -            } catch(Exception e) {
  +        if(null != _factory) {
  +            if(!(_factory.validateObject(obj))) {
                   success = false;
  +            } else {
  +                try {
  +                    _factory.passivateObject(obj);
  +                } catch(Exception e) {
  +                    success = false;
  +                }
               }
           }
  -
  +        
           boolean shouldDestroy = !success;
   
           synchronized(this) {
  @@ -196,7 +198,7 @@
               notifyAll(); // _numActive has changed
           }
   
  -        if(shouldDestroy) {
  +        if(shouldDestroy) { // by constructor, shouldDestroy is false when _factory is
null
               try {
                   _factory.destroyObject(obj);
               } catch(Exception e) {
  @@ -207,7 +209,9 @@
   
       public synchronized void invalidateObject(Object obj) throws Exception {
           _numActive--;
  -        _factory.destroyObject(obj);
  +        if(null != _factory ) {
  +            _factory.destroyObject(obj);
  +        }
           notifyAll(); // _numActive has changed
       }
   
  
  
  
  1.7       +30 -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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestStackKeyedObjectPool.java	31 Oct 2002 15:04:24 -0000	1.6
  +++ TestStackKeyedObjectPool.java	30 Nov 2002 09:14:01 -0000	1.7
  @@ -61,6 +61,7 @@
   
   package org.apache.commons.pool.impl;
   
  +import java.util.BitSet;
   import java.util.HashMap;
   
   import junit.framework.Test;
  @@ -171,4 +172,29 @@
               assertEquals((i < 8 ? i+1 : 8),pool.getNumIdle(""));
           }
       }
  +    
  +    public void testPoolWithNullFactory() throws Exception {
  +        KeyedObjectPool pool = new StackKeyedObjectPool(10);
  +        for(int i=0;i<10;i++) {
  +            pool.returnObject("X",new Integer(i));
  +        }
  +        for(int j=0;j<3;j++) {
  +            Integer[] borrowed = new Integer[10];
  +            BitSet found = new BitSet();
  +            for(int i=0;i<10;i++) {
  +                borrowed[i] = (Integer)(pool.borrowObject("X"));
  +                assertNotNull(borrowed);
  +                assertTrue(!found.get(borrowed[i].intValue()));
  +                found.set(borrowed[i].intValue());
  +            }
  +            for(int i=0;i<10;i++) {
  +                pool.returnObject("X",borrowed[i]);
  +            }
  +        }
  +        pool.invalidateObject("X",pool.borrowObject("X"));
  +        pool.invalidateObject("X",pool.borrowObject("X"));
  +        pool.clear("X");        
  +        pool.clear();        
  +    }
  +    
   }
  
  
  
  1.6       +29 -4     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestStackObjectPool.java	31 Oct 2002 00:06:19 -0000	1.5
  +++ TestStackObjectPool.java	30 Nov 2002 09:14:01 -0000	1.6
  @@ -61,6 +61,8 @@
   
   package org.apache.commons.pool.impl;
   
  +import java.util.BitSet;
  +
   import junit.framework.Test;
   import junit.framework.TestSuite;
   
  @@ -112,5 +114,28 @@
               assertEquals(99 - i,pool.getNumActive());
               assertEquals((i < 8 ? i+1 : 8),pool.getNumIdle());
           }
  +    }
  +
  +    public void testPoolWithNullFactory() throws Exception {
  +        ObjectPool pool = new StackObjectPool(10);
  +        for(int i=0;i<10;i++) {
  +            pool.returnObject(new Integer(i));
  +        }
  +        for(int j=0;j<3;j++) {
  +            Integer[] borrowed = new Integer[10];
  +            BitSet found = new BitSet();
  +            for(int i=0;i<10;i++) {
  +                borrowed[i] = (Integer)(pool.borrowObject());
  +                assertNotNull(borrowed);
  +                assertTrue(!found.get(borrowed[i].intValue()));
  +                found.set(borrowed[i].intValue());
  +            }
  +            for(int i=0;i<10;i++) {
  +                pool.returnObject(borrowed[i]);
  +            }
  +        }
  +        pool.invalidateObject(pool.borrowObject());
  +        pool.invalidateObject(pool.borrowObject());
  +        pool.clear();        
       }
   }
  
  
  

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