commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From di...@apache.org
Subject cvs commit: jakarta-commons/pool/src/test/org/apache/commons/pool/impl TestGenericObjectPool.java
Date Tue, 10 Aug 2004 19:39:13 GMT
dirkv       2004/08/10 12:39:13

  Modified:    pool/src/test/org/apache/commons/pool/impl
                        TestGenericObjectPool.java
  Log:
  Bugzilla Bug 30426:	[pool] need property for removing objects above min
  - applied patch from David Rosenstark (with some cleanups)
  
  Revision  Changes    Path
  1.24      +51 -1     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.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- TestGenericObjectPool.java	4 Jul 2004 17:21:47 -0000	1.23
  +++ TestGenericObjectPool.java	10 Aug 2004 19:39:13 -0000	1.24
  @@ -21,6 +21,7 @@
   import junit.framework.Test;
   import junit.framework.TestSuite;
   
  +import org.apache.commons.pool.BasePoolableObjectFactory;
   import org.apache.commons.pool.ObjectPool;
   import org.apache.commons.pool.PoolableObjectFactory;
   import org.apache.commons.pool.TestObjectPool;
  @@ -593,6 +594,55 @@
           assertTrue("Should be less than 100 idle, found " + pool.getNumIdle(),pool.getNumIdle()
< 100);
           try { Thread.sleep(600L); } catch(Exception e) { }
           assertEquals("Should be zero idle, found " + pool.getNumIdle(),0,pool.getNumIdle());
  +    }
  +
  +    public void testEvictionSoftMinIdle() throws Exception {
  +        GenericObjectPool pool = null;
  +        
  +        class TimeTest extends BasePoolableObjectFactory {
  +            private final long createTime;
  +            public TimeTest() {
  +                createTime = System.currentTimeMillis();
  +            }
  +            public Object makeObject() throws Exception {
  +                return new TimeTest();
  +            }
  +            public long getCreateTime() {
  +                return createTime;
  +            }
  +        }
  +        
  +        pool = new GenericObjectPool(new TimeTest());
  +        
  +        pool.setMaxIdle(5);
  +        pool.setMaxActive(5);
  +        pool.setNumTestsPerEvictionRun(5);
  +        pool.setMinEvictableIdleTimeMillis(3000L);
  +        pool.setTimeBetweenEvictionRunsMillis(250L);
  +        pool.setTestWhileIdle(true);
  +        pool.setSoftMinEvictableIdleTimeMillis(1000L);
  +        pool.setMinIdle(2);
  +        
  +        Object[] active = new Object[5];
  +        Long[] creationTime = new Long[5] ;
  +        for(int i=0;i<5;i++) {
  +            active[i] = pool.borrowObject();
  +            creationTime[i] = new Long(((TimeTest)active[i]).getCreateTime());
  +        }
  +        
  +        for(int i=0;i<5;i++) {
  +            pool.returnObject(active[i]);
  +        }
  +        
  +        try { Thread.sleep(1500L); } catch(Exception e) { }
  +        assertTrue("Should be 2 OLD idle, found " + pool.getNumIdle(),pool.getNumIdle()
== 2 &&
  +                ((TimeTest)pool.borrowObject()).getCreateTime() == creationTime[3].longValue()
&&
  +                ((TimeTest)pool.borrowObject()).getCreateTime() == creationTime[4].longValue());
  +        
  +        try { Thread.sleep(2000L); } catch(Exception e) { }
  +        assertTrue("Should be 2 NEW idle , found " + pool.getNumIdle(),pool.getNumIdle()
== 2 &&
  +                ((TimeTest)pool.borrowObject()).getCreateTime() != creationTime[0].longValue()
&&
  +                ((TimeTest)pool.borrowObject()).getCreateTime() != creationTime[1].longValue());
       }
   
       public void testMinIdle() 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