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

AMXTestBase

public class AMXTestBase extends com.sun.enterprise.management.util.jmx.JMXTestBase
Base class for testing the AMX API

Fields Summary
private com.sun.appserv.management.client.ConnectionSource
mConnectionSource
private final com.sun.appserv.management.DomainRoot
mDomainRoot
private final com.sun.appserv.management.client.ProxyFactory
mProxyFactory
private final Set
mNotTested
private final TestUtil
mTestUtil
protected static final String
PE_CONFIG_NAME
config name for PE (non-EE) configuration
private static final boolean
WEB_MODULE_MONITOR_BROKEN
private static boolean
MONITORING_ENABLED
protected static final String
NEWLINE
private static final Set
EXPECTED_REMOTE_INCOMPLETE_TYPES
protected static final Class[]
OBJECTNAME_SIG
protected static final Class[]
PROXY_SIG
private static final String
DEFAULT_INSTANCE_NAME
Constructors Summary
public AMXTestBase()

	
	
		
	 
	
	    checkConnection( getConnection() );
		
		mNotTested	= new HashSet<ObjectName>();
		try
		{
			mConnectionSource	=
					new MBeanServerConnectionConnectionSource( getConnection() );
			
			mProxyFactory		= ProxyFactory.getInstance( mConnectionSource, true );
			mDomainRoot		= mProxyFactory.getDomainRoot();
		}
		catch( Exception e )
		{
			throw new RuntimeException( e.toString(), e );
		}
		
		mTestUtil   = new TestUtil( getDomainRoot() );
	
Methods Summary
protected voidcheckConnection(javax.management.MBeanServerConnection conn)

	    assert( getConnection() != null );
	    
	    try
	    {
			conn.isRegistered( JMXUtil.getMBeanServerDelegateObjectName() );
	   	}
	   	catch( Exception e )
	   	{
	   		fail( "Connection failed:\n" +
	   			ExceptionUtil.getStackTrace( getRootCause( e ) ) );
	   	}
	
protected voidcheckConnection()

		checkConnection( getConnection( ) );
	
protected booleancheckNotOffline(java.lang.String testName)
Check if we're testing in Offline mode, which means that Config MBeans are loaded in-process. If so, issue a warning.

return
true if test should be run, false if in offline mode

        boolean offline = getTestOffline();
        
        if ( offline )
        {
            //warning( "amxtest.testOffline=true, skipping test " + testName + "()" );
        }
        
        return ! offline;
    
com.sun.enterprise.management.support.AMXDebugSupportMBeangetAMXDebugSupportMBean()

	    final ObjectName  objectName  = Util.newObjectName( AMXDebugSupportMBean.OBJECT_NAME );
	    
	    try
	    {
	    return (AMXDebugSupportMBean)newProxy( objectName, AMXDebugSupportMBean.class );
	    }
	    catch( Exception e )
	    {
	        assert false : "Can't get proxy to " + objectName;
	    }
	    return null;
	
protected java.util.SetgetAllAMX()

	    return getTestUtil().getAllAMX();
	
protected com.sun.appserv.management.base.BulkAccessgetBulkAccess()

		return( getDomainRoot().getBulkAccess() );
	
protected com.sun.appserv.management.config.ConfigConfiggetConfigConfig(java.lang.String name)

		final Map<String,ConfigConfig>	configs	= getDomainConfig().getConfigConfigMap();

		return configs.get( name == null ? PE_CONFIG_NAME : name );
	
protected static com.sun.appserv.management.config.ConfigConfiggetConfigConfig(com.sun.appserv.management.config.AMXConfig any)

        final ObjectName   objectName  = Util.getObjectName( any );
        final String       configName  = objectName.getKeyProperty( XTypes.CONFIG_CONFIG );
    
        return any.getDomainRoot().getDomainConfig().getConfigConfigMap().get( configName );
	
protected com.sun.appserv.management.config.ConfigConfiggetConfigConfig()

		return( getConfigConfig( PE_CONFIG_NAME ) );
	
