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

CoverageInfoAnalyzer

public final class CoverageInfoAnalyzer extends Object
Analyze the CoverageInfo for AMX MBeans. Use only after tests have been run.

Fields Summary
private final com.sun.appserv.management.DomainRoot
mDomainRoot
private final com.sun.appserv.management.base.QueryMgr
mQueryMgr
private final TestUtil
mTestUtil
private final String
NEWLINE
private static final Set
IGNORE_METHODS
private static final Set
IGNORE_UNKNOWN
Constructors Summary
public CoverageInfoAnalyzer(com.sun.appserv.management.DomainRoot domainRoot)

	    mDomainRoot   = domainRoot;
	    mQueryMgr     = domainRoot.getQueryMgr();
	    mTestUtil     = new TestUtil( domainRoot );
	    
	    final AMXDebugStuff debugRoot   = mTestUtil.asAMXDebugStuff( mDomainRoot );
	    if ( debugRoot == null )
	    {
	        throw new RuntimeException( "AMX-DEBUG/CoverageInfo is not enabled" );
	    }
	    
	    final CoverageInfo coverageInfo = debugRoot.getCoverageInfo();
	    
	    if ( coverageInfo instanceof CoverageInfoDummy )
	    {
	        throw new IllegalArgumentException( "Coverage disabled--add system property " +
	        "'-DAMX-DEBUG=true', then restart server" );
	    }
	    
	    NEWLINE = System.getProperty( "line.separator" );
	
Methods Summary
protected java.lang.StringcreateMissingString(java.lang.String msg)

	    String  result  = "";
	    
	    final Set<String>   missing   = findMissingJ2EETypes();
	    if ( missing.size() != 0 )
	    {
    	    final Set<String>   missingConfig     = new HashSet<String>();
    	    final Set<String>   missingMonitors   = new HashSet<String>();
    	    final Set<String>   missingOthers     = new HashSet<String>();
    	    
    	    groupMissingJ2EETypes( missing, missingConfig, missingMonitors, missingOthers );
    	    
            result = msg + NEWLINE + 
            "Config: " + NEWLINE +
                setToSortedString( missingConfig, NEWLINE) + NEWLINE + NEWLINE +
            "Monitor: " + NEWLINE +
                setToSortedString( missingMonitors, NEWLINE) + NEWLINE + NEWLINE +
            "J2EE/Other: " + NEWLINE +
                setToSortedString( missingOthers, NEWLINE);
	    }
	    
	    return result;
	
protected java.util.SetfindMissingJ2EETypes()

return
Set of j2eeTypes for which no MBeans exist

	    final Set<String>   missing = new HashSet<String>();
	    missing.addAll( XTypesMapper.getInstance().getJ2EETypes() );
	    missing.addAll( J2EETypesMapper.getInstance().getJ2EETypes() );
	    
	    missing.removeAll( mTestUtil.findRegisteredJ2EETypes() );
	    
	    final Set<ObjectName>   registered  =
	        Observer.getInstance().getRegistrationListener().getRegistered();
	    for( final ObjectName objectName : registered )
	    {
	        final String    j2eeType    = Util.getJ2EEType( objectName );
	        if ( j2eeType != null )
	        {
	            missing.remove( j2eeType );
	        }
	    }
	    
	    return missing;
	
public java.util.MapgetCoverage(java.util.Set candidates)

	    final Map<String,CoverageInfo>  coverageMap    = new HashMap<String,CoverageInfo>();
	    
	    for( final AMX amx: candidates )
	    {
	        final AMXDebugStuff debug   = mTestUtil.asAMXDebugStuff( amx );
	        final CoverageInfo  coverageInfo = debug.getCoverageInfo();
	        assert( coverageInfo != null );
	        handleSpecialCases( coverageInfo );
	        
	        final String j2eeType   = amx.getJ2EEType();
	        final CoverageInfo  existing    = coverageMap.get( j2eeType );
	        if ( existing != null )
	        {
	            existing.merge( coverageInfo );
	        }
	        else
	        {
	            coverageMap.put( j2eeType, coverageInfo );
	        }
	    }
	    
        return coverageMap;
	
public java.lang.StringgetCoverageSummary()

	    final Set<AMX>  amx = mTestUtil.getAllAMX();
	    final Map<String,CoverageInfo>  coverage    = getCoverage( amx );
	    
	    final String[]  j2eeTypes = GSetUtil.toStringArray( coverage.keySet() );
	    Arrays.sort( j2eeTypes );
	    
	    final String LINE_SEP  = System.getProperty( "line.separator" );
	    
	    final StringBuilder builder = new StringBuilder();
	    for( final String j2eeType : j2eeTypes )
	    {
	        final CoverageInfo  info    = coverage.get( j2eeType );
	        
	        final String    infoString  =
	            "Coverage for j2eeType = " + j2eeType + 
	            ": " + (info.getFullCoverage() ? "100%" : "INCOMPLETE COVERAGE" ) +
	            LINE_SEP +
	            info.toString( false ) + LINE_SEP + LINE_SEP;
	        
	        builder.append( infoString );
	    }
	    
	    final String msg    = 
    	    "No AMX MBeans having the following types " +
    	        "were ever present, and so were NEVER TESTED:" + NEWLINE;
	    builder.append( createMissingString( msg ) );
	        
	    return builder.toString();
	
protected voidgroupMissingJ2EETypes(java.util.Set allMissing, java.util.Set missingConfigs, java.util.Set missingMonitors, java.util.Set missingOthers)

	    for( final String j2eeType : allMissing )
	    {
	        if ( j2eeType.endsWith( "Config" ) )
	        {
	            missingConfigs.add( j2eeType );
	        }
	        else if ( j2eeType.endsWith( "Monitor" ) )
	        {
	            missingMonitors.add( j2eeType );
	        }
	        else
	        {
	            missingOthers.add( j2eeType );
	        }
	    }
	
private voidhandleSpecialCases(com.sun.enterprise.management.support.CoverageInfo coverageInfo)
Certain methods will never be called via remote access due to the JMX implementation. removeNotificationListener() in particular is only invoked in one way by the MBeanServer in response to remote clients registering listeners. Omit these cases, since they will never be invoked.

		              	         	               	            	        	 
	     
        
    
        final Set<String>   notInvoked  = coverageInfo.getOperationsNotInvoked();
        
        for( final String op : notInvoked )
        {
            for( final String prefix : IGNORE_METHODS )
            {
                if ( op.startsWith( prefix ) )
                {
                    coverageInfo.markAsInvoked( op );
                }
            }
        }
        
        // make a copy, we'll be modifying it
        final Set<String> unknown =coverageInfo.getUnknownAttributes().keySet();
        for( final String s : unknown )
        {
            if ( s.startsWith( "bogus" ) ||
                IGNORE_UNKNOWN.contains( s ) )
            {
                coverageInfo.ignoreUnknownAttribute( s );
            }
        }
    
private java.lang.StringsetToSortedString(java.util.Set s, java.lang.String delim)

        final String[]  a    = GSetUtil.toStringArray( s );
        Arrays.sort( a );
	   
	    return StringUtil.toString( NEWLINE, (Object[])a );