FileDocCategorySizeDatePackage
TestRunner.javaAPI DocGlassfish v2 API9974Fri May 04 22:23:50 BST 2007com.sun.enterprise.management

TestRunner

public final class TestRunner extends Object
Class that supports running all the unit tests for AMX

Fields Summary
final com.sun.appserv.management.client.ConnectionSource
mConn
boolean
mVerbose
Constructors Summary
public TestRunner(com.sun.appserv.management.client.ConnectionSource conn)

		mConn		= conn;
		mVerbose	= false;
	
Methods Summary
public longelapsed(long start)

		return( System.currentTimeMillis() - start );
	
public javax.management.MBeanServerConnectiongetMBeanServerConnection()

		return( mConn == null ? null : mConn.getMBeanServerConnection( false ) );
	
private voidprint(java.lang.Object o)

		System.out.print( toString( o ) );
	
protected voidprintVerbose(java.lang.Object o)

		if ( mVerbose )
		{
			println( o );
		}
	
private voidprintln(java.lang.Object o)

		System.out.println( toString( o ) );
	
protected voidrunAll(java.util.List testClasses, boolean threaded, java.util.Map env)

param
threaded if true, run the tests from each TestCase in separate threads
param
env arbitrary environment values for JMXTestBase

		mVerbose	= Boolean.valueOf( (String)env.get( PropertyKeys.VERBOSE_KEY ) ).booleanValue();
		
		//testSpeed();
		
		// use the current connection which must contain the AMX MBeans
		final MBeanServerConnection	 conn	= getMBeanServerConnection();
		
		JMXTestBase.setGlobalConnection( conn );
		JMXTestBase.setEnvValues( env );
		
		println( "\n--- " + testClasses.size() + " TEST CLASSES ---" );
		
		for( final Class<junit.framework.TestCase> theClass : testClasses )
		{
			println( theClass.getName() );
		}
		
		println( "\n--- BEGIN TESTS ---" );
		runTests( testClasses, threaded );
	
public intrunSuite(java.lang.String name, junit.framework.TestSuite suite)

		System.out.println( "*** testing " + name + " ***");
		
        junit.textui.TestRunner runner = new junit.textui.TestRunner();
		junit.framework.TestResult	result	= runner.doRun( suite, false );
		
		return( result.failureCount() );
	
public voidrunTests(java.util.List testClasses, boolean threaded)

		for( final Class<junit.framework.TestCase> theClass : testClasses )
		{
			final int failureCount	= threaded ?
				testClassThreaded( theClass ) : 
				testClass( theClass );
				
			if ( failureCount != 0 )
			{
				println(  "Test " + theClass.getName() + " had failures: " + failureCount );
			}
		}
	
private voidtestAppserverConnectionSource(java.lang.String host, java.lang.String user, java.lang.String password)
Comment in call to this for hard-coded test.

		MBeanServerConnection	conn	= null;
		
		final TestClientTrustStoreTrustManager	tm	= new TestClientTrustStoreTrustManager();
		final HandshakeCompletedListenerImpl	hcl	= new HandshakeCompletedListenerImpl();
		tm.setPrompt( true );
		final TLSParams	tlsParams	=
			new TLSParams( new X509TrustManager[] { tm }, hcl );
			
		println( "\ntestAppserverConnectionSource: testing: " + AppserverConnectionSource.PROTOCOL_RMI);
			
		final ConnectionSource	rmiSource	=
			new AppserverConnectionSource( AppserverConnectionSource.PROTOCOL_RMI,
				host, 8686, user, password, null);
		conn	= rmiSource.getMBeanServerConnection( true );
		conn.isRegistered( JMXUtil.getMBeanServerDelegateObjectName() );
		
		println( AppserverConnectionSource.PROTOCOL_RMI + " OK using " + rmiSource );
		
		
		println( "\ntestAppserverConnectionSource: testing: " + AppserverConnectionSource.PROTOCOL_HTTP );
		final Map<String,String>	env	= Collections.emptyMap();
		
		final ConnectionSource	httpSource	=
			new AppserverConnectionSource( AppserverConnectionSource.PROTOCOL_HTTP,
				host, 1234, user, password, tlsParams, env);
		conn	= httpSource.getMBeanServerConnection( true );
		assert conn.isRegistered( JMXUtil.getMBeanServerDelegateObjectName() );
	
		println( AppserverConnectionSource.PROTOCOL_HTTP + " OK using " + httpSource );
		
	
public inttestClass(java.lang.Class theClass)

		final TestSuite	suite	= new TestSuite( theClass );
		return( runSuite( theClass.getName(), suite ) );
	
public inttestClassThreaded(java.lang.Class theClass)

		final TestSuite	suite	= new ActiveTestSuite( theClass );
		
		return( runSuite( theClass.getName(), suite ) );
	
private voidtestGetMBeanInfoSpeed(javax.management.MBeanServerConnection conn, java.lang.String domain, java.lang.String props)

		final ObjectName	pattern	= Util.newObjectNamePattern( domain, props );
		final Set<ObjectName>	objectNameSet	= JMXUtil.queryNames( conn, pattern, null);
		
		final ObjectName[]	objectNames	= new ObjectName[ objectNameSet.size() ];
		objectNameSet.toArray( objectNames );
		
		final long elapsed	= testGetMBeanInfoSpeed( conn, objectNames );
		
		println( "Time to getMBeanInfo on " + domain + ":" + props + " (" + objectNames.length + " MBeans)" +
			" = " + elapsed + "ms" );
	
private longtestGetMBeanInfoSpeed(javax.management.MBeanServerConnection conn, javax.management.ObjectName[] objectNames)

		// sorting provides consistent, ordered output
		Arrays.sort( objectNames, ObjectNameComparator.INSTANCE );	
		
		final long	startAll	= System.currentTimeMillis();
		for( int i = 0; i < objectNames.length; ++i )
		{
			final ObjectName	objectName	= objectNames[ i ];
			
			final long	start	= System.currentTimeMillis();
			
			final MBeanInfo	mbeanInfo	= conn.getMBeanInfo( objectName );
			
			final long	elapsed	= elapsed( start );
			
			String	id	= objectName.toString();
			String	value;
			
			if ( (value = objectName.getKeyProperty( "type" )) != null )
			{
				id	= value;
			}
			else if ( (value = objectName.getKeyProperty( "j2eeType" )) != null )
			{
				id	= value;
			}
			
			if ( (value = objectName.getKeyProperty( "name" )) != null )
			{
				id	= Util.concatenateProps( id, Util.makeNameProp( value ) );
			}
			
			
			//printVerbose( "GetMBeanInfo time for " + id + " = " + elapsed );
		}
		
		final long	elapsed	= System.currentTimeMillis() - startAll;
		return( elapsed );
	
public voidtestSpeed()

		final DomainRoot	domainRootProxy	= ProxyFactory.getInstance( mConn ).
			createDomainRoot();
		
		final MBeanServerConnection	conn	= getMBeanServerConnection();
		
		testGetMBeanInfoSpeed( conn, Util.getObjectName( domainRootProxy ).getDomain(), JMXUtil.WILD_ALL  );
	
public static java.lang.StringtoString(java.lang.Object o)

		return( SmartStringifier.toString( o ) );