You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2004/03/17 13:12:37 UTC
cvs commit: avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test BufferedLogger.java CascadingAssertionFailedError.java LatchedThreadGroup.java MultiThreadedPoolComparisonProfile.java ResourceLimitingPoolMultithreadMaxStrictBlockTestCase.java ResourceLimitingPoolMultithreadMaxStrictTestCase.java ResourceLimitingPoolMultithreadMaxTestCase.java ResourceLimitingPoolMultithreadTestCase.java ResourceLimitingPoolTestCase.java
mcconnell 2004/03/17 04:12:37
Modified: pool .cvsignore maven.xml project.xml
pool/src/test/org/apache/avalon/excalibur/pool/test
MultiThreadedPoolComparisonProfile.java
ResourceLimitingPoolMultithreadMaxStrictBlockTestCase.java
ResourceLimitingPoolMultithreadMaxStrictTestCase.java
ResourceLimitingPoolMultithreadMaxTestCase.java
ResourceLimitingPoolMultithreadTestCase.java
ResourceLimitingPoolTestCase.java
Added: pool README.TXT
pool/src/test/org/apache/avalon/excalibur/pool/test
BufferedLogger.java
CascadingAssertionFailedError.java
LatchedThreadGroup.java
Log:
Removal of fortress and ECM dependencies.
Revision Changes Path
1.2 +2 -0 avalon-excalibur/pool/.cvsignore
Index: .cvsignore
===================================================================
RCS file: /home/cvs/avalon-excalibur/pool/.cvsignore,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- .cvsignore 9 Nov 2003 14:44:01 -0000 1.1
+++ .cvsignore 17 Mar 2004 12:12:36 -0000 1.2
@@ -6,3 +6,5 @@
excalibur-*
*.el
*.ipr
+*.log
+target
1.5 +1 -1 avalon-excalibur/pool/maven.xml
Index: maven.xml
===================================================================
RCS file: /home/cvs/avalon-excalibur/pool/maven.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- maven.xml 28 Feb 2004 11:47:33 -0000 1.4
+++ maven.xml 17 Mar 2004 12:12:36 -0000 1.5
@@ -42,7 +42,7 @@
<!-- ===================================================================== -->
<postGoal name="java:compile">
- <attainGoal name="provide-fortress-meta"/>
+ <!--<attainGoal name="provide-fortress-meta"/>-->
</postGoal>
<goal
1.6 +14 -14 avalon-excalibur/pool/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/avalon-excalibur/pool/project.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- project.xml 28 Feb 2004 11:47:33 -0000 1.5
+++ project.xml 17 Mar 2004 12:12:36 -0000 1.6
@@ -29,11 +29,17 @@
</description>
<dependencies>
- <dependency>
- <id>avalon-framework</id>
- <version>4.1.4</version>
- <groupId>framework</groupId>
- </dependency>
+ <dependency>
+ <groupId>avalon-framework</groupId>
+ <artifactId>avalon-framework-api</artifactId>
+ <version>4.1.5</version>
+ </dependency>
+ <dependency>
+ <groupId>avalon-framework</groupId>
+ <artifactId>avalon-framework-impl</artifactId>
+ <version>4.1.5</version>
+ </dependency>
+
<dependency>
<!-- testing only -->
<id>logkit</id>
@@ -48,12 +54,6 @@
<version>2.1</version>
</dependency>
<dependency>
- <!-- testing only -->
- <id>excalibur-testcase</id>
- <version>1.2</version>
- <groupId>excalibur-component</groupId>
- </dependency>
- <dependency>
<id>excalibur-instrument</id>
<version>1.0</version>
</dependency>
@@ -63,17 +63,17 @@
<version>1.8</version>
</dependency>
-
+ <!--
<dependency>
- <!-- for metadata generation only -->
<id>excalibur-fortress-tools</id>
<version>1.0</version>
<groupId>excalibur-fortress</groupId>
</dependency>
<dependency>
- <!-- for metadata generation only -->
<id>qdox</id>
<version>1.1</version>
</dependency>
+ -->
+
</dependencies>
</project>
1.1 avalon-excalibur/pool/README.TXT
Index: README.TXT
===================================================================
Directory structure:
--------------------
1.X content:
/src - the 1.X codebase
2.X content
/api - the API to the Excalibur Thread package
/impl - the default implementation
/instumented - an extended implementation that includes instrumentation
1.5 +1 -3 avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/MultiThreadedPoolComparisonProfile.java
Index: MultiThreadedPoolComparisonProfile.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/MultiThreadedPoolComparisonProfile.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MultiThreadedPoolComparisonProfile.java 28 Feb 2004 11:47:22 -0000 1.4
+++ MultiThreadedPoolComparisonProfile.java 17 Mar 2004 12:12:37 -0000 1.5
@@ -18,8 +18,6 @@
import org.apache.avalon.excalibur.pool.Pool;
import org.apache.avalon.excalibur.pool.Poolable;
-import org.apache.avalon.excalibur.testcase.CascadingAssertionFailedError;
-import org.apache.avalon.excalibur.testcase.LatchedThreadGroup;
import org.apache.avalon.framework.activity.Disposable;
/**
1.6 +1 -2 avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/ResourceLimitingPoolMultithreadMaxStrictBlockTestCase.java
Index: ResourceLimitingPoolMultithreadMaxStrictBlockTestCase.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/ResourceLimitingPoolMultithreadMaxStrictBlockTestCase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ResourceLimitingPoolMultithreadMaxStrictBlockTestCase.java 16 Mar 2004 09:53:07 -0000 1.5
+++ ResourceLimitingPoolMultithreadMaxStrictBlockTestCase.java 17 Mar 2004 12:12:37 -0000 1.6
@@ -23,7 +23,6 @@
import org.apache.avalon.excalibur.pool.Poolable;
import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
-import org.apache.avalon.excalibur.testcase.BufferedLogger;
import com.clarkware.junitperf.ConstantTimer;
import com.clarkware.junitperf.LoadTest;
1.6 +1 -2 avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/ResourceLimitingPoolMultithreadMaxStrictTestCase.java
Index: ResourceLimitingPoolMultithreadMaxStrictTestCase.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/ResourceLimitingPoolMultithreadMaxStrictTestCase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ResourceLimitingPoolMultithreadMaxStrictTestCase.java 16 Mar 2004 09:53:07 -0000 1.5
+++ ResourceLimitingPoolMultithreadMaxStrictTestCase.java 17 Mar 2004 12:12:37 -0000 1.6
@@ -23,7 +23,6 @@
import org.apache.avalon.excalibur.pool.Poolable;
import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
-import org.apache.avalon.excalibur.testcase.BufferedLogger;
import com.clarkware.junitperf.ConstantTimer;
import com.clarkware.junitperf.LoadTest;
1.6 +1 -2 avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/ResourceLimitingPoolMultithreadMaxTestCase.java
Index: ResourceLimitingPoolMultithreadMaxTestCase.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/ResourceLimitingPoolMultithreadMaxTestCase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ResourceLimitingPoolMultithreadMaxTestCase.java 16 Mar 2004 09:53:07 -0000 1.5
+++ ResourceLimitingPoolMultithreadMaxTestCase.java 17 Mar 2004 12:12:37 -0000 1.6
@@ -23,7 +23,6 @@
import org.apache.avalon.excalibur.pool.Poolable;
import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
-import org.apache.avalon.excalibur.testcase.BufferedLogger;
import com.clarkware.junitperf.ConstantTimer;
import com.clarkware.junitperf.LoadTest;
1.7 +1 -2 avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/ResourceLimitingPoolMultithreadTestCase.java
Index: ResourceLimitingPoolMultithreadTestCase.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/ResourceLimitingPoolMultithreadTestCase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ResourceLimitingPoolMultithreadTestCase.java 16 Mar 2004 09:53:39 -0000 1.6
+++ ResourceLimitingPoolMultithreadTestCase.java 17 Mar 2004 12:12:37 -0000 1.7
@@ -23,7 +23,6 @@
import org.apache.avalon.excalibur.pool.Poolable;
import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
-import org.apache.avalon.excalibur.testcase.BufferedLogger;
import com.clarkware.junitperf.ConstantTimer;
import com.clarkware.junitperf.LoadTest;
1.5 +1 -2 avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/ResourceLimitingPoolTestCase.java
Index: ResourceLimitingPoolTestCase.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/ResourceLimitingPoolTestCase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ResourceLimitingPoolTestCase.java 28 Feb 2004 11:47:22 -0000 1.4
+++ ResourceLimitingPoolTestCase.java 17 Mar 2004 12:12:37 -0000 1.5
@@ -20,7 +20,6 @@
import org.apache.avalon.excalibur.pool.Poolable;
import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
-import org.apache.avalon.excalibur.testcase.BufferedLogger;
/**
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
1.1 avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/BufferedLogger.java
Index: BufferedLogger.java
===================================================================
/*
* Copyright 2002-2004 Apache Software Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.avalon.excalibur.pool.test;
import org.apache.avalon.framework.ExceptionUtil;
import org.apache.avalon.framework.logger.Logger;
/**
* Simple Logger which logs all information to an internal StringBuffer.
* When logging is complete call toString() on the logger to obtain the
* logged output. Useful for testing.
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version CVS $Revision: 1.1 $ $Date: 2004/03/17 12:12:37 $
* @since 4.0
*/
public class BufferedLogger
implements Logger
{
private final StringBuffer m_sb = new StringBuffer();
/**
* Log a debug message.
*
* @param message the message
*/
public void debug( final String message )
{
debug( message, null );
}
/**
* Log a debug message.
*
* @param message the message
* @param throwable the throwable
*/
public void debug( final String message, final Throwable throwable )
{
append( "DEBUG", message, throwable );
}
/**
* Determine if messages of priority "debug" will be logged.
*
* @return true if "debug" messages will be logged
*/
public boolean isDebugEnabled()
{
return true;
}
/**
* Log a info message.
*
* @param message the message
*/
public void info( final String message )
{
info( message, null );
}
/**
* Log a info message.
*
* @param message the message
* @param throwable the throwable
*/
public void info( final String message, final Throwable throwable )
{
append( "INFO", message, throwable );
}
/**
* Determine if messages of priority "info" will be logged.
*
* @return true if "info" messages will be logged
*/
public boolean isInfoEnabled()
{
return true;
}
/**
* Log a warn message.
*
* @param message the message
*/
public void warn( final String message )
{
warn( message, null );
}
/**
* Log a warn message.
*
* @param message the message
* @param throwable the throwable
*/
public void warn( final String message, final Throwable throwable )
{
append( "WARN", message, throwable );
}
/**
* Determine if messages of priority "warn" will be logged.
*
* @return true if "warn" messages will be logged
*/
public boolean isWarnEnabled()
{
return true;
}
/**
* Log a error message.
*
* @param message the message
*/
public void error( final String message )
{
error( message, null );
}
/**
* Log a error message.
*
* @param message the message
* @param throwable the throwable
*/
public void error( final String message, final Throwable throwable )
{
append( "ERROR", message, throwable );
}
/**
* Determine if messages of priority "error" will be logged.
*
* @return true if "error" messages will be logged
*/
public boolean isErrorEnabled()
{
return true;
}
/**
* Log a fatalError message.
*
* @param message the message
*/
public void fatalError( final String message )
{
fatalError( message, null );
}
/**
* Log a fatalError message.
*
* @param message the message
* @param throwable the throwable
*/
public void fatalError( final String message, final Throwable throwable )
{
append( "FATAL ERROR", message, throwable );
}
/**
* Determine if messages of priority "fatalError" will be logged.
*
* @return true if "fatalError" messages will be logged
*/
public boolean isFatalErrorEnabled()
{
return true;
}
/**
* Create a new child logger.
* The name of the child logger is [current-loggers-name].[passed-in-name]
*
* @param name the subname of this logger
* @return the new logger
*/
public Logger getChildLogger( final String name )
{
return this;
}
/**
* Returns the contents of the buffer.
*
* @return the buffer contents
*
*/
public String toString()
{
return m_sb.toString();
}
private void append( final String level,
final String message,
final Throwable throwable )
{
synchronized( m_sb )
{
m_sb.append( level );
m_sb.append( " - " );
m_sb.append( message );
if( null != throwable )
{
final String stackTrace =
ExceptionUtil.printStackTrace( throwable );
m_sb.append( " : " );
m_sb.append( stackTrace );
}
m_sb.append( "\n" );
}
}
}
1.1 avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/CascadingAssertionFailedError.java
Index: CascadingAssertionFailedError.java
===================================================================
/*
* Copyright 2002-2004 Apache Software Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.avalon.excalibur.pool.test;
import junit.framework.AssertionFailedError;
import org.apache.avalon.framework.CascadingThrowable;
/**
* This is an extention to the testing framework so that we can get detailed
* messages from JUnit (The AssertionFailedError hides the underlying cause)
*
* @deprecated ECM is no longer supported
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version $Id: CascadingAssertionFailedError.java,v 1.1 2004/03/17 12:12:37 mcconnell Exp $
*/
public class CascadingAssertionFailedError
extends AssertionFailedError
implements CascadingThrowable
{
private final Throwable m_throwable;
/**
* Constructor with no message
*/
public CascadingAssertionFailedError()
{
this( null, null );
}
/**
* Constructor with a message
*/
public CascadingAssertionFailedError( String message )
{
this( message, null );
}
/**
* Constructor with a message and a parent exception
*/
public CascadingAssertionFailedError( String message,
Throwable parentThrowable )
{
super( message );
m_throwable = parentThrowable;
}
/**
* Return the parent exception
*/
public final Throwable getCause()
{
return m_throwable;
}
}
1.1 avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/LatchedThreadGroup.java
Index: LatchedThreadGroup.java
===================================================================
/*
* Copyright 2002-2004 Apache Software Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.avalon.excalibur.pool.test;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
/**
* This class is useful for writing MultiThreaded test cases where you need to perform
* multithreaded load testing on a component.
* <p>
* An instance of will create a block of threads of the specified size. Each thread will be
* assigned to run a specified Runnable instance. The threads will then all wait at a latch
* until the go method is called. The go method will not return until all of the
* Runnables have completed.
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version $Id: LatchedThreadGroup.java,v 1.1 2004/03/17 12:12:37 mcconnell Exp $
*/
public class LatchedThreadGroup
extends AbstractLogEnabled
{
private Thread[] m_threads;
private Object m_semaphore = new Object();
private int m_startedCount;
private boolean m_latched;
private int m_completedCount;
private Throwable m_exception;
/*---------------------------------------------------------------
* Constructors
*-------------------------------------------------------------*/
/**
* Creates a LatchedThreadGroup with a thread for each Runnable in the runnables array.
*/
public LatchedThreadGroup( Runnable[] runnables )
{
int threadCount = runnables.length;
m_threads = new Thread[ threadCount ];
for( int i = 0; i < threadCount; i++ )
{
m_threads[ i ] = new Runner( runnables[ i ], "Latched_Thread_" + i );
}
}
/**
* Creates a LatchedThreadGroup with threadCount threads each running runnable.
*/
public LatchedThreadGroup( Runnable runnable, int threadCount )
{
m_threads = new Thread[ threadCount ];
for( int i = 0; i < threadCount; i++ )
{
m_threads[ i ] = new Runner( runnable, "Latched_Thread_" + i );
}
}
/*---------------------------------------------------------------
* Methods
*-------------------------------------------------------------*/
protected void resetMemory()
{
System.gc();
System.gc();
// Let the system settle down.
try
{
Thread.sleep( 50 );
}
catch( InterruptedException e )
{
}
Runtime runtime = Runtime.getRuntime();
getLogger().debug( "Memory: " + ( runtime.totalMemory() - runtime.freeMemory() ) );
}
/**
* Causes all of the Runnables to start at the same instance. This method will return
* once all of the Runnables have completed.
*
* @return time, in milliseconds, that it took for all of the Runnables to complete.
*/
public long go()
throws Exception
{
// Start each of the threads. They will block until the latch is released. This is
// necessary because it takes some time for the threads to each allocate their required
// system resources and actually be ready to run.
int threadCount = m_threads.length;
for( int i = 0; i < threadCount; i++ )
{
m_threads[ i ].start();
}
// Wait for all of the threads to start before starting to time the test
synchronized( m_semaphore )
{
while( m_startedCount < threadCount )
{
m_semaphore.wait();
}
// Start clean
resetMemory();
// Release the threads.
m_latched = true;
getLogger().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 )
{
getLogger().debug( "Waiting for test threads to all complete." );
while( m_completedCount < threadCount )
{
try
{
m_semaphore.wait();
}
catch( InterruptedException e )
{
}
}
}
final long duration = System.currentTimeMillis() - startTime;
getLogger().debug( "All test threads completed." );
if( m_exception != null )
{
throw new CascadingAssertionFailedError( "Exception in test thread.", m_exception );
}
return duration;
}
/**
* Inner access method to getLogger() to work around a bug in the Javac compiler
* when getLogger() is called from the method of an inner class. Jikes seems to
* handle it Ok. :-/
*/
private Logger getInnerLogger()
{
return getLogger();
}
/*---------------------------------------------------------------
* Inner Classes
*-------------------------------------------------------------*/
private class Runner extends Thread
{
private Runnable m_runnable;
protected Runner( Runnable runnable, String name )
{
super( name );
m_runnable = runnable;
}
public void run()
{
try
{
// Need all threads to wait until all the others are ready.
synchronized( m_semaphore )
{
m_startedCount++;
getInnerLogger().debug( "Started " + m_startedCount + " test threads." );
if( m_startedCount >= m_threads.length )
{
m_semaphore.notifyAll();
}
while( !m_latched )
{
try
{
m_semaphore.wait();
}
catch( InterruptedException e )
{
}
}
}
// Run the runnable
try
{
m_runnable.run();
}
catch( Throwable t )
{
synchronized( m_semaphore )
{
getInnerLogger().error( "Error in " + Thread.currentThread().getName(), t );
if( m_exception != null )
{
m_exception = t;
}
}
}
}
finally
{
// Say that we are done
synchronized( m_semaphore )
{
m_completedCount++;
getInnerLogger().debug( m_completedCount + " test threads completed." );
m_semaphore.notifyAll();
}
}
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org