protected java.lang.String[]getConfigNames()

		final Map<String,ConfigConfig>	configMap	=
			getDomainConfig().getConfigConfigMap();
		
		return( GSetUtil.toStringArray( configMap.keySet() ) );
	
protected javax.management.MBeanServerConnectiongetConnection()

		return( getGlobalConnection() );
	
protected com.sun.appserv.management.client.ConnectionSourcegetConnectionSource()

		assert( mConnectionSource != null );
		return( mConnectionSource );
	
protected com.sun.appserv.management.config.NodeAgentConfiggetDASNodeAgentConfig()

       final String name    = getDASNodeAgentName();
       
       NodeAgentConfig  config  = null;
       if ( name != null )
       {
            config  = getDomainConfig().getNodeAgentConfigMap().get( name );
       }
       
       return config;
    
protected java.lang.StringgetDASNodeAgentName()

        return getEnvString( PropertyKeys.DAS_NODE_AGENT_NAME, null);
    
public static CapabilitiesgetDefaultCapabilities()

	    return getOfflineCapableCapabilities( true );
	
protected static java.lang.StringgetDefaultInstanceName(java.lang.String qualifier)

	
	      
	    
	
	    String  name    = null;
	    
	    if ( qualifier == null )
	    {
	        name    = DEFAULT_INSTANCE_NAME;
	    }
	    else
	    {
	        name    = qualifier + "." + DEFAULT_INSTANCE_NAME;
	    }
	    return name;
	
protected final com.sun.appserv.management.config.DomainConfiggetDomainConfig()

		return( getDomainRoot().getDomainConfig() );
	
protected final com.sun.appserv.management.DomainRootgetDomainRoot()

		assert( mDomainRoot != null ) : "mDomainRoot is null";
		return( mDomainRoot );
	
protected java.lang.ClassgetInterfaceClass(com.sun.appserv.management.base.AMX proxy)

		final String	name	= Util.getExtra( proxy ).getInterfaceName();
		return( ClassUtil.getClassFromName( name ) );
	
protected final com.sun.appserv.management.j2ee.J2EEDomaingetJ2EEDomain()

		return( getDomainRoot().getJ2EEDomain() );
	
protected com.sun.appserv.management.config.ModuleMonitoringLevelsConfiggetModuleMonitoringLevelsConfig(java.lang.String configName)

		final ConfigConfig	cc	= configName == null ? getConfigConfig() : getConfigConfig( configName );
		assert( cc != null );
		
		final ModuleMonitoringLevelsConfig	mon	=
			cc.getMonitoringServiceConfig().getModuleMonitoringLevelsConfig();
		
		return( mon );
	
protected com.sun.appserv.management.config.ModuleMonitoringLevelsConfiggetModuleMonitoringLevelsConfig()

		return getModuleMonitoringLevelsConfig( null );
	
protected java.util.MapgetNodeAgents()

       final Map<?,?> m = Map.class.cast( getEnvValue( PropertyKeys.NODE_AGENTS_KEY ) );
       return TypeCast.checkedMap( m,
                String.class, AppserverConnectionSource.class);
    
protected final java.util.SetgetNotTestedSet()

		return( mNotTested );
	
protected com.sun.appserv.management.base.NotificationServiceMgrgetNotificationServiceMgr()

		return( getDomainRoot().getNotificationServiceMgr() );
	
protected static CapabilitiesgetOfflineCapableCapabilities(boolean offlineCapable)

	    final Capabilities    c   = new Capabilities( );
	    c.setOfflineCapable( offlineCapable );
	    
	    return c;
	
protected final com.sun.appserv.management.base.AMXgetProxy(javax.management.ObjectName objectName)

		final ProxyFactory	factory	= ProxyFactory.getInstance( getConnectionSource(), true);
		
		final AMX proxy   = factory.getProxy( objectName, AMX.class );
		
		return( proxy );
	
protected final TgetProxy(javax.management.ObjectName objectName, java.lang.Class theClass)
We don't have T extend AMX because not all mixin interfaces extend AMX.

		return( theClass.cast( getProxy(objectName) ) );
	
protected com.sun.appserv.management.client.ProxyFactorygetProxyFactory()

		return( mProxyFactory );
	
protected com.sun.appserv.management.base.QueryMgrgetQueryMgr()

		assert( mDomainRoot != null );
		final QueryMgr	proxy	= getDomainRoot().getQueryMgr();
		assert( proxy != null );
		return( proxy );
	
protected java.lang.ThrowablegetRootCause(java.lang.Throwable t)

	    return ExceptionUtil.getRootCause( t );
	
protected java.lang.StringgetRootCauseStackTrace(java.lang.Throwable t)

	    return getStackTrace( getRootCause( t ) );
	
protected java.lang.StringgetStackTrace(java.lang.Throwable t)

	    return ExceptionUtil.getStackTrace( t );
	
protected booleangetTestOffline()

        return getEnvBoolean( PropertyKeys.TEST_OFFLINE_KEY, false );
    
protected TestUtilgetTestUtil()

	    return mTestUtil;
	
protected booleanisRemoteIncomplete(javax.management.ObjectName objectName)

	    
	     
	    
	
	   final AMX amx    = getProxyFactory().getProxy( objectName, AMX.class );
	   final String j2eeType    = amx.getJ2EEType();
	   
	   final boolean    isRemote    = ! amx.isDAS();
	   
	   if ( isRemote &&
	     ! EXPECTED_REMOTE_INCOMPLETE_TYPES.contains( j2eeType ) )
	   {
    	    warning( "isRemoteIncomplete: not expecting j2eeType=" + j2eeType +
    	        ", has the implementation changed?" );
	   }
	   
	   return isRemote;
	
public static voidmySleep(long millis)

		try
		{
			Thread.sleep( millis );
		}
		catch( InterruptedException e )
		{
		}
	
protected final voidnotTested(javax.management.ObjectName objectName)

	    if ( isRemoteIncomplete( objectName ) )
	    {
	        trace( "remoteIncomplete (this is OK): " + objectName );
		}
		else
		{
		    mNotTested.add( objectName );
		}
	
public voidsetUp()

		super.setUp();
					
		turnOnMonitoring();
	
protected booleanshouldTest(javax.management.ObjectName objectName)

		boolean	shouldTest	= ! isRemoteIncomplete( objectName );
		
		return( shouldTest );
	
protected booleansupportsClusters()

	    return getDomainRoot().getSystemInfo().supportsFeature( SystemInfo.CLUSTERS_FEATURE );
	
protected booleansupportsMultipleServers()

	    return supportsMultipleServers( getDomainRoot() );
	
public static booleansupportsMultipleServers(com.sun.appserv.management.DomainRoot domainRoot)

	    return domainRoot.getSystemInfo().supportsFeature( SystemInfo.MULTIPLE_SERVERS_FEATURE );
	
protected voidtestAll(java.util.Collection objectNames, java.lang.String methodName)


		 
	       
		 
	
		final boolean success	= testOnObjectNames( objectNames,
					this.getClass().getMethod( methodName, OBJECTNAME_SIG ) );
		
		assert( success );
	
protected voidtestAll(java.lang.String methodName)

		final Set<ObjectName>	names	= getTestUtil().getAllObjectNames();
		
		testAll( names, methodName );
	
protected voidtestAllProxies(java.util.Collection proxies, java.lang.String methodName)

		final boolean success	= testOnProxies( proxies,
					this.getClass().getMethod( methodName, PROXY_SIG ) );
		
		assert( success );
	
public voidtestAssertsOn()

	    checkAssertsOn();
	
protected booleantestOnObjectNames(java.util.Collection objectNames, java.lang.reflect.Method method)

		boolean	failed	= false;
		
		final Object[]	args	= new Object[ 1 ];
		
		int	testCount	= 0;
		final long	start	= now();
		
		for( final ObjectName objectName : objectNames )
		{
			if ( ! shouldTest( objectName ) )
			{
				notTested( objectName );
				continue;
			}

			++testCount;
			try
			{
				args[ 0 ]	= objectName;
				method.invoke( this, args );
			}
			catch( Exception e )
			{
			    final Throwable rootCause   = getRootCause( e );
				trace( method.getName() + " failed for: " +
				    quote( JMXUtil.toString( objectName ) ) + " with Exception of type " +
				        rootCause.getClass().getName() + ", msg = " + rootCause.getMessage() );
				failed	= true;
			}
		}
		
		final long	elapsed	= now() - start;
		printVerbose( "Ran test method " + method.getName() + " on " + testCount +
			" candidates in " + elapsed + "ms");
		warnNotTested();
		
		return( ! failed );
	
protected booleantestOnProxies(java.util.Collection proxies, java.lang.reflect.Method method)

		final long	start	= now();
		
		boolean	failed	= false;
		
		int	testCount	= 0;
		
		final Object[]	args	= new Object[ 1 ];
		for( final T proxy : proxies )
		{
			final ObjectName	objectName	= Util.getExtra( proxy ).getObjectName();
			
			if ( ! shouldTest( objectName ) )
			{
				notTested( objectName );
				continue;
			}

			++testCount;
			try
			{
				args[ 0 ]	= proxy;
				method.invoke( this, args );
			}
			catch( Exception e )
			{
				trace( method.getName() + " failed for proxy: " +
				    quote( JMXUtil.toString( objectName ) ) );
				failed	= true;
				trace( ExceptionUtil.toString( e ) );
			}
		}
		
		
		final long	elapsed	= now() - start;
		printVerbose( "Ran test method " + method.getName() + " on " + testCount +
			" candidates in " + elapsed + "ms");
		warnNotTested();
		
		warnNotTested();
		
		return( ! failed );
	
protected synchronized voidturnOffMonitoring()

		synchronized( AMXTestBase.class )
		{
			getModuleMonitoringLevelsConfig().changeAll( ModuleMonitoringLevelValues.OFF );
			MONITORING_ENABLED	= false;
		}
	
protected synchronized voidturnOnMonitoring()
Ensure that monitoring is enabled so that unit tests don't miss anything

		if ( ! MONITORING_ENABLED )
		{
			synchronized( AMXTestBase.class )
			{
				final String[]	configNames	= getConfigNames();
				for( int i = 0; i < configNames.length; ++i )
				{
					getModuleMonitoringLevelsConfig( configNames[ i ] ).changeAll( ModuleMonitoringLevelValues.HIGH );
				}
				
				MONITORING_ENABLED	= true;
			}
		}
	
protected voidwaitProxyGone(com.sun.appserv.management.client.ProxyFactory factory, javax.management.ObjectName objectName)
Because proxies are cleaned up asynchronously, it's possible for one to remain in the factory until the factory processes the Notification that it's MBean has been unregistered.

		long	millis	= 1;
		
	    while ( factory.getProxy( objectName, AMX.class, false ) != null )
	    {
			mySleep( millis );
			millis	*= 2;
			trace( "waitProxyGone: waiting for proxy to disappear: " + objectName );
	    }
	
protected voidwaitUnregistered(javax.management.ObjectName objectName)

	    final MBeanServerConnection	conn	= getConnection();
	    if ( conn.isRegistered( objectName ) )
	    {
	    	mySleep( 100 );
	    }

	    while ( conn.isRegistered( objectName ) )
	    {
	    	trace( "waitUnregistered: " + objectName);
	    	mySleep( 100 );
	    }	    
	
protected final voidwarnNotTested()

		final Set<ObjectName>	notTested	= getNotTestedSet();
		
		if ( notTested.size() != 0 )
		{
			final Set	j2eeTypes	=
				JMXUtil.getKeyPropertySet( AMX.J2EE_TYPE_KEY, notTested );
			
			trace( "WARNING: DID NOT TEST: " + notTested.size() + " MBeans of types {" +
				toString( j2eeTypes ) + "}" );
		}