FileDocCategorySizeDatePackage
J2EETest.javaAPI DocGlassfish v2 API13661Fri May 04 22:24:04 BST 2007com.sun.enterprise.management.j2ee

J2EETest

public final class J2EETest extends com.sun.enterprise.management.AMXTestBase

Fields Summary
private static boolean
FAILURES_WARNED
private static final Map
ToConfigMap
Map from JSR77 j2eeType to our config j2eeType.
private static final Map
ToMonitorMap
Maps a j2eeType to its peer monitoring j2eeType
private static final Set
HasNoStats
Constructors Summary
public J2EETest()

		turnOnMonitoring();
	
Methods Summary
private booleanappearsToBeDefaultWebModule(java.lang.String webModuleName)

	    return webModuleName.startsWith( "//" ) && webModuleName.endsWith( "/" );
	
public static com.sun.enterprise.management.CapabilitiesgetCapabilities()

	
	      
	
	
	    return getOfflineCapableCapabilities( false );
	
private static java.lang.StringgetConfigPeerJ2EEType(java.lang.String j2eeType)

	
		  
	    
	
		return ToConfigMap.get( j2eeType );
	
protected java.lang.StringgetMonitoringPeerJ2EEType(java.lang.String j2eeType)

	    
	    
		 
	    
	
		return ToMonitorMap.get( j2eeType );
	
protected java.lang.StringgetMonitoringPeerProps(com.sun.appserv.management.j2ee.J2EEManagedObject item)

	    final String j2eeType   = item.getJ2EEType();
	    final String monitoringPeerJ2EEType = getMonitoringPeerJ2EEType( j2eeType );
	    final ObjectName    objectName  = Util.getObjectName( item );
	    
	    String  props   = null;
	    if ( monitoringPeerJ2EEType != null )
	    {
            props  = Util.makeRequiredProps( monitoringPeerJ2EEType, item.getName() );

            for( final String propKey : ToMonitorMap.keySet() )
            {
                final String value  = objectName.getKeyProperty( propKey );
                if ( value != null )
                {
                    final String prop   =
                        Util.makeProp( getMonitoringPeerJ2EEType( propKey ), value );
                    props   = Util.concatenateProps( props, prop );
                }
            }
    	}
    	
    	return props;
	
public voidtestJ2EE()

		final QueryMgr	queryMgr	= getQueryMgr();
		
		final Set<J2EEManagedObject>	j2eeAll	= 
		    queryMgr.queryInterfaceSet( J2EEManagedObject.class.getName(), null);
		
		final Set<ObjectName>	failedSet	= new HashSet<ObjectName>();
		final Set<ObjectName>	noPeerSet	= new HashSet<ObjectName>();
		
		for( final J2EEManagedObject item : j2eeAll )
		{
			final ObjectName	objectName	= Util.getObjectName( item );
			assert( objectName.equals( Util.newObjectName( item.getobjectName() ) ) );
			
			final String j2eeType   = item.getJ2EEType();
			
			if ( item.isstateManageable() )
			{
				assert( item instanceof StateManageable );
				
				final StateManageable	sm	= (StateManageable)item;
				
				final int	state	= sm.getstate();
				assert( state == StateManageable.STATE_STARTING ||
					state == StateManageable.STATE_RUNNING ||
					state == StateManageable.STATE_STOPPING ||
					state == StateManageable.STATE_STOPPED ||
					state == StateManageable.STATE_FAILED );
				
				if ( state == StateManageable.STATE_RUNNING )
				{
					try
					{
						final long	startTime	= sm.getstartTime();
					
						// assume it was started less than 30 days ago
						final long MILLIS_PER_DAY	= 24L * 60L * 60L * 1000L;
						final long days30	= 30L * MILLIS_PER_DAY;
						if ( startTime < now() - days30 )
						{
							warning( "MBean " + quote( objectName ) +
							" claims a start time of " +  new Date( startTime ) + ", which is more than 30 days prior to now = " +
								new Date( now() ) );
							failedSet.add( objectName );
						}
					}
					catch( Exception e )
					{
						final Throwable	rootCause	= ExceptionUtil.getRootCause( e );
						warning( "MBean " + quote( objectName ) +
						" is 'stateManageable' and in 'STATE_RUNNING', but could not supply Attribute 'startTime', " +
						"threw an exception of class " +
							rootCause.getClass().getName() );
							failedSet.add( objectName );
					}
				}
			}
			
			if ( item.iseventProvider() )
			{
				assert( item instanceof EventProvider );
				
				final EventProvider	ep	= (EventProvider)item;
				final String[]	types	= ep.gettypes();
				assert types != null :
				    "Item claims to be EventProvider, but provides null 'types': " +
				        toString( objectName );
			}
			
			/*
				 monitoring was enabled so monitoring peers should exist
				 Can't just call isStatisticProvider(), since it will be false
				 if the monitoring peer is null (correctly or incorrectly).
		     */
		    final String monitoringPeerJ2EEType = getMonitoringPeerJ2EEType( j2eeType );
		    final Monitoring    monitoringPeer  = item.getMonitoringPeer();
			if ( monitoringPeerJ2EEType != null )
			{
			    // See if there actually is a monitoring peer, but null is being returned.
				if ( monitoringPeer == null )
				{
    			    final String props  = getMonitoringPeerProps( item );
    			    final Set<Monitoring>  monitors    = getQueryMgr().queryPropsSet( props );
    			    if ( monitors.size() != 0 )
    			    {
    					warning( "MBean " + quote( objectName ) +
    					" returned null for its monitoring peer, but found the following:" +
    					    NEWLINE +
    					    CollectionUtil.toString( Util.toObjectNames( monitors ), NEWLINE ) );
    					    
    					failedSet.add( objectName );
    				}
				}
				else
				{
				    // we have a monitoring peer, verify that it states that it has
				    // statistics
					if ( ! HasNoStats.contains( j2eeType ) )
					{
				        assert item.isstatisticProvider() && item.isstatisticsProvider();
				    }
				}
			}
			else
			{
			    // it has a monitoring peer
				if ( item.isstatisticProvider() || item.isstatisticsProvider() )
				{ 
					warning( "MBean " + quote( objectName ) +
					    " should not have its statisticProvider set to true" );
					failedSet.add( objectName );
				}
			}
			
			
			if ( item.isConfigProvider() )
			{
				final AMXConfig	config	= item.getConfigPeer();
				
				if ( config == null )
				{
				    // Some auto-generated items do not have config.  See if it's there
				    final String props  = Util.makeRequiredProps(
				        getConfigPeerJ2EEType( j2eeType ), item.getName() );
				    
				    if ( getQueryMgr().queryPropsSet( props ).size() != 0 )
				    {
    					warning( "MBean " + quote( objectName ) +
    					" has existing config peer, but returned null" );
    					failedSet.add( objectName );
					}
				}
			}
		}
		
		if ( noPeerSet.size() != 0 )
		{
		    warning( "The following MBeans do not have a Monitoring peer:" +
		        NEWLINE + toString( noPeerSet ) );
			
	    }
						
		if( failedSet.size() != 0 )
		{
			failure( "Failures in the following " + failedSet.size() + " MBeans:\n" +
			    toString( failedSet ) );
		}
	
public voidtestJ2EEClusterMatchesClusterConfig()
Verify that there is one J2EEServer for each ServerConfig (standalone or not)

		final Map<String,ClusterConfig>	clusterConfigMap	= getDomainConfig().getClusterConfigMap();
		final Map<String,J2EECluster>	j2eeClusterMap	= getJ2EEDomain().getJ2EEClusterMap();
		
		assert( clusterConfigMap.keySet().equals( j2eeClusterMap.keySet() ) ) :
			"ClusterConfig names do not match J2EECluster names, ClusterConfig names = " +
			toString( clusterConfigMap.keySet() ) + ", J2EECluster names = " +
			toString( j2eeClusterMap.keySet() );
	
public voidtestJ2EEServerMatchesServerConfig()
Verify that there is one J2EEServer for each ServerConfig (standalone or not)

		final Map<String,ServerConfig>	serverConfigMap	=
		    getDomainConfig().getServerConfigMap();
		    
		final Map<String,J2EEServer>	j2eeServerMap	=
		    getDomainRoot().getJ2EEDomain().getJ2EEServerMap();
		
		assert( serverConfigMap.keySet().equals( j2eeServerMap.keySet() ) ) :
			"ServerConfig names do not match J2EEServer names, ServerConfig names = " +
			toString( serverConfigMap.keySet() ) + ", J2EEServer names = " +
			toString( j2eeServerMap.keySet() );
		
	
public voidtestJVMs()

		final QueryMgr	queryMgr	= getQueryMgr();
		
		final Set	jvms	= queryMgr.queryJ2EETypeSet( J2EETypes.JVM );
		final Iterator	iter	= jvms.iterator();
		
		String	lastVendor	= null;
		String	lastVersion	= null;
		while ( iter.hasNext() )
		{
			final JVM	jvm	= (JVM)iter.next();
			
			// the ObjectName of the Node must match the String version for "node"
			assert( jvm.getnode() != null );
			
			// the JVMs should all have the same vendor (presumably)
			assert( jvm.getjavaVendor() != null );
			if ( lastVendor == null )
			{
				lastVendor	= jvm.getjavaVendor();
			}
			else
			{
				assert( lastVendor.equals( jvm.getjavaVendor() ) );
			}
			
			// the JVMs should all have the same version (presumably)
			assert( jvm.getjavaVersion() != null );
			if ( lastVersion == null )
			{
				lastVersion	= jvm.getjavaVersion();
			}
			else
			{
				assert( lastVersion.equals( jvm.getjavaVersion() ) );
			}
		}