FileDocCategorySizeDatePackage
LogMBeanTest.javaAPI DocGlassfish v2 API9367Fri May 04 22:24:04 BST 2007com.sun.enterprise.management.ext.logging

LogMBeanTest

public final class LogMBeanTest extends com.sun.enterprise.management.AMXTestBase
Test the LogMBean. It is not part of AMX, but we rely on it closely, so ensure that it works.

Fields Summary
private com.sun.enterprise.management.ext.logging.LogMBeanIntf
mLogMBean
final ObjectName
mTarget
Constructors Summary
public LogMBeanTest()

	    mTarget  =
            Util.newObjectName( "com.sun.appserv:name=logmanager,category=runtime,server=server" );

	    mLogMBean   = initLogMBean();
	
Methods Summary
private voidaddListener(com.sun.enterprise.management.ext.logging.LogMBeanIntf logMBean)

	    final MyLogMBeanListener listener = new MyLogMBeanListener();
	    final NotificationFilter filter = null;
	    logMBean.addNotificationListener( listener, filter, null );
	
private com.sun.appserv.management.ext.logging.LogQueryResultconvertQueryResult(javax.management.AttributeList queryResult)

	    // extract field descriptions into a String[]
	    final AttributeList   fieldAttrs    = (AttributeList)((Attribute)queryResult.get( 0 )).getValue();
	    final String[]  fieldHeaders  = new String[ fieldAttrs.size() ];
	    assert( fieldHeaders.length == LogRecordFields.NUM_FIELDS );
	    for( int i = 0; i < fieldHeaders.length; ++i )
	    {
	        final Attribute attr    = (Attribute)fieldAttrs.get( i );
	        fieldHeaders[ i ] = (String)attr.getValue();
	        //System.out.println( fieldHeaders[ i ] );
	    }
	    
	    // extract every record
	    final List<List<Serializable>> records    =
	        TypeCast.asList( ((Attribute)queryResult.get( 1 )).getValue() );
	    final LogQueryEntry[]  entries = new LogQueryEntry[ records.size() ];
	    for( int recordIdx = 0; recordIdx < records.size(); ++recordIdx )
	    {
	        final List<Serializable> record    = records.get( recordIdx );
	        TypeCast.checkList( record, Serializable.class );
	        
	        assert( record.size() == fieldHeaders.length );
	        final Serializable[]  fieldValues = new Serializable[ fieldHeaders.length ];
	        for( int fieldIdx = 0; fieldIdx < fieldValues.length; ++fieldIdx )
	        {
	            fieldValues[ fieldIdx ] = record.get( fieldIdx );
	        }
	        
	        entries[ recordIdx ]    = new LogQueryEntryImpl( fieldValues );
	    }
	    
	    return new LogQueryResultImpl( fieldHeaders, entries );
	
private voiddisplayAttribute(javax.management.Attribute attr)

	    trace( "Attribute: " + attr.getName() );
	    final Object    value   = attr.getValue();
	    trace( "    Value: " + (value == null ? "null" : value.getClass().getName()) );
	
public static com.sun.enterprise.management.CapabilitiesgetCapabilities()

	    return getOfflineCapableCapabilities( false );
	
public com.sun.enterprise.management.ext.logging.LogMBeanIntfgetLogMBean()

	    return mLogMBean;
	
public com.sun.enterprise.management.ext.logging.LogMBeanIntfinitLogMBean()

	    final LogMBeanIntf  logMBean	= (LogMBeanIntf)
		    MBeanServerInvocationHandler.newProxyInstance(
			    getConnection(), mTarget, LogMBeanIntf.class, true );
	    
	    return logMBean;
	
public voidtestGetArchivedLogFiles()

	    final String[]  names   = getLogMBean().getArchivedLogfiles();
	    //trace( "getArchivedLogFiles: " + ArrayStringifier.stringify( names, "\n") );
	
public voidtestGetLogFilesDirectory()

	    final String  name   = getLogMBean().getLogFilesDirectory();
	    //trace( "getLogFilesDirectory: " + name );
	
public voidtestGetLoggerNames()

	    final List<String> names   = TypeCast.asList( getLogMBean().getLoggerNames() );
	    TypeCast.checkList( names, String.class );
	    //System.out.println( "getLogFilesDirectory: " + names );
	    
	    for( final String name : names )
	    {
	        final String level  = getLogMBean().getLogLevel( name );
	        Level.parse( level );
	        
	        final List<String>  unders = TypeCast.asList( getLogMBean().getLoggerNamesUnder( name ) );
	        TypeCast.checkList( unders, String.class );
	    }
	
public voidtestQuery()

	    final String    filename    = "server.log";
	    final Boolean   searchForward   = Boolean.TRUE;
	    final Boolean   sortAscending   = Boolean.TRUE;
	    final int       startRecord = 0;
	    final int       requestedCount  = 1000 * 1000;
	    final Date      fromDate    = null;
	    final Date      toDate    = null;
	    final List<Object>      listOfModules   = null;
	    final Boolean   levelOnly   = Boolean.FALSE;
	    final Properties    props   = null;
	    
	    final AttributeList attrs   = getLogMBean().getLogRecordsUsingQuery(
	        filename,
	        new Long( startRecord ),
	        searchForward,
	        sortAscending,
	        new Integer( requestedCount ),
	        fromDate,
	        toDate,
	        Level.WARNING.toString(),
	        levelOnly,
	        listOfModules,
	        props );
	   
	   final LogQueryResult result  = convertQueryResult( attrs );
	   
	   final LogQueryEntry[]    entries = result.getEntries();
	   assert( entries.length != 0 );
	   
	   for( final LogQueryEntry entry : entries )
	   {
	        final String    messageID   = entry.getMessageID();
	        
	        final ArrayList  causes  = getLogMBean().getDiagnosticCausesForMessageId( messageID );
	        //trace( causes );
	        final ArrayList  checks  = getLogMBean().getDiagnosticChecksForMessageId( messageID );
	        //trace( checks );
	        final String    uri  = getLogMBean().getDiagnosticURIForMessageId( messageID );
	        //trace( uri );
	   }
	   
	  // trace( result );