avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/pool/test PoolComparisonProfileAbstract.java MultiThreadedPoolComparisonProfile.java SingleThreadedPoolComparisonProfile.java
Date Sat, 02 Feb 2002 17:31:33 GMT
leif        02/02/02 09:31:33

  Modified:    src/scratchpad/org/apache/avalon/excalibur/pool/test
                        SingleThreadedPoolComparisonProfile.java
  Added:       src/scratchpad/org/apache/avalon/excalibur/pool/test
                        PoolComparisonProfileAbstract.java
                        MultiThreadedPoolComparisonProfile.java
  Log:
  Added Multithreaded Pool Comparison Tests
  
  Revision  Changes    Path
  1.3       +25 -531   jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/pool/test/SingleThreadedPoolComparisonProfile.java
  
  Index: SingleThreadedPoolComparisonProfile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/pool/test/SingleThreadedPoolComparisonProfile.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SingleThreadedPoolComparisonProfile.java	2 Feb 2002 15:16:05 -0000	1.2
  +++ SingleThreadedPoolComparisonProfile.java	2 Feb 2002 17:31:32 -0000	1.3
  @@ -20,6 +20,7 @@
   import org.apache.avalon.excalibur.pool.VariableSizePool;
   
   import org.apache.avalon.framework.activity.Disposable;
  +import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.framework.logger.LogKitLogger;
   
  @@ -28,38 +29,17 @@
    *  given a single access thread.
    *
    * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
  - * @version $Id: SingleThreadedPoolComparisonProfile.java,v 1.2 2002/02/02 15:16:05 leif Exp $
  + * @version $Id: SingleThreadedPoolComparisonProfile.java,v 1.3 2002/02/02 17:31:32 leif Exp $
    */
   public class SingleThreadedPoolComparisonProfile
  -    extends TestCase
  +    extends PoolComparisonProfileAbstract
   {
  -    /**
  -     * The TEST_SIZE defines the overall size of the tests.  Decreasing this will
  -     *  decrease the time the test takes to run, but also decrease its efficiency.
  -     */
  -    protected static final int TEST_SIZE = 50000;
  -
  -    private Logger m_logger;
  -    private Logger m_poolLogger;
  -    
       /*---------------------------------------------------------------
        * Constructors
        *-------------------------------------------------------------*/
       public SingleThreadedPoolComparisonProfile(String name)
       {
           super(name);
  -
  -        // Set to debug to see more useful information.
  -        org.apache.log.Logger logger = 
  -            org.apache.log.Hierarchy.getDefaultHierarchy().getLoggerFor( "test" );
  -        logger.setPriority( org.apache.log.Priority.INFO );
  -        m_logger = new LogKitLogger( logger );
  -        
  -        // The output from the pools is too much data to be useful, so use a different logger.
  -        org.apache.log.Logger poolLogger =
  -            org.apache.log.Hierarchy.getDefaultHierarchy().getLoggerFor( "pool" );
  -        poolLogger.setPriority( org.apache.log.Priority.INFO );
  -        m_poolLogger = new LogKitLogger( poolLogger );
       }
       
       /*---------------------------------------------------------------
  @@ -93,7 +73,7 @@
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  -        generalTest( name, poolA, poolB, 10, poolableClass );
  +        generalTest( name, poolA, poolB, 10, factory );
       }
   
       /**
  @@ -124,7 +104,7 @@
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  -        generalTest( name, poolA, poolB, 20, poolableClass );
  +        generalTest( name, poolA, poolB, 20, factory );
       }
   
       /**
  @@ -155,7 +135,7 @@
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  -        generalTest( name, poolA, poolB, 10, poolableClass );
  +        generalTest( name, poolA, poolB, 10, factory );
       }
   
       /**
  @@ -186,7 +166,7 @@
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  -        generalTest( name, poolA, poolB, 20, poolableClass );
  +        generalTest( name, poolA, poolB, 20, factory );
       }
   
       /**
  @@ -217,7 +197,7 @@
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  -        generalTest( name, poolA, poolB, 10, poolableClass );
  +        generalTest( name, poolA, poolB, 10, factory );
       }
   
       /**
  @@ -248,382 +228,7 @@
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  -        generalTest( name, poolA, poolB, 20, poolableClass );
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * SoftResourceLimitingPool vs ResourceLimitingPool TestCases
  -     *-------------------------------------------------------------*/
  -    /**
  -     * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
  -     * <p>
  -     * Test will use pools with a max size of 10, while getting up to 10 at a time,
  -     *  Poolables are small objects.
  -     */
  -    public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables()
  -        throws Exception
  -    {
  -        String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
  -        
  -        Class         poolableClass = SmallPoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = false;
  -        boolean       blocking     = false;
  -        long          blockTimeout = 0;
  -        long          trimInterval = 0;
  -        
  -        SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
  -        poolA.enableLogging( m_poolLogger );
  -        poolA.initialize();
  -        
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 10, poolableClass );
  -    }
  -
  -    /**
  -     * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
  -     * <p>
  -     * Test will use pools with a max size of 10, while getting up to 20 at a time,
  -     *  Poolables are small objects.
  -     */
  -    public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_SmallPoolables()
  -        throws Exception
  -    {
  -        String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_SmallPoolables";
  -        
  -        Class         poolableClass = SmallPoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = false;
  -        boolean       blocking     = false;
  -        long          blockTimeout = 0;
  -        long          trimInterval = 0;
  -        
  -        SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
  -        poolA.enableLogging( m_poolLogger );
  -        poolA.initialize();
  -        
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 20, poolableClass );
  -    }
  -
  -    /**
  -     * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
  -     * <p>
  -     * Test will use pools with a max size of 10, while getting up to 10 at a time,
  -     *  Poolables are medium objects.
  -     */
  -    public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables()
  -        throws Exception
  -    {
  -        String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
  -        
  -        Class         poolableClass = MediumPoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = false;
  -        boolean       blocking     = false;
  -        long          blockTimeout = 0;
  -        long          trimInterval = 0;
  -        
  -        SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
  -        poolA.enableLogging( m_poolLogger );
  -        poolA.initialize();
  -        
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 10, poolableClass );
  -    }
  -
  -    /**
  -     * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
  -     * <p>
  -     * Test will use pools with a max size of 10, while getting up to 20 at a time,
  -     *  Poolables are medium objects.
  -     */
  -    public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_MediumPoolables()
  -        throws Exception
  -    {
  -        String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_MediumPoolables";
  -        
  -        Class         poolableClass = MediumPoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = false;
  -        boolean       blocking     = false;
  -        long          blockTimeout = 0;
  -        long          trimInterval = 0;
  -        
  -        SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
  -        poolA.enableLogging( m_poolLogger );
  -        poolA.initialize();
  -        
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 20, poolableClass );
  -    }
  -
  -    /**
  -     * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
  -     * <p>
  -     * Test will use pools with a max size of 10, while getting up to 10 at a time,
  -     *  Poolables are large objects.
  -     */
  -    public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables()
  -        throws Exception
  -    {
  -        String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
  -        
  -        Class         poolableClass = LargePoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = false;
  -        boolean       blocking     = false;
  -        long          blockTimeout = 0;
  -        long          trimInterval = 0;
  -        
  -        SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
  -        poolA.enableLogging( m_poolLogger );
  -        poolA.initialize();
  -        
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 10, poolableClass );
  -    }
  -
  -    /**
  -     * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
  -     * <p>
  -     * Test will use pools with a max size of 10, while getting up to 20 at a time,
  -     *  Poolables are large objects.
  -     */
  -    public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_LargePoolables()
  -        throws Exception
  -    {
  -        String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_LargePoolables";
  -        
  -        Class         poolableClass = LargePoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = false;
  -        boolean       blocking     = false;
  -        long          blockTimeout = 0;
  -        long          trimInterval = 0;
  -        
  -        SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
  -        poolA.enableLogging( m_poolLogger );
  -        poolA.initialize();
  -        
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 20, poolableClass );
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * HardResourceLimitingPool vs ResourceLimitingPool TestCases
  -     *-------------------------------------------------------------*/
  -    /**
  -     * Compare the HardResourceLimitingPool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a HardResourceLimitingPool.
  -     * <p>
  -     * Test will use pools with a max size of 10, while getting up to 10 at a time,
  -     *  Poolables are small objects.
  -     */
  -    public void testCompare_HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables()
  -        throws Exception
  -    {
  -        String name = "HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
  -        
  -        Class         poolableClass = SmallPoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = true;
  -        boolean       blocking     = false;
  -        long          blockTimeout = 0;
  -        long          trimInterval = 0;
  -        
  -        HardResourceLimitingPool poolA = new HardResourceLimitingPool( factory, min, max );
  -        poolA.enableLogging( m_poolLogger );
  -        poolA.initialize();
  -        
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 10, poolableClass );
  -    }
  -
  -    /**
  -     * Compare the HardResourceLimitingPool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a HardResourceLimitingPool.
  -     * <p>
  -     * Test will use pools with a max size of 10, while getting up to 10 at a time,
  -     *  Poolables are medium objects.
  -     */
  -    public void testCompare_HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables()
  -        throws Exception
  -    {
  -        String name = "HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
  -        
  -        Class         poolableClass = MediumPoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = true;
  -        boolean       blocking     = false;
  -        long          blockTimeout = 0;
  -        long          trimInterval = 0;
  -        
  -        HardResourceLimitingPool poolA = new HardResourceLimitingPool( factory, min, max );
  -        poolA.enableLogging( m_poolLogger );
  -        poolA.initialize();
  -        
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 10, poolableClass );
  -    }
  -
  -    /**
  -     * Compare the HardResourceLimitingPool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a HardResourceLimitingPool.
  -     * <p>
  -     * Test will use pools with a max size of 10, while getting up to 10 at a time,
  -     *  Poolables are large objects.
  -     */
  -    public void testCompare_HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables()
  -        throws Exception
  -    {
  -        String name = "HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
  -        
  -        Class         poolableClass = LargePoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = true;
  -        boolean       blocking     = false;
  -        long          blockTimeout = 0;
  -        long          trimInterval = 0;
  -        
  -        HardResourceLimitingPool poolA = new HardResourceLimitingPool( factory, min, max );
  -        poolA.enableLogging( m_poolLogger );
  -        poolA.initialize();
  -        
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 10, poolableClass );
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * FixedSizePool vs ResourceLimitingPool TestCases
  -     *-------------------------------------------------------------*/
  -    /**
  -     * Compare the FixedSizePool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a FixedSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 10, while getting up to 10 at a time,
  -     *  Poolables are small objects.
  -     */
  -    public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables()
  -        throws Exception
  -    {
  -        String name = "FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
  -        
  -        Class         poolableClass = SmallPoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = true;
  -        boolean       blocking     = false;
  -        long          blockTimeout = 0;
  -        long          trimInterval = 0;
  -        
  -        FixedSizePool poolA = new FixedSizePool( factory, max );
  -        
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -        
  -        generalTest( name, poolA, poolB, 10, poolableClass );
  -    }
  -    
  -    /**
  -     * Compare the FixedSizePool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a FixedSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 10, while getting up to 10 at a time,
  -     *  Poolables are medium objects.
  -     */
  -    public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables()
  -        throws Exception
  -    {
  -        String name = "FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
  -        
  -        Class         poolableClass = MediumPoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = true;
  -        boolean       blocking     = false;
  -        long          blockTimeout = 0;
  -        long          trimInterval = 0;
  -        
  -        FixedSizePool poolA = new FixedSizePool( factory, max );
  -        
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -        
  -        generalTest( name, poolA, poolB, 10, poolableClass );
  -    }
  -    
  -    /**
  -     * Compare the FixedSizePool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a FixedSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 10, while getting up to 10 at a time,
  -     *  Poolables are large objects.
  -     */
  -    public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables()
  -        throws Exception
  -    {
  -        String name = "FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
  -        
  -        Class         poolableClass = LargePoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = true;
  -        boolean       blocking     = false;
  -        long          blockTimeout = 0;
  -        long          trimInterval = 0;
  -        
  -        FixedSizePool poolA = new FixedSizePool( factory, max );
  -        
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -        
  -        generalTest( name, poolA, poolB, 10, poolableClass );
  +        generalTest( name, poolA, poolB, 20, factory );
       }
       
       /*---------------------------------------------------------------
  @@ -655,7 +260,7 @@
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
           
  -        generalTest( name, poolA, poolB, 10, poolableClass );
  +        generalTest( name, poolA, poolB, 10, factory );
       }
       
       /**
  @@ -684,7 +289,7 @@
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
           
  -        generalTest( name, poolA, poolB, 10, poolableClass );
  +        generalTest( name, poolA, poolB, 10, factory );
       }
       
       /**
  @@ -713,154 +318,43 @@
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
           
  -        generalTest( name, poolA, poolB, 10, poolableClass );
  +        generalTest( name, poolA, poolB, 10, factory );
       }
       
       /*---------------------------------------------------------------
  -     * Test Classes
  +     * PoolComparisonProfileAbstract Methods
        *-------------------------------------------------------------*/
  -    public static class SmallPoolable
  -        implements Poolable
  -    {
  -        int a;
  -    }
  -
  -    public static class MediumPoolable
  -        implements Poolable
  -    {
  -        int[] a = new int[100];
  -    }
  -
  -    public static class LargePoolable
  -        implements Poolable
  -    {
  -        int[][] a = new int[100][50];
  -    }
  -    
  -    /*---------------------------------------------------------------
  -     * Utility Methods
  -     *-------------------------------------------------------------*/
  -    private void resetMemory()
  -    {
  -        System.gc();
  -        System.gc();
  -        
  -        // Let the system settle down.
  -        try
  -        {
  -            Thread.sleep( 50 );
  -        }
  -        catch (InterruptedException e ) {}
  -        Runtime runtime = Runtime.getRuntime();
  -        m_logger.debug( "Memory: " + ( runtime.totalMemory() - runtime.freeMemory() ) );
  -    }
  -    
  -    private String getShortClassName( Object o )
  -    {
  -        String name = o.getClass().getName();
  -        int pos = name.lastIndexOf('.');
  -        if ( pos > 0 )
  -        {
  -            name = name.substring( pos + 1 );
  -        }
  -        return name;
  -    }
  -    
  -    /**
  -     * The guts of the various test cases.  Will dispose the pools
  -     */
  -    private void generalTest(String name, Pool poolA, Pool poolB, int gets, Class poolableClass)
  +    protected long getPoolRunTime( Pool pool, int gets )
           throws Exception
       {
  -        m_logger.info( "Test Case: " + name );
  -        
  -        // Get the short class names
  -        final String poolAName = getShortClassName( poolA );
  -        final String poolBName = getShortClassName( poolB );
  -        
           // Start clean
           resetMemory();
           
  -        // Get a baseline speed for object creation
  -        final long noPoolStartTime = System.currentTimeMillis();
  -        for( int i = 0; i < TEST_SIZE; i++ )
  -        {
  -            final Poolable a1 = (Poolable)poolableClass.newInstance();
  -        }
  -        final long noPoolDuration = System.currentTimeMillis() - noPoolStartTime;
  -        m_logger.info( "     Unpooled time = " + noPoolDuration + "ms. to use " + TEST_SIZE + " objects." );
  -        resetMemory();
  -        
  -        
  -        // Get the time for poolA
  -        final long poolAStartTime = System.currentTimeMillis();
  -        final Poolable[] poolATmp = new Poolable[gets];
  -        final int poolALoops = TEST_SIZE / gets;
  -        for( int i = 0; i < poolALoops; i++ )
  +        final long startTime = System.currentTimeMillis();
  +        final Poolable[] poolTmp = new Poolable[gets];
  +        final int loops = TEST_SIZE / gets;
  +        for( int i = 0; i < loops; i++ )
           {
               // Get some Poolables
               for ( int j = 0; j < gets; j++ )
               {
  -                poolATmp[j] = poolA.get();
  +                poolTmp[j] = pool.get();
               }
               
               // Put the Poolables back
               for ( int j = 0; j < gets; j++ )
               {
  -                poolA.put( poolATmp[j] );
  -                poolATmp[j] = null;
  +                pool.put( poolTmp[j] );
  +                poolTmp[j] = null;
               }
           }
  -        final long poolADuration = System.currentTimeMillis() - poolAStartTime;
  -        // Dispose if necessary
  -        if ( poolA instanceof Disposable ) {
  -            ((Disposable)poolA).dispose();
  -        }
  -        poolA = null;
  -        m_logger.info( "     " + poolAName + " time = " + poolADuration + "ms. to use " + TEST_SIZE + " objects, " + gets + " at a time." );
  -        resetMemory();
  -        
  +        final long duration = System.currentTimeMillis() - startTime;
           
  -        // Get the time for poolB
  -        final long poolBStartTime = System.currentTimeMillis();
  -        final Poolable[] poolBTmp = new Poolable[gets];
  -        final int poolBLoops = TEST_SIZE / gets;
  -        for( int i = 0; i < poolBLoops; i++ )
  -        {
  -            // Get some Poolables
  -            for ( int j = 0; j < gets; j++ )
  -            {
  -                poolBTmp[j] = poolB.get();
  -            }
  -            
  -            // Put the Poolables back
  -            for ( int j = 0; j < gets; j++ )
  -            {
  -                poolB.put( poolBTmp[j] );
  -                poolBTmp[j] = null;
  -            }
  -        }
  -        final long poolBDuration = System.currentTimeMillis() - poolBStartTime;
           // Dispose if necessary
  -        if ( poolB instanceof Disposable ) {
  -            ((Disposable)poolB).dispose();
  +        if ( pool instanceof Disposable ) {
  +            ((Disposable)pool).dispose();
           }
  -        poolB = null;
  -        m_logger.info( "     " + poolBName + " time = " + poolBDuration + "ms. to use " + TEST_SIZE + " objects, " + gets + " at a time." );
  -        resetMemory();
           
  -        // Show a summary
  -        if ( m_logger.isInfoEnabled() )
  -        {
  -            double mult;
  -            mult = ( poolADuration > 0 ? ( noPoolDuration * 100 / poolADuration ) / 100.0 : Float.POSITIVE_INFINITY );
  -            m_logger.info( "  => " + poolAName + " is " + mult + " X as fast as not pooling." );
  -            
  -            mult = ( poolBDuration > 0 ? ( noPoolDuration * 100 / poolBDuration ) / 100.0 : Float.POSITIVE_INFINITY );
  -            m_logger.info( "  => " + poolBName + " is " + mult + " X as fast as not pooling." );
  -            
  -            mult = ( poolBDuration > 0 ? ( poolADuration * 100 / poolBDuration ) / 100.0 : Float.POSITIVE_INFINITY );
  -            m_logger.info( "  => " + poolBName + " is " + mult + " X as fast as " + poolAName + "." );
  -        }
  +        return duration;
       }
   }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/pool/test/PoolComparisonProfileAbstract.java
  
  Index: PoolComparisonProfileAbstract.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.pool.test;
  
  import junit.framework.TestCase;
  
  import org.apache.avalon.excalibur.pool.FixedSizePool;
  import org.apache.avalon.excalibur.pool.HardResourceLimitingPool;
  import org.apache.avalon.excalibur.pool.ObjectFactory;
  import org.apache.avalon.excalibur.pool.Pool;
  import org.apache.avalon.excalibur.pool.Poolable;
  import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
  import org.apache.avalon.excalibur.pool.SingleThreadedPool;
  import org.apache.avalon.excalibur.pool.SoftResourceLimitingPool;
  import org.apache.avalon.excalibur.pool.VariableSizePool;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.LogKitLogger;
  
  /**
   * Used as a basis for the PoolComparisonProfile Tests
   *
   * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
   * @version $Id: PoolComparisonProfileAbstract.java,v 1.1 2002/02/02 17:31:32 leif Exp $
   */
  public abstract class PoolComparisonProfileAbstract
      extends TestCase
  {
      /**
       * The TEST_SIZE defines the overall size of the tests.  Decreasing this will
       *  decrease the time the test takes to run, but also decrease its efficiency.
       */
      protected static final int TEST_SIZE = 50000;
  
      protected Logger m_logger;
      protected Logger m_poolLogger;
      
      /*---------------------------------------------------------------
       * Constructors
       *-------------------------------------------------------------*/
      public PoolComparisonProfileAbstract(String name)
      {
          super(name);
  
          // Set to debug to see more useful information.
          org.apache.log.Logger logger = 
              org.apache.log.Hierarchy.getDefaultHierarchy().getLoggerFor( "test" );
          logger.setPriority( org.apache.log.Priority.INFO );
          m_logger = new LogKitLogger( logger );
          
          // The output from the pools is too much data to be useful, so use a different logger.
          org.apache.log.Logger poolLogger =
              org.apache.log.Hierarchy.getDefaultHierarchy().getLoggerFor( "pool" );
          poolLogger.setPriority( org.apache.log.Priority.INFO );
          m_poolLogger = new LogKitLogger( poolLogger );
      }
      
      /*---------------------------------------------------------------
       * SoftResourceLimitingPool vs ResourceLimitingPool TestCases
       *-------------------------------------------------------------*/
      /**
       * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are small objects.
       */
      public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables()
          throws Exception
      {
          String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
          
          Class         poolableClass = SmallPoolable.class;
          ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
          
          SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
          
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 10, factory );
      }
  
      /**
       * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 20 at a time,
       *  Poolables are small objects.
       */
      public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_SmallPoolables()
          throws Exception
      {
          String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_SmallPoolables";
          
          Class         poolableClass = SmallPoolable.class;
          ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
          
          SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
          
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 20, factory );
      }
  
      /**
       * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are medium objects.
       */
      public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables()
          throws Exception
      {
          String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
          
          Class         poolableClass = MediumPoolable.class;
          ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
          
          SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
          
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 10, factory );
      }
  
      /**
       * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 20 at a time,
       *  Poolables are medium objects.
       */
      public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_MediumPoolables()
          throws Exception
      {
          String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_MediumPoolables";
          
          Class         poolableClass = MediumPoolable.class;
          ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
          
          SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
          
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 20, factory );
      }
  
      /**
       * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are large objects.
       */
      public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables()
          throws Exception
      {
          String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
          
          Class         poolableClass = LargePoolable.class;
          ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
          
          SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
          
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 10, factory );
      }
  
      /**
       * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 20 at a time,
       *  Poolables are large objects.
       */
      public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_LargePoolables()
          throws Exception
      {
          String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_LargePoolables";
          
          Class         poolableClass = LargePoolable.class;
          ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
          
          SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
          
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 20, factory );
      }
  
      /*---------------------------------------------------------------
       * HardResourceLimitingPool vs ResourceLimitingPool TestCases
       *-------------------------------------------------------------*/
      /**
       * Compare the HardResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a HardResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are small objects.
       */
      public void testCompare_HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables()
          throws Exception
      {
          String name = "HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
          
          Class         poolableClass = SmallPoolable.class;
          ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = true;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
          
          HardResourceLimitingPool poolA = new HardResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
          
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 10, factory );
      }
  
      /**
       * Compare the HardResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a HardResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are medium objects.
       */
      public void testCompare_HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables()
          throws Exception
      {
          String name = "HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
          
          Class         poolableClass = MediumPoolable.class;
          ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = true;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
          
          HardResourceLimitingPool poolA = new HardResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
          
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 10, factory );
      }
  
      /**
       * Compare the HardResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a HardResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are large objects.
       */
      public void testCompare_HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables()
          throws Exception
      {
          String name = "HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
          
          Class         poolableClass = LargePoolable.class;
          ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = true;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
          
          HardResourceLimitingPool poolA = new HardResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
          
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 10, factory );
      }
  
      /*---------------------------------------------------------------
       * FixedSizePool vs ResourceLimitingPool TestCases
       *-------------------------------------------------------------*/
      /**
       * Compare the FixedSizePool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a FixedSizePool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are small objects.
       */
      public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables()
          throws Exception
      {
          String name = "FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
          
          Class         poolableClass = SmallPoolable.class;
          ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = true;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
          
          FixedSizePool poolA = new FixedSizePool( factory, max );
          
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
          
          generalTest( name, poolA, poolB, 10, factory );
      }
      
      /**
       * Compare the FixedSizePool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a FixedSizePool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are medium objects.
       */
      public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables()
          throws Exception
      {
          String name = "FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
          
          Class         poolableClass = MediumPoolable.class;
          ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = true;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
          
          FixedSizePool poolA = new FixedSizePool( factory, max );
          
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
          
          generalTest( name, poolA, poolB, 10, factory );
      }
      
      /**
       * Compare the FixedSizePool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a FixedSizePool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are large objects.
       */
      public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables()
          throws Exception
      {
          String name = "FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
          
          Class         poolableClass = LargePoolable.class;
          ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = true;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
          
          FixedSizePool poolA = new FixedSizePool( factory, max );
          
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
          
          generalTest( name, poolA, poolB, 10, factory );
      }
      
      /*---------------------------------------------------------------
       * Test Classes
       *-------------------------------------------------------------*/
      public static class SmallPoolable
          implements Poolable
      {
          int a;
      }
  
      public static class MediumPoolable
          implements Poolable
      {
          int[] a = new int[100];
      }
  
      public static class LargePoolable
          implements Poolable
      {
          int[][] a = new int[100][50];
      }
      
      /**
       * Dummy class used for timing test cases where no pooling is done.
       */
      public static class NoPoolingPool
          implements Pool, LogEnabled
      {
          private ObjectFactory m_factory;
          private Logger        m_logger;
          
          public NoPoolingPool( ObjectFactory factory )
          {
              m_factory = factory;
          }
          
          public void enableLogging( Logger logger )
          {
              m_logger = logger;
          }
          
          public Poolable get() throws Exception
          {
              return (Poolable)m_factory.newInstance();
          }
          
          public void put( Poolable poolable )
          {
              try {
                  m_factory.decommission( poolable );
              }
              catch ( Exception e )
              {
                  m_logger.debug( "Error decommissioning object", e );
              }
          }
      }
      
      /*---------------------------------------------------------------
       * Utility Methods
       *-------------------------------------------------------------*/
      protected void resetMemory()
      {
          System.gc();
          System.gc();
          
          // Let the system settle down.
          try
          {
              Thread.sleep( 50 );
          }
          catch (InterruptedException e ) {}
          Runtime runtime = Runtime.getRuntime();
          m_logger.debug( "Memory: " + ( runtime.totalMemory() - runtime.freeMemory() ) );
      }
      
      protected String getShortClassName( Object o )
      {
          String name = o.getClass().getName();
          int pos = name.lastIndexOf('.');
          if ( pos > 0 )
          {
              name = name.substring( pos + 1 );
          }
          return name;
      }
      
      protected abstract long getPoolRunTime( Pool pool, int gets )
          throws Exception;
      
      /**
       * The guts of the various test cases.  Will dispose the pools
       */
      protected void generalTest(String name, Pool poolA, Pool poolB, int gets, ObjectFactory factory)
          throws Exception
      {
          m_logger.info( "Test Case: " + name );
          
          // Get the short class names
          final String poolAName = getShortClassName( poolA );
          final String poolBName = getShortClassName( poolB );
          
          // Start clean
          resetMemory();
          
          // Get a baseline speed for object creation
          NoPoolingPool poolBase = new NoPoolingPool( factory );
          poolBase.enableLogging( m_poolLogger );
          final long noPoolDuration = getPoolRunTime( poolBase, gets );
          m_logger.info( "     Unpooled time = " + noPoolDuration + "ms. to use " + TEST_SIZE + " objects." );
          resetMemory();
          
          
          // Get the time for poolA
          final long poolADuration = getPoolRunTime( poolA, gets );
          m_logger.info( "     " + poolAName + " time = " + poolADuration + "ms. to use " + TEST_SIZE + " objects, " + gets + " at a time." );
          resetMemory();
          
          
          // Get the time for poolB
          final long poolBDuration = getPoolRunTime( poolB, gets );
          m_logger.info( "     " + poolBName + " time = " + poolBDuration + "ms. to use " + TEST_SIZE + " objects, " + gets + " at a time." );
          resetMemory();
          
          // Show a summary
          if ( m_logger.isInfoEnabled() )
          {
              double mult;
              mult = ( poolADuration > 0 ? ( noPoolDuration * 100 / poolADuration ) / 100.0 : Float.POSITIVE_INFINITY );
              m_logger.info( "  => " + poolAName + " is " + mult + " X as fast as not pooling." );
              
              mult = ( poolBDuration > 0 ? ( noPoolDuration * 100 / poolBDuration ) / 100.0 : Float.POSITIVE_INFINITY );
              m_logger.info( "  => " + poolBName + " is " + mult + " X as fast as not pooling." );
              
              mult = ( poolBDuration > 0 ? ( poolADuration * 100 / poolBDuration ) / 100.0 : Float.POSITIVE_INFINITY );
              m_logger.info( "  => " + poolBName + " is " + mult + " X as fast as " + poolAName + "." );
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/pool/test/MultiThreadedPoolComparisonProfile.java
  
  Index: MultiThreadedPoolComparisonProfile.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.pool.test;
  
  import junit.framework.TestCase;
  
  import org.apache.avalon.excalibur.pool.FixedSizePool;
  import org.apache.avalon.excalibur.pool.HardResourceLimitingPool;
  import org.apache.avalon.excalibur.pool.ObjectFactory;
  import org.apache.avalon.excalibur.pool.Pool;
  import org.apache.avalon.excalibur.pool.Poolable;
  import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
  import org.apache.avalon.excalibur.pool.SingleThreadedPool;
  import org.apache.avalon.excalibur.pool.SoftResourceLimitingPool;
  import org.apache.avalon.excalibur.pool.VariableSizePool;
  import org.apache.avalon.excalibur.testcase.CascadingAssertionFailedError;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.LogKitLogger;
  
  /**
   * This is used to profile and compare various pool implementations
   *  given a single access thread.
   *
   * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
   * @version $Id: MultiThreadedPoolComparisonProfile.java,v 1.1 2002/02/02 17:31:32 leif Exp $
   */
  public class MultiThreadedPoolComparisonProfile
      extends PoolComparisonProfileAbstract
  {
      protected static final int THREADS = 10;
      
      private Object  m_semaphore = new Object();
      private int     m_startedCount;
      private boolean m_latched;
      private int     m_completedCount;
      private int     m_getCount;
      private Exception m_exception;
      
      /*---------------------------------------------------------------
       * Constructors
       *-------------------------------------------------------------*/
      public MultiThreadedPoolComparisonProfile(String name)
      {
          super(name);
      }
      
      /*---------------------------------------------------------------
       * PoolComparisonProfileAbstract Methods
       *-------------------------------------------------------------*/
      protected long getPoolRunTime( final Pool pool, final int gets )
          throws Exception
      {
          if ( gets % THREADS != 0 )
          {
              fail( "gets must be evenly divisible by THREADS");
          }
          
          m_startedCount = 0;
          m_latched = false;
          m_completedCount = 0;
          m_getCount = 0;
          m_exception = null;
          
          // Create the threads.  Implement a simple latch so they all run at the same time
          Thread[] threads = new Thread[THREADS];
          for ( int i = 0; i < THREADS; i++ )
          {
              Runnable runnable = new Runnable()
              {
                  public void run()
                  {
                      // Need all threads to wait until all the others are ready.
                      synchronized(m_semaphore)
                      {
                          m_startedCount++;
                          m_logger.debug( "Started " + m_startedCount + " test threads." );
                          if ( m_startedCount >= THREADS )
                          {
                              m_semaphore.notifyAll();
                          }
                          while ( !m_latched )
                          {
                              try
                              {
                                  m_semaphore.wait();
                              }
                              catch ( InterruptedException e ) {}
                          }
                      }
                      
                      try
                      {
                          // Perform this threads part of the test.
                          final int cnt = gets / THREADS;
                          final Poolable[] poolTmp = new Poolable[cnt];
                          final int loops = TEST_SIZE / gets;
                          for( int i = 0; i < loops; i++ )
                          {
                              // Get some Poolables
                              for ( int j = 0; j < cnt; j++ )
                              {
                                  try
                                  {
                                      poolTmp[j] = pool.get();
                                      synchronized(m_semaphore)
                                      {
                                          m_getCount++;
                                      }
                                  }
                                  catch ( Exception e )
                                  {
                                      m_poolLogger.error( "Unexpected error", e );
                                      
                                      synchronized(m_semaphore)
                                      {
                                          if (m_exception == null) {
                                              m_exception = e;
                                          }
                                      }
                                      return;
                                  }
                              }
                              
                              // Make the loops hold the poolables longer than they are released, but only slightly.
                              Thread.yield();
                              
                              // Put the Poolables back
                              for ( int j = 0; j < cnt; j++ )
                              {
                                  pool.put( poolTmp[j] );
                                  synchronized(m_semaphore)
                                  {
                                      m_getCount--;
                                  }
                                  poolTmp[j] = null;
                              }
                          }
                      }
                      
                      
                      finally
                      {
                          // Say that we are done
                          synchronized(m_semaphore)
                          {
                              m_completedCount++;
                              m_logger.debug( m_completedCount + " test threads completed." );
                              m_semaphore.notifyAll();
                          }
                      }
                  }
              };
              
              threads[i] = new Thread( runnable, "Test_Thread_" + i );
              threads[i].start();
          }
  
          // Wait for all of the threads to start before starting to time the test
          synchronized(m_semaphore)
          {
              while ( m_startedCount < THREADS ) {
                  m_semaphore.wait();
              }
              
              // Start clean
              resetMemory();
              
              // Release the threads.
              m_latched = true;
              m_logger.debug( "Main thread released the test thread latch." );
              m_semaphore.notifyAll();
          }
          // Start timing
          long startTime = System.currentTimeMillis();
          
          // Wait for all of the threads to complete
          synchronized(m_semaphore)
          {
              m_logger.debug( "Waiting for test threads to all complete." );
              while ( m_completedCount < THREADS ) {
                  try
                  {
                      m_semaphore.wait();
                  }
                  catch ( InterruptedException e ) {}
              }
          }
          final long duration = System.currentTimeMillis() - startTime;
          m_logger.debug( "All test threads completed." );
          
          if ( m_exception != null )
          {
              throw new CascadingAssertionFailedError( "Exception in test thread.", m_exception );
          }
          
          assertTrue( "m_getCount == 0 (" + m_getCount + ")", m_getCount == 0 );
          
          // Dispose if necessary
          if ( pool instanceof Disposable ) {
              ((Disposable)pool).dispose();
          }
          
          return duration;
      }
  }
  
  
  

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


Mime
View raw message