Return-Path: Delivered-To: apmail-avalon-cvs-archive@avalon.apache.org Received: (qmail 7066 invoked by uid 500); 1 May 2003 10:15:16 -0000 Mailing-List: contact cvs-help@avalon.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list cvs@avalon.apache.org Received: (qmail 7055 invoked by uid 500); 1 May 2003 10:15:16 -0000 Received: (qmail 7052 invoked from network); 1 May 2003 10:15:16 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 1 May 2003 10:15:16 -0000 Received: (qmail 83909 invoked by uid 1449); 1 May 2003 10:15:14 -0000 Date: 1 May 2003 10:15:14 -0000 Message-ID: <20030501101514.83907.qmail@icarus.apache.org> From: leosutic@apache.org To: avalon-excalibur-cvs@apache.org Subject: cvs commit: avalon-excalibur/component/src/test/org/apache/avalon/excalibur/component/test PoolableTestObjectInterface.java PoolableTestObject.java PoolableComponentHandlerTestCase.xtest PoolableComponentHandlerTestCase.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N leosutic 2003/05/01 03:15:14 Modified: component/src/test/org/apache/avalon/excalibur/component/test PoolableTestObject.java PoolableComponentHandlerTestCase.xtest PoolableComponentHandlerTestCase.java Added: component/src/test/org/apache/avalon/excalibur/component/test PoolableTestObjectInterface.java Log: Updated the test case to work with components not implementing the Component interface. Revision Changes Path 1.3 +2 -4 avalon-excalibur/component/src/test/org/apache/avalon/excalibur/component/test/PoolableTestObject.java Index: PoolableTestObject.java =================================================================== RCS file: /home/cvs/avalon-excalibur/component/src/test/org/apache/avalon/excalibur/component/test/PoolableTestObject.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- PoolableTestObject.java 4 Mar 2003 17:15:06 -0000 1.2 +++ PoolableTestObject.java 1 May 2003 10:15:13 -0000 1.3 @@ -61,10 +61,8 @@ * @version CVS $Revision$ $Date$ */ public class PoolableTestObject - implements Component, Initializable, Recyclable, Disposable, Poolable + implements PoolableTestObjectInterface, Initializable, Recyclable, Disposable, Poolable { - public static final String ROLE = PoolableTestObject.class.getName(); - /** Semaphore used to synchronize access to m_instanceCounter */ private static Object m_semaphore = new Object(); 1.2 +6 -6 avalon-excalibur/component/src/test/org/apache/avalon/excalibur/component/test/PoolableComponentHandlerTestCase.xtest Index: PoolableComponentHandlerTestCase.xtest =================================================================== RCS file: /home/cvs/avalon-excalibur/component/src/test/org/apache/avalon/excalibur/component/test/PoolableComponentHandlerTestCase.xtest,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PoolableComponentHandlerTestCase.xtest 4 Apr 2002 05:09:02 -0000 1.1 +++ PoolableComponentHandlerTestCase.xtest 1 May 2003 10:15:13 -0000 1.2 @@ -48,27 +48,27 @@ - - - - - - 1.4 +152 -81 avalon-excalibur/component/src/test/org/apache/avalon/excalibur/component/test/PoolableComponentHandlerTestCase.java Index: PoolableComponentHandlerTestCase.java =================================================================== RCS file: /home/cvs/avalon-excalibur/component/src/test/org/apache/avalon/excalibur/component/test/PoolableComponentHandlerTestCase.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- PoolableComponentHandlerTestCase.java 4 Mar 2003 17:15:06 -0000 1.3 +++ PoolableComponentHandlerTestCase.java 1 May 2003 10:15:13 -0000 1.4 @@ -49,6 +49,8 @@ */ package org.apache.avalon.excalibur.component.test; +import org.apache.avalon.framework.component.Component; +import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.excalibur.component.PoolableComponentHandler; import org.apache.avalon.excalibur.testcase.BufferedLogger; import org.apache.avalon.excalibur.testcase.ExcaliburTestCase; @@ -105,19 +107,19 @@ PoolableTestObject.setStaticLoggger( logger ); PoolableTestObject.resetInstanceCounter(); - PoolableTestObject[] poolables = new PoolableTestObject[ size ]; + PoolableTestObjectInterface[] poolables = new PoolableTestObjectInterface[ size ]; // Lookup the components. for( int i = 0; i < size; i++ ) { poolables[ i ] = - (PoolableTestObject)lookup( PoolableTestObject.ROLE + "_" + name ); + (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name ); } // Release the components. for( int i = 0; i < size; i++ ) { - release( poolables[ i ] ); + release( (Component)poolables[ i ] ); poolables[ i ] = null; } @@ -125,13 +127,13 @@ for( int i = 0; i < size; i++ ) { poolables[ i ] = - (PoolableTestObject)lookup( PoolableTestObject.ROLE + "_" + name ); + (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name ); } // Release the components. for( int i = 0; i < size; i++ ) { - release( poolables[ i ] ); + release( (Component)poolables[ i ] ); poolables[ i ] = null; } @@ -177,7 +179,16 @@ "DEBUG - PoolableTestObject #11 recycled.\n" + "DEBUG - PoolableTestObject #12 recycled.\n"; - assertEquals( "Log did not contain the expected output.", resultLog, expectedLog ); + try + { + assertEquals( "Log did not contain the expected output.", resultLog, expectedLog ); + } + catch(junit.framework.ComparisonFailure cf) + { + // For clarity. + System.out.println( "Expected:\n" + expectedLog + "Was:\n" + resultLog); + throw cf; + } } /** @@ -194,19 +205,19 @@ PoolableTestObject.setStaticLoggger( logger ); PoolableTestObject.resetInstanceCounter(); - PoolableTestObject[] poolables = new PoolableTestObject[ size ]; + PoolableTestObjectInterface[] poolables = new PoolableTestObjectInterface[ size ]; // Lookup the components. for( int i = 0; i < size; i++ ) { poolables[ i ] = - (PoolableTestObject)lookup( PoolableTestObject.ROLE + "_" + name ); + (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name ); } // Release the components. for( int i = 0; i < size; i++ ) { - release( poolables[ i ] ); + release( (Component)poolables[ i ] ); poolables[ i ] = null; } @@ -214,13 +225,13 @@ for( int i = 0; i < size; i++ ) { poolables[ i ] = - (PoolableTestObject)lookup( PoolableTestObject.ROLE + "_" + name ); + (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name ); } // Release the components. for( int i = 0; i < size; i++ ) { - release( poolables[ i ] ); + release( (Component)poolables[ i ] ); poolables[ i ] = null; } @@ -247,7 +258,16 @@ "DEBUG - PoolableTestObject #2 recycled.\n" + "DEBUG - PoolableTestObject #6 recycled.\n"; - assertEquals( "Log did not contain the expected output.", resultLog, expectedLog ); + try + { + assertEquals( "Log did not contain the expected output.", resultLog, expectedLog ); + } + catch(junit.framework.ComparisonFailure cf) + { + // For clarity. + System.out.println( "Expected:\n" + expectedLog + "Was:\n" + resultLog); + throw cf; + } } /** @@ -264,19 +284,19 @@ PoolableTestObject.setStaticLoggger( logger ); PoolableTestObject.resetInstanceCounter(); - PoolableTestObject[] poolables = new PoolableTestObject[ size ]; + PoolableTestObjectInterface[] poolables = new PoolableTestObjectInterface[ size ]; // Lookup the components. for( int i = 0; i < size; i++ ) { poolables[ i ] = - (PoolableTestObject)lookup( PoolableTestObject.ROLE + "_" + name ); + (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name ); } // Try to get one more. Should fail. try { - lookup( PoolableTestObject.ROLE + "_" + name ); + lookup( PoolableTestObjectInterface.ROLE + "/" + name ); fail( "Attempt to get more Pollables than are in the pool should have failed." ); } catch( Exception e ) @@ -287,7 +307,7 @@ // Release the components. for( int i = 0; i < size; i++ ) { - release( poolables[ i ] ); + release( (Component)poolables[ i ] ); poolables[ i ] = null; } @@ -304,9 +324,56 @@ "DEBUG - PoolableTestObject #3 recycled.\n" + "DEBUG - PoolableTestObject #4 recycled.\n"; - assertEquals( "Log did not contain the expected output.", resultLog, expectedLog ); + try + { + assertEquals( "Log did not contain the expected output.", resultLog, expectedLog ); + } + catch(junit.framework.ComparisonFailure cf) + { + // For clarity. + System.out.println( "Expected:\n" + expectedLog + "Was:\n" + resultLog); + throw cf; + } } + private static class TestMax4StrictBlockingThread extends Thread + { + private final ComponentManager manager; + private final BufferedLogger logger; + + public TestMax4StrictBlockingThread( ComponentManager manager, BufferedLogger logger ) + { + this.manager = manager; + this.logger = logger; + } + + public void run() + { + final String name = "testMax4StrictBlocking"; + try + { + logger.debug( "Lookup in second thread." ); + PoolableTestObjectInterface poolable = (PoolableTestObjectInterface) manager.lookup( PoolableTestObjectInterface.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( (Component)poolable ); + } + catch( Exception e ) + { + e.printStackTrace (); + } + } + } + /** * Test a non-default max value with a strict max and blocking with no timeout */ @@ -314,55 +381,29 @@ { 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 ]; - + + PoolableTestObjectInterface[] poolables = new PoolableTestObjectInterface[ size ]; + // Lookup the components. for( int i = 0; i < size; i++ ) { poolables[ i ] = - (PoolableTestObject)lookup( PoolableTestObject.ROLE + "_" + name ); + (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name ); } - + // In another thread, get and release another poolable to cause this one to wait. - new Thread() - { - public void run() - { - try - { - logger.debug( "Lookup in second thread." ); - PoolableTestObject poolable = - (PoolableTestObject)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." ); - release( poolable ); - } - catch( Exception e ) - { - m_exception = e; - } - } - }.start(); - + TestMax4StrictBlockingThread secondThread = new TestMax4StrictBlockingThread( manager, logger ); + secondThread.start(); + // Give the second thread a chance to get the 4th poolable try { @@ -371,25 +412,27 @@ 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)lookup( PoolableTestObject.ROLE + "_" + name ); - + PoolableTestObjectInterface poolable = + (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name ); + logger.debug( "Release in main thread." ); - release( poolable ); - + release( (Component)poolable ); + + secondThread.join(); + // Release the components. for( int i = 0; i < size; i++ ) { - release( poolables[ i ] ); + release( (Component)poolables[ i ] ); poolables[ i ] = null; } - + // Make sure that the second thread did not throw an exception 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(); @@ -407,10 +450,20 @@ "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 ); + + try + { + assertEquals( "Log did not contain the expected output.", resultLog, expectedLog ); + } + catch(junit.framework.ComparisonFailure cf) + { + // For clarity. + System.out.println( "Expected:\n" + expectedLog + "Was:\n" + resultLog); + throw cf; + } + } - + /** * Test a non-default max value with a strict max and blocking with a timeout */ @@ -425,20 +478,20 @@ PoolableTestObject.setStaticLoggger( logger ); PoolableTestObject.resetInstanceCounter(); - PoolableTestObject[] poolables = new PoolableTestObject[ size ]; + PoolableTestObjectInterface[] poolables = new PoolableTestObjectInterface[ size ]; // Lookup the components. for( int i = 0; i < size; i++ ) { poolables[ i ] = - (PoolableTestObject)lookup( PoolableTestObject.ROLE + "_" + name ); + (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name ); } // Try to get one more. Should fail after 500 milliseconds. long start = System.currentTimeMillis(); try { - lookup( PoolableTestObject.ROLE + "_" + name ); + lookup( PoolableTestObjectInterface.ROLE + "/" + name ); fail( "Attempt to get more Pollables than are in the pool should have failed." ); } catch( Exception e ) @@ -452,7 +505,7 @@ // Release the components. for( int i = 0; i < size; i++ ) { - release( poolables[ i ] ); + release( (Component)poolables[ i ] ); poolables[ i ] = null; } @@ -469,7 +522,16 @@ "DEBUG - PoolableTestObject #3 recycled.\n" + "DEBUG - PoolableTestObject #4 recycled.\n"; - assertEquals( "Log did not contain the expected output.", resultLog, expectedLog ); + try + { + assertEquals( "Log did not contain the expected output.", resultLog, expectedLog ); + } + catch(junit.framework.ComparisonFailure cf) + { + // For clarity. + System.out.println( "Expected:\n" + expectedLog + "Was:\n" + resultLog); + throw cf; + } } /** @@ -484,27 +546,27 @@ PoolableTestObject.setStaticLoggger( logger ); PoolableTestObject.resetInstanceCounter(); - PoolableTestObject[] poolables = new PoolableTestObject[ 4 ]; + PoolableTestObjectInterface[] poolables = new PoolableTestObjectInterface[ 4 ]; // Lookup and release all 4 components a couple of times. for( int i = 0; i < 4; i++ ) { poolables[ i ] = - (PoolableTestObject)lookup( PoolableTestObject.ROLE + "_" + name ); + (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name ); } for( int i = 0; i < 4; i++ ) { - release( poolables[ i ] ); + release( (Component)poolables[ i ] ); poolables[ i ] = null; } for( int i = 0; i < 4; i++ ) { poolables[ i ] = - (PoolableTestObject)lookup( PoolableTestObject.ROLE + "_" + name ); + (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name ); } for( int i = 0; i < 4; i++ ) { - release( poolables[ i ] ); + release( (Component)poolables[ i ] ); poolables[ i ] = null; } @@ -521,11 +583,11 @@ for( int i = 0; i < 2; i++ ) { poolables[ i ] = - (PoolableTestObject)lookup( PoolableTestObject.ROLE + "_" + name ); + (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name ); } for( int i = 0; i < 2; i++ ) { - release( poolables[ i ] ); + release( (Component)poolables[ i ] ); poolables[ i ] = null; } @@ -544,11 +606,11 @@ for( int i = 0; i < 4; i++ ) { poolables[ i ] = - (PoolableTestObject)lookup( PoolableTestObject.ROLE + "_" + name ); + (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name ); } for( int i = 0; i < 4; i++ ) { - release( poolables[ i ] ); + release( (Component)poolables[ i ] ); poolables[ i ] = null; } @@ -580,7 +642,16 @@ "DEBUG - PoolableTestObject #5 recycled.\n" + "DEBUG - PoolableTestObject #6 recycled.\n"; - assertEquals( "Log did not contain the expected output.", resultLog, expectedLog ); + try + { + assertEquals( "Log did not contain the expected output.", resultLog, expectedLog ); + } + catch(junit.framework.ComparisonFailure cf) + { + // For clarity. + System.out.println( "Expected:\n" + expectedLog + "Was:\n" + resultLog); + throw cf; + } } } 1.1 avalon-excalibur/component/src/test/org/apache/avalon/excalibur/component/test/PoolableTestObjectInterface.java Index: PoolableTestObjectInterface.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact apache@apache.org. 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see . */ package org.apache.avalon.excalibur.component.test; public interface PoolableTestObjectInterface { public static final String ROLE = PoolableTestObjectInterface.class.getName(); } --------------------------------------------------------------------- To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org For additional commands, e-mail: cvs-help@avalon.apache.org