avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosu...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/test ContainerProfile.roles ContainerProfile.java
Date Thu, 07 Mar 2002 07:04:22 GMT
leosutic    02/03/06 23:04:22

  Modified:    src/scratchpad/org/apache/avalon/excalibur/system/test
                        ContainerProfile.roles ContainerProfile.java
  Log:
  First cut of modifications
  
  Revision  Changes    Path
  1.2       +1 -17     jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/test/ContainerProfile.roles
  
  Index: ContainerProfile.roles
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/test/ContainerProfile.roles,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ContainerProfile.roles	19 Feb 2002 14:54:23 -0000	1.1
  +++ ContainerProfile.roles	7 Mar 2002 07:04:22 -0000	1.2
  @@ -1,17 +1 @@
  -<test>
  -  <role name="org.apache.avalon.excalibur.datasource.DataSourceComponent">
  -    <component shorthand="datasource"
  -               class="org.apache.avalon.excalibur.datasource.JdbcDataSource"
  -               handler="org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler"/>
  -  </role>
  -  <role name="org.apache.avalon.excalibur.monitor.Monitor">
  -    <component shorthand="monitor"
  -               class="org.apache.avalon.excalibur.monitor.ActiveMonitor"
  -               handler="org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler"/>
  -  </role>
  -  <role name="org.apache.avalon.excalibur.xml.Parser">
  -  <component shorthand="parser"
  -             class="org.apache.avalon.excalibur.xml.JaxpParser"
  -             handler="org.apache.avalon.excalibur.system.handler.PoolableComponentHandler"/>
  -  </role>
  -</test>
  +<test>
  <role name="org.apache.avalon.excalibur.datasource.DataSourceComponent">
   <component shorthand="datasource"
               class="org.apache.avalon.excalibur.datasource.JdbcDataSource"
              handler="org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler"/>
 </role>
  <role name="org.apache.avalon.excalibur.monitor.Monitor">
    <component
shorthand="monitor"
               class="org.apache.avalon.excalibur.monitor.ActiveMonitor"
              handler="org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler"/>
 </role>
  <role name="org.apache.avalon.excalibur.xml.Parser">
  <component
shorthand="parser"
             class="org.apache.avalon.excalibur.xml.JaxpParser"
      
      handler="org.apache.avalon.excalibur.system.handler.PoolableComponentHandler"/>
 </role>
</test>

  \ No newline at end of file
  
  
  
  1.9       +89 -87    jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/test/ContainerProfile.java
  
  Index: ContainerProfile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/test/ContainerProfile.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ContainerProfile.java	4 Mar 2002 21:21:16 -0000	1.8
  +++ ContainerProfile.java	7 Mar 2002 07:04:22 -0000	1.9
  @@ -10,6 +10,7 @@
   import junit.framework.TestCase;
   
   import org.apache.avalon.excalibur.system.*;
  +import org.apache.avalon.excalibur.system.util.*;
   import org.apache.avalon.excalibur.component.*;
   import org.apache.avalon.excalibur.logger.*;
   import org.apache.avalon.excalibur.testcase.*;
  @@ -31,7 +32,7 @@
    * Used as a basis for the PoolComparisonProfile Tests
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version $Id: ContainerProfile.java,v 1.8 2002/03/04 21:21:16 bloritsch Exp $
  + * @version $Id: ContainerProfile.java,v 1.9 2002/03/07 07:04:22 leosutic Exp $
    */
   public final class ContainerProfile
       extends TestCase
  @@ -40,22 +41,22 @@
        * 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 static final int      THREADS     = 100;
  -
  +    protected static final int      TEST_SIZE   = 5000;
  +    protected static final int      THREADS     = 20;
  +    
       protected static Throwable      m_throwable = null;
       protected static int            m_getCount  = 0;
  -
  +    
       protected Logger                m_logger;
       protected org.apache.log.Logger m_logKitLogger;
  -
  +    
       /*---------------------------------------------------------------
        * Constructors
        *-------------------------------------------------------------*/
       public ContainerProfile(String name)
       {
           super(name);
  -
  +        
           // Set to debug to see more useful information.
           org.apache.log.Logger logger =
               org.apache.log.Hierarchy.getDefaultHierarchy().getLoggerFor( "test" );
  @@ -63,7 +64,7 @@
           m_logKitLogger = logger;
           m_logger = new LogKitLogger( logger );
       }
  -
  +    
       /*---------------------------------------------------------------
        * ECM vs. ContainerManager StartTimes
        *-------------------------------------------------------------*/
  @@ -74,81 +75,81 @@
           throws Exception
       {
           resetMemory(); // Start clean
  -
  +        
           long ecmStart = System.currentTimeMillis();
  -            ExcaliburComponentManager manager = new ExcaliburComponentManager();
  -            Context context = new DefaultContext();
  -            manager.setLogger(m_logKitLogger);
  -            manager.contextualize( context );
  -            DefaultLogKitManager logmanager = new DefaultLogKitManager();
  -            logmanager.setLogger(m_logKitLogger);
  -            logmanager.contextualize(context);
  -            logmanager.configure( getLogKitConfig() );
  -            manager.setLogKitManager(logmanager);
  -            manager.configure( getContainerConfig() );
  -            manager.initialize();
  +        ExcaliburComponentManager manager = new ExcaliburComponentManager();
  +        Context context = new DefaultContext();
  +        manager.setLogger(m_logKitLogger);
  +        manager.contextualize( context );
  +        DefaultLogKitManager logmanager = new DefaultLogKitManager();
  +        logmanager.setLogger(m_logKitLogger);
  +        logmanager.contextualize(context);
  +        logmanager.configure( getLogKitConfig() );
  +        manager.setLogKitManager(logmanager);
  +        manager.configure( getContainerConfig() );
  +        manager.initialize();
           long ecmStop = System.currentTimeMillis();
           long ecmDuration = ecmStop - ecmStart;
  -
  +        
           resetMemory(); // Start clean
  -
  +        
           long cmStart = System.currentTimeMillis();
  -            Parameters params = new Parameters();
  -            params.setParameter( ContainerManager.CONTAINER_CLASS, "org.apache.avalon.excalibur.system.test.TestContainer"
);
  -            params.setParameter( ContainerManager.CONTEXT_DIRECTORY, "./" );
  -            params.setParameter( ContainerManager.WORK_DIRECTORY, "/tmp/" );
  -            params.setParameter( ContainerManager.CONTAINER_CONFIG, "resource://org/apache/avalon/excalibur/system/test/ContainerProfile.xconf"
);
  -            params.setParameter( ContainerManager.LOG_CATEGORY, "test" );
  -            params.setParameter( ContainerManager.LOGKIT_CONFIG, "resource://org/apache/avalon/excalibur/system/test/ContainerProfile.xlog"
);
  -            params.setParameter( ContainerManager.THREADS_CPU, "2" );
  -            params.setParameter( ContainerManager.THREAD_TIMEOUT, "100" );
  -            params.makeReadOnly();
  -            ContainerManager cm = new RootContainerManager( params, new NullLogger() );
  -            cm.initialize();
  -            TestContainer container = (TestContainer) cm.getContainer();
  -            assertNotNull(container);
  +        ContextBuilder contextBuilder = new ContextBuilder ();
  +        contextBuilder.setContainerClass( "org.apache.avalon.excalibur.system.test.TestContainer"
);
  +        contextBuilder.setContextDirectory( "./" );
  +        contextBuilder.setWorkDirectory( "./" );
  +        contextBuilder.setContainerConfiguration( "resource://org/apache/avalon/excalibur/system/test/ContainerProfile.xconf"
);
  +        contextBuilder.setLoggerManagerConfiguration( "resource://org/apache/avalon/excalibur/system/test/ContainerProfile.xlog"
);
  +        
  +        ContextManager contextManager = new ContextManager( null, contextBuilder.getContext(),
null );
  +        contextManager.initialize();
  +        
  +        ContainerManager cm = new DefaultContainerManager( contextManager );
  +        cm.initialize();
  +        TestContainer container = (TestContainer) cm.getContainer();
  +        assertNotNull(container);
           long cmStop = System.currentTimeMillis();
           long cmDuration = cmStop - cmStart;
  -
  +        
           // Show a summary
           if ( m_logger.isInfoEnabled() )
           {
               m_logger.info( "Test Case: ECM_ContainerManager_StartTime" );
               m_logger.info( "     ECM time = " + ecmDuration + "ms." );
               m_logger.info( "     ContainerManager time = " + cmDuration + "ms." );
  -
  +            
               double mult;
               mult = ( cmDuration > 0 ? ( ecmDuration * 100 / cmDuration ) / 100.0 : Float.POSITIVE_INFINITY
);
               m_logger.info( "  => ContainerManager is " + mult + " X as fast as ExcaliburComponentManager
on init." );
               mult = ( ecmDuration > 0 ? ( cmDuration * 100 / ecmDuration ) / 100.0 :
Float.POSITIVE_INFINITY );
               m_logger.info( "  => ExcaliburComponentManager is " + mult + " X as fast
as ContainerManager on init." );
           }
  -
  +        
           resetMemory();
  -
  +        
           lookupTest( "Test Case: ECM_ContainerManager_UseageTime", container.getCM(), manager
);
  -
  +        
           resetMemory();
  -
  +        
           ecmStart = System.currentTimeMillis();
  -            manager.dispose();
  +        manager.dispose();
           ecmStop = System.currentTimeMillis();
           ecmDuration = ecmStop - ecmStart;
  -
  +        
           resetMemory();
  -
  +        
           cmStart = System.currentTimeMillis();
  -            cm.dispose();
  +        cm.dispose();
           cmStop = System.currentTimeMillis();
           cmDuration = cmStop - cmStart;
  -
  +        
           // Show a summary
           if ( m_logger.isInfoEnabled() )
           {
               m_logger.info( "Test Case: ECM_ContainerManager_KillTime" );
               m_logger.info( "     ECM time = " + ecmDuration + "ms." );
               m_logger.info( "     ContainerManager time = " + cmDuration + "ms." );
  -
  +            
               double mult;
               mult = ( cmDuration > 0 ? ( ecmDuration * 100 / cmDuration ) / 100.0 : Float.POSITIVE_INFINITY
);
               m_logger.info( "  => ContainerManager is " + mult + " X as fast as ExcaliburComponentManager
on dispose." );
  @@ -156,7 +157,7 @@
               m_logger.info( "  => ExcaliburComponentManager is " + mult + " X as fast
as ContainerManager on dispose." );
           }
       }
  -
  +    
       /*---------------------------------------------------------------
        * Utility Methods
        *-------------------------------------------------------------*/
  @@ -164,7 +165,7 @@
       {
           System.gc();
           System.gc();
  -
  +        
           // Let the system settle down.
           try
           {
  @@ -174,7 +175,7 @@
           Runtime runtime = Runtime.getRuntime();
           m_logger.debug( "Memory: " + ( runtime.totalMemory() - runtime.freeMemory() ) );
       }
  -
  +    
       /**
        * Get the LogKitManager Config file
        */
  @@ -185,7 +186,7 @@
           URL resource = this.getClass().getClassLoader().getResource( resourceName );
           return loadConfig( resource );
       }
  -
  +    
       /**
        * Get the Container Config file
        */
  @@ -196,7 +197,7 @@
           URL resource = this.getClass().getClassLoader().getResource( resourceName );
           return loadConfig( resource );
       }
  -
  +    
       /**
        * Load Config
        */
  @@ -206,7 +207,7 @@
           final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
           return builder.build( path.openStream() );
       }
  -
  +    
       /**
        * Get the short class name
        */
  @@ -220,7 +221,7 @@
           }
           return name;
       }
  -
  +    
       /**
        * The guts of the various test cases.  Will dispose the pools
        */
  @@ -228,46 +229,46 @@
           throws Exception
       {
           m_logger.info( "Test Case: " + name );
  -
  +        
           // Get the short class names
           final String cmAName = getShortClassName( cmA );
           final String cmBName = getShortClassName( cmB );
  -
  +        
           // Start clean
           resetMemory();
  -
  -
  +        
  +        
           // Get the time for ecm
           final long cmADuration = getLookupRunTime( cmA );
           m_logger.info( "     " + cmAName + " time = " + cmADuration + "ms. to use " + TEST_SIZE
+ " calls on 3 components." );
           resetMemory();
  -
  -
  +        
  +        
           // Get the time for manager
           final long cmBDuration = getLookupRunTime( cmB );
           m_logger.info( "     " + cmBName + " time = " + cmBDuration + "ms. to use " + TEST_SIZE
+ " calls on 3 components." );
           resetMemory();
  -
  +        
           // Show a summary
           if ( m_logger.isInfoEnabled() )
           {
               double mult;
               mult = ( cmADuration > 0 ? ( cmBDuration * 100 / cmADuration ) / 100.0 :
Float.POSITIVE_INFINITY );
               m_logger.info( "  => " + cmAName + " is " + mult + " X as fast as " + cmBName
+ "." );
  -
  +            
               mult = ( cmBDuration > 0 ? ( cmADuration * 100 / cmBDuration ) / 100.0 :
Float.POSITIVE_INFINITY );
               m_logger.info( "  => " + cmBName + " is " + mult + " X as fast as " + cmAName
+ "." );
           }
       }
  -
  +    
       protected long getLookupRunTime( ComponentManager manager )
       {
           // Create the runnable
           LookupRunner runnable = new LookupRunner(manager, m_logger);
  -
  +        
           LatchedThreadGroup group = new LatchedThreadGroup( runnable, THREADS );
           group.enableLogging( m_logger );
  -
  +        
           long duration;
           try
           {
  @@ -281,40 +282,40 @@
               }
               duration = 0;
           }
  -
  +        
           if ( m_throwable != null )
           {
               throw new CascadingAssertionFailedError( "Exception in test thread.", m_throwable
);
           }
  -
  +        
           assertTrue( "m_getCount == 0 (" + m_getCount + ")", m_getCount == 0 );
  -
  +        
           return duration;
       }
  -
  +    
       private static class LookupRunner implements Runnable
       {
           private Logger m_logger;
           private ComponentManager m_manager;
           private int m_getCount = 0;
           private Throwable m_throwable = null;
  -
  +        
           public LookupRunner(ComponentManager manager, Logger logger)
           {
               m_manager = manager;
               m_logger = logger;
           }
  -
  +        
           public int getCount()
           {
               return m_getCount;
           }
  -
  +        
           public Throwable getThrowable()
           {
               return m_throwable;
           }
  -
  +        
           public void run()
           {
               // Perform this threads part of the test.
  @@ -324,19 +325,19 @@
                   Parser parser = null;
                   DataSourceComponent datasource = null;
                   Monitor monitor = null;
  -
  +                
                   try
                   {
                       parser = (Parser) m_manager.lookup(Parser.ROLE);
  -
  +                    
                       // Make the loops hold the components longer than they are released,
but only slightly.
                       Thread.yield();
                   }
                   catch (Throwable t)
                   {
                       m_logger.error( "Unexpected error after " + m_getCount +
  -                                    " iterations retrieved for Parser", t );
  -
  +                        " iterations retrieved for Parser", t );
  +                    
                       if (m_throwable == null) {
                           m_throwable = t;
                       }
  @@ -349,18 +350,19 @@
                           m_manager.release( parser );
                       }
                   }
  +                /*
                   try
                   {
                       datasource = (DataSourceComponent) m_manager.lookup(DataSourceComponent.ROLE);
  -
  +                    
                       // Make the loops hold the components longer than they are released,
but only slightly.
                       Thread.yield();
                   }
                   catch (Throwable t)
                   {
                       m_logger.error( "Unexpected error after " + m_getCount +
  -                                    " iterations retrieved for DataSourceComponent", t
);
  -
  +                        " iterations retrieved for DataSourceComponent", t );
  +                    
                       if (m_throwable == null) {
                           m_throwable = t;
                       }
  @@ -373,19 +375,19 @@
                           m_manager.release( datasource );
                       }
                   }
  -
  +                */
                   try
                   {
                       monitor = (Monitor) m_manager.lookup(Monitor.ROLE);
  -
  +                    
                       // Make the loops hold the components longer than they are released,
but only slightly.
                       Thread.yield();
                   }
                   catch (Throwable t)
                   {
                       m_logger.error( "Unexpected error after " + m_getCount +
  -                                    " iterations retrieved for DataSourceComponent", t
);
  -
  +                        " iterations retrieved for DataSourceComponent", t );
  +                    
                       if (m_throwable == null) {
                           m_throwable = t;
                       }
  @@ -401,10 +403,10 @@
               }
           }
       }
  -
  +    
       public static final void main(String[] args)
       {
  -         TestRunner.run( ContainerProfile.class );
  +        TestRunner.run( ContainerProfile.class );
       }
   }
   
  
  
  

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