You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2002/02/18 21:48:09 UTC
cvs commit: jakarta-avalon-excalibur/src/test/org/apache/avalon/excalibur/component/test PoolableComponentHandlerTestCase.java
bloritsch 02/02/18 12:48:09
Modified: src/scratchpad/org/apache/avalon/excalibur/mpool/test
PoolComparisonProfileAbstract.java
src/test/org/apache/avalon/excalibur/component/test
PoolableComponentHandlerTestCase.java
Log:
update reporting on mpool profile
Revision Changes Path
1.7 +4 -1 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/PoolComparisonProfileAbstract.java
Index: PoolComparisonProfileAbstract.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/PoolComparisonProfileAbstract.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PoolComparisonProfileAbstract.java 18 Feb 2002 20:44:05 -0000 1.6
+++ PoolComparisonProfileAbstract.java 18 Feb 2002 20:48:09 -0000 1.7
@@ -24,7 +24,7 @@
* 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.6 2002/02/18 20:44:05 bloritsch Exp $
+ * @version $Id: PoolComparisonProfileAbstract.java,v 1.7 2002/02/18 20:48:09 bloritsch Exp $
*/
public abstract class PoolComparisonProfileAbstract
extends TestCase
@@ -592,6 +592,9 @@
mult = ( poolBDuration > 0 ? ( poolADuration * 100 / poolBDuration ) / 100.0 : Float.POSITIVE_INFINITY );
m_logger.info( " => " + poolBName + " is " + mult + " X as fast as " + poolAName + "." );
+
+ mult = ( poolADuration > 0 ? ( poolBDuration * 100 / poolADuration ) / 100.0 : Float.POSITIVE_INFINITY );
+ m_logger.info( " => " + poolAName + " is " + mult + " X as fast as " + poolBName + "." );
}
}
}
1.2 +72 -72 jakarta-avalon-excalibur/src/test/org/apache/avalon/excalibur/component/test/PoolableComponentHandlerTestCase.java
Index: PoolableComponentHandlerTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/test/org/apache/avalon/excalibur/component/test/PoolableComponentHandlerTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PoolableComponentHandlerTestCase.java 18 Feb 2002 10:14:17 -0000 1.1
+++ PoolableComponentHandlerTestCase.java 18 Feb 2002 20:48:09 -0000 1.2
@@ -22,29 +22,29 @@
extends ExcaliburTestCase
{
private Exception m_exception;
-
+
/*---------------------------------------------------------------
* Constructors
*-------------------------------------------------------------*/
public PoolableComponentHandlerTestCase( String name )
{
super(name);
-
+
// Set the priority for default log output.
m_logPriority = org.apache.log.Priority.INFO;
}
-
+
/*---------------------------------------------------------------
* TestCase Methods
*-------------------------------------------------------------*/
public void setUp() throws Exception {
super.setUp();
- }
-
+ }
+
public void tearDown() throws Exception {
super.tearDown();
}
-
+
/*---------------------------------------------------------------
* Test Cases
*-------------------------------------------------------------*/
@@ -55,43 +55,43 @@
{
String name = "testDefaults";
getLogger().info("Test: " + name);
-
+
int size = PoolableComponentHandler.DEFAULT_MAX_POOL_SIZE + 2;
-
+
BufferedLogger logger = new BufferedLogger();
PoolableTestObject.setStaticLoggger( logger );
PoolableTestObject.resetInstanceCounter();
-
+
PoolableTestObject[] poolables = new PoolableTestObject[size];
-
+
// Lookup the components.
for (int i = 0; i < size; i++)
{
poolables[i] =
(PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
}
-
+
// Release the components.
for (int i = 0; i < size; i++)
{
manager.release( poolables[i] );
poolables[i] = null;
}
-
+
// Lookup the components.
for (int i = 0; i < size; i++)
{
poolables[i] =
(PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
}
-
+
// Release the components.
for (int i = 0; i < size; i++)
{
manager.release( poolables[i] );
poolables[i] = null;
}
-
+
// The disposal of the objects will not show up in the log until the component manager is
// actually disposed.
// When objects are returned the pool, they are stored in a last in first off list.
@@ -133,10 +133,10 @@
"DEBUG - PoolableTestObject #3 recycled.\n" +
"DEBUG - PoolableTestObject #11 recycled.\n" +
"DEBUG - PoolableTestObject #12 recycled.\n";
-
+
assertEquals( "Log did not contain the expected output.", resultLog, expectedLog );
}
-
+
/**
* Test a non-default max value.
*/
@@ -144,43 +144,43 @@
{
String name = "testMax4";
getLogger().info("Test: " + name);
-
+
int size = 4 + 1;
-
+
BufferedLogger logger = new BufferedLogger();
PoolableTestObject.setStaticLoggger( logger );
PoolableTestObject.resetInstanceCounter();
-
+
PoolableTestObject[] poolables = new PoolableTestObject[size];
-
+
// Lookup the components.
for (int i = 0; i < size; i++)
{
poolables[i] =
(PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
}
-
+
// Release the components.
for (int i = 0; i < size; i++)
{
manager.release( poolables[i] );
poolables[i] = null;
}
-
+
// Lookup the components.
for (int i = 0; i < size; i++)
{
poolables[i] =
(PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
}
-
+
// Release the components.
for (int i = 0; i < size; i++)
{
manager.release( poolables[i] );
poolables[i] = null;
}
-
+
// The disposal of the objects will not show up in the log until the component manager is
// actually disposed.
String resultLog = logger.toString();
@@ -203,10 +203,10 @@
"DEBUG - PoolableTestObject #3 recycled.\n" +
"DEBUG - PoolableTestObject #2 recycled.\n" +
"DEBUG - PoolableTestObject #6 recycled.\n";
-
+
assertEquals( "Log did not contain the expected output.", resultLog, expectedLog );
}
-
+
/**
* Test a non-default max value with a strict max and no blocking
*/
@@ -214,22 +214,22 @@
{
String name = "testMax4StrictNoBlocking";
getLogger().info("Test: " + name);
-
+
int size = 4;
-
+
BufferedLogger logger = new BufferedLogger();
PoolableTestObject.setStaticLoggger( logger );
PoolableTestObject.resetInstanceCounter();
-
+
PoolableTestObject[] poolables = new PoolableTestObject[size];
-
+
// Lookup the components.
for (int i = 0; i < size; i++)
{
poolables[i] =
(PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
}
-
+
// Try to get one more. Should fail.
try
{
@@ -239,14 +239,14 @@
{
// Passed
}
-
+
// Release the components.
for (int i = 0; i < size; i++)
{
manager.release( poolables[i] );
poolables[i] = null;
}
-
+
// The disposal of the objects will not show up in the log until the component manager is
// actually disposed.
String resultLog = logger.toString();
@@ -259,10 +259,10 @@
"DEBUG - PoolableTestObject #2 recycled.\n" +
"DEBUG - PoolableTestObject #3 recycled.\n" +
"DEBUG - PoolableTestObject #4 recycled.\n";
-
+
assertEquals( "Log did not contain the expected output.", resultLog, expectedLog );
}
-
+
/**
* Test a non-default max value with a strict max and blocking with no timeout
*/
@@ -270,25 +270,25 @@
{
final String name = "testMax4StrictBlocking";
getLogger().info("Test: " + name);
-
+
int size = 3;
-
+
// Initialize the exception field.
m_exception = null;
-
+
final BufferedLogger logger = new BufferedLogger();
PoolableTestObject.setStaticLoggger( logger );
PoolableTestObject.resetInstanceCounter();
-
+
PoolableTestObject[] poolables = new PoolableTestObject[size];
-
+
// Lookup the components.
for (int i = 0; i < size; i++)
{
poolables[i] =
(PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
}
-
+
// In another thread, get and release another poolable to cause this one to wait.
new Thread() {
public void run() {
@@ -297,14 +297,14 @@
logger.debug( "Lookup in second thread." );
PoolableTestObject poolable =
(PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
-
+
// Give the main thread a chance to block
try
{
Thread.sleep( 500 );
}
catch ( InterruptedException e ) {}
-
+
logger.debug( "Release in second thread." );
manager.release( poolable );
}
@@ -314,32 +314,32 @@
}
}
}.start();
-
+
// Give the second thread a chance to get the 4th poolable
try
{
Thread.sleep( 250 );
}
catch ( InterruptedException e ) {}
-
+
// Try to get one more. Should block until the other thread has put it back.
logger.debug( "Lookup in main thread." );
PoolableTestObject poolable =
(PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
-
+
logger.debug( "Release in main thread." );
manager.release( poolable );
-
+
// Release the components.
for (int i = 0; i < size; i++)
{
manager.release( poolables[i] );
poolables[i] = null;
}
-
+
// Make sure that the second thread did not throw an exception
- assert( "Unexpected exception in second thread.", m_exception == null );
-
+ assertTrue( "Unexpected exception in second thread.", m_exception == null );
+
// The disposal of the objects will not show up in the log until the component manager is
// actually disposed.
String resultLog = logger.toString();
@@ -357,10 +357,10 @@
"DEBUG - PoolableTestObject #1 recycled.\n" +
"DEBUG - PoolableTestObject #2 recycled.\n" +
"DEBUG - PoolableTestObject #3 recycled.\n";
-
+
assertEquals( "Log did not contain the expected output.", resultLog, expectedLog );
}
-
+
/**
* Test a non-default max value with a strict max and blocking with a timeout
*/
@@ -368,22 +368,22 @@
{
String name = "testMax4StrictBlockingTimeout";
getLogger().info("Test: " + name);
-
+
int size = 4;
-
+
BufferedLogger logger = new BufferedLogger();
PoolableTestObject.setStaticLoggger( logger );
PoolableTestObject.resetInstanceCounter();
-
+
PoolableTestObject[] poolables = new PoolableTestObject[size];
-
+
// Lookup the components.
for (int i = 0; i < size; i++)
{
poolables[i] =
(PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
}
-
+
// Try to get one more. Should fail after 500 milliseconds.
long start = System.currentTimeMillis();
try
@@ -395,16 +395,16 @@
// Passed
}
long dur = System.currentTimeMillis() - start;
- assert( "Block timeout was not within 50 milliseconds of the configured 500 milliseconds,",
+ assertTrue( "Block timeout was not within 50 milliseconds of the configured 500 milliseconds,",
dur >= 450 && dur <= 550 );
-
+
// Release the components.
for (int i = 0; i < size; i++)
{
manager.release( poolables[i] );
poolables[i] = null;
}
-
+
// The disposal of the objects will not show up in the log until the component manager is
// actually disposed.
String resultLog = logger.toString();
@@ -417,10 +417,10 @@
"DEBUG - PoolableTestObject #2 recycled.\n" +
"DEBUG - PoolableTestObject #3 recycled.\n" +
"DEBUG - PoolableTestObject #4 recycled.\n";
-
+
assertEquals( "Log did not contain the expected output.", resultLog, expectedLog );
}
-
+
/**
* Test the trimming features.
*/
@@ -428,13 +428,13 @@
{
String name = "testTrimming";
getLogger().info("Test: " + name);
-
+
BufferedLogger logger = new BufferedLogger();
PoolableTestObject.setStaticLoggger( logger );
PoolableTestObject.resetInstanceCounter();
-
+
PoolableTestObject[] poolables = new PoolableTestObject[4];
-
+
// Lookup and release all 4 components a couple of times.
for (int i = 0; i < 4; i++)
{
@@ -456,14 +456,14 @@
manager.release( poolables[i] );
poolables[i] = null;
}
-
+
// Now wait for 550 ms to trigger a trim on the next lookup.
try
{
Thread.sleep( 550 );
}
catch ( InterruptedException e ) {}
-
+
// Lookup and release 2 components to mark them as being recently used.
for (int i = 0; i < 2; i++)
{
@@ -475,14 +475,14 @@
manager.release( poolables[i] );
poolables[i] = null;
}
-
+
// Now wait for 550 ms to trigger a trim on the next lookup.
try
{
Thread.sleep( 550 );
}
catch ( InterruptedException e ) {}
-
+
// This next get should cause 2 of the components to be trimmed but the 2 we just lookedup
// should stay around.
// Lookup and release all 4 components to see which ones are left.
@@ -496,8 +496,8 @@
manager.release( poolables[i] );
poolables[i] = null;
}
-
-
+
+
// The disposal of the objects will not show up in the log until the component manager is
// actually disposed.
String resultLog = logger.toString();
@@ -524,7 +524,7 @@
"DEBUG - PoolableTestObject #1 recycled.\n" +
"DEBUG - PoolableTestObject #5 recycled.\n" +
"DEBUG - PoolableTestObject #6 recycled.\n";
-
+
assertEquals( "Log did not contain the expected output.", resultLog, expectedLog );
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>