Search in sources :

Example 46 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.

the class EngineAudienceTest method testOperatorModeFiltering.

/**
	 * Test the filtering for OPERATOR.
	 * 
	 * The logs that should not be filtered are those that:
	 *  - have a level of WARINING or greater
	 *  - have the audience set to OPERATOR 
	 *  
	 *  The test is done in 2 times:
	 *   1. a collection of logs with no audience is tested
	 *   2. a collection of logs with different values for audience 
	 *      is tested
	 *  
	 * @throws Exception
	 */
public void testOperatorModeFiltering() throws Exception {
    audience = AudienceInfo.OPERATOR.getAudience();
    logRetieval.setAudience(audience);
    //
    // Step 1: generate a collection of logs with no audience
    //
    // Generate 1000 log of each type
    Collection<ILogEntry> logs = new Vector<ILogEntry>();
    for (LogTypeHelper logType : LogTypeHelper.values()) {
        if (logType != LogTypeHelper.OFF) {
            Collection<ILogEntry> tempLogs = CacheUtils.generateLogsType(1000, logType);
            logs.addAll(tempLogs);
        }
    }
    assertEquals(1000 * (LogTypeHelper.values().length - 1), logs.size());
    for (ILogEntry log : logs) {
        logRetieval.addLog(log.toXMLString());
    }
    // Wait until logRetrieval publish all the logs
    assertFalse("Timeout waiting for logs", waitForLogs());
    // Check the received logs
    assertEquals(logs.size(), numOfReceivedXMLLogs);
    assertEquals(1000 * 5, numOfReceivedLogs);
    // 
    // Step 2: test a collection of logs with the audience
    //
    ACSLogParser parser = ACSLogParserFactory.getParser();
    assertNotNull(parser);
    SimpleDateFormat df = new IsoDateFormat();
    assertNotNull(df);
    // Generate 2 logs for each type.
    // only one of them with audience OPERATOR
    logs.clear();
    for (LogTypeHelper logType : LogTypeHelper.values()) {
        if (logType == LogTypeHelper.OFF) {
            continue;
        }
        Date dt = new Date(System.currentTimeMillis());
        StringBuffer dateSB = new StringBuffer();
        FieldPosition pos = new FieldPosition(0);
        df.format(dt, dateSB, pos);
        StringBuilder logOperatorStr = new StringBuilder("<");
        StringBuilder logNoOperatorStr = new StringBuilder();
        // (see COMP-3749 : JDK levels FINER and FINEST were previously mapped to TRACE, while now FINER maps to DELOUSE).
        if (logType == LogTypeHelper.TRACE || logType == LogTypeHelper.DELOUSE) {
            logType = LogTypeHelper.INFO;
        }
        logOperatorStr.append(logType.logEntryType);
        logOperatorStr.append(logHeaderStr);
        logOperatorStr.append(dateSB.toString());
        logOperatorStr.append(logBodyStr);
        // Insert the audience
        logNoOperatorStr = new StringBuilder(logOperatorStr);
        logOperatorStr.append(alma.log_audience.OPERATOR.value);
        logNoOperatorStr.append(alma.log_audience.DEVELOPER.value);
        logOperatorStr.append(logEndOfBodyStr);
        logNoOperatorStr.append(logEndOfBodyStr);
        logOperatorStr.append("LOG Txt>");
        logNoOperatorStr.append("LOG Txt>");
        logOperatorStr.append(logFooterStr);
        logNoOperatorStr.append(logFooterStr);
        logOperatorStr.append(logType.logEntryType);
        logNoOperatorStr.append(logType.logEntryType);
        logOperatorStr.append('>');
        logNoOperatorStr.append('>');
        ILogEntry logOp = parser.parse(logOperatorStr.toString());
        logs.add(logOp);
        ILogEntry logNoOp = parser.parse(logNoOperatorStr.toString());
        logs.add(logNoOp);
    }
    assertEquals(2 * (LogTypeHelper.values().length - 1), logs.size());
    numOfReceivedLogs = 0;
    numOfReceivedXMLLogs = 0;
    for (ILogEntry log : logs) {
        logRetieval.addLog(log.toXMLString());
    }
    assertFalse("Timeout waiting for logs", waitForLogs());
    assertEquals(logs.size(), numOfReceivedXMLLogs);
    assertEquals(10, numOfReceivedLogs);
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogTypeHelper(com.cosylab.logging.engine.log.LogTypeHelper) ACSLogParser(alma.acs.logging.engine.parser.ACSLogParser) IsoDateFormat(alma.acs.util.IsoDateFormat) FieldPosition(java.text.FieldPosition) Vector(java.util.Vector) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 47 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.

the class EngineAudienceTest method testNoAudienceModeFiltering.

/**
	 * Test the case of ENGINEER i.e. no filtering
	 * 
	 * @throws Exception
	 */
public void testNoAudienceModeFiltering() throws Exception {
    audience = AudienceInfo.ENGINEER.getAudience();
    logRetieval.setAudience(audience);
    Collection<ILogEntry> logs = CacheUtils.generateLogs(10000);
    for (ILogEntry log : logs) {
        logRetieval.addLog(log.toXMLString());
    }
    assertEquals(10000, logs.size());
    assertFalse("Timeout waiting for logs", waitForLogs());
    // All logs received or timeout
    assertEquals(numOfReceivedXMLLogs, logs.size());
    assertEquals(numOfReceivedLogs, logs.size());
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry)

Example 48 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.

the class ACSLogParserTest method testSpecialLogs.

/**
	 * Test special logs i.e. logs that sometime have returned errors while parsing.
	 * 
	 * @see <code>specialLogs</code>
	 * @throws Exception
	 */
public void testSpecialLogs() throws Exception {
    // Cycle through all available parsers
    for (ParserTypes type : ParserTypes.values()) {
        System.out.println("testSpecialLogs: Testing parser " + type);
        parser = ACSLogParserFactory.getParser(type);
        assertNotNull(parser);
        assertEquals(type, ACSLogParserFactory.getParserType(parser));
        for (String xmlLog : specialLogs) {
            ILogEntry log = parser.parse(xmlLog);
            Vector<AdditionalData> data = log.getAdditionalData();
            if (data != null) {
                for (int t = 0; t < data.size(); t++) {
                    AdditionalData d = data.get(t);
                    System.out.println("Data:  name=" + d.name + ", value=" + d.value);
                }
            } else {
                System.out.println("The log has no additional data entries");
            }
            System.out.println("Body: " + log.getField(LogField.LOGMESSAGE));
        }
    }
}
Also used : AdditionalData(com.cosylab.logging.engine.log.ILogEntry.AdditionalData) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) ParserTypes(alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes)

Example 49 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.

the class ACSLogParserTest method testFields.

/**
	 * Check if the fields are read as expected
	 * 
	 * @throws Exception
	 */
public void testFields() throws Exception {
    // Cycle through all available parsers
    for (ParserTypes type : ParserTypes.values()) {
        System.out.println("testFields: Testing parser " + type);
        parser = ACSLogParserFactory.getParser(type);
        assertNotNull(parser);
        assertEquals(type, ACSLogParserFactory.getParserType(parser));
        ILogEntry log = parser.parse(xmlLogInfo1);
        assertNotNull(log);
        // Check the date
        Long logDate = (Long) log.getField(LogField.TIMESTAMP);
        assertNotNull(logDate);
        Long xmlDate = null;
        SimpleDateFormat dateFormat = new IsoDateFormat();
        Date date = dateFormat.parse("2006-03-28T00:26:29.238");
        xmlDate = Long.valueOf(date.getTime());
        assertEquals("The dates differ", xmlDate, logDate);
        // Check the log type
        assertEquals(LogTypeHelper.INFO, (LogTypeHelper) log.getField(LogField.ENTRYTYPE));
        // Check the file
        assertEquals("maciContainerImpl.cpp", log.getField(LogField.FILE));
        // Check the line
        assertEquals(Integer.valueOf(1454), log.getField(LogField.LINE));
        // Check the routine
        assertEquals("maci::ContainerImpl::initThread", log.getField(LogField.ROUTINE));
        // Check the host
        assertEquals("gas", log.getField(LogField.HOST));
        // Check the process
        assertEquals("maciContainer", log.getField(LogField.PROCESS));
        // Check the thread
        assertEquals("ARCHIVE_BULKSENDER::actionThread", log.getField(LogField.THREAD));
        // Check the Antenna
        assertEquals("CTXT", log.getField(LogField.CONTEXT));
        // Check the source object
        assertEquals("ARCHIVE_BULKSENDER::source", log.getField(LogField.SOURCEOBJECT));
        // Check the stack level
        assertEquals(10, log.getField(LogField.STACKLEVEL));
        // Check the stack level
        assertEquals(3, log.getField(LogField.PRIORITY));
        // Check the stack level
        assertEquals("TheStackID", log.getField(LogField.STACKID));
        // Check the Audience
        assertEquals("Operator", log.getField(LogField.AUDIENCE));
        // Check the Array
        assertEquals("AnArray", log.getField(LogField.ARRAY));
        // Check the Antenna
        assertEquals("ThisIsTheAntenna", log.getField(LogField.ANTENNA));
    }
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) ParserTypes(alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes) IsoDateFormat(alma.acs.util.IsoDateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 50 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.

the class CacheUtils method generateLogs.

/**
	 * Generate a set of logs to be used for testing
	 * Each log has 
	 *    - a different time stamp.
	 *    - the message contains the key of the log
	 *    - the log type is random (all types but Trace because trace
	 *      has no body)
	 *
	 * @param numOfLogs The number of logs to put in the collection
	 * @return The collection with the logs
	 */
public static Collection<ILogEntry> generateLogs(int numOfLogs) throws Exception {
    Random rnd = new Random(Calendar.getInstance().getTimeInMillis());
    // Yesterday
    long now = Calendar.getInstance().getTimeInMillis() - 1000 * 60 * 60 * 24;
    SimpleDateFormat df = new IsoDateFormat();
    Vector<ILogEntry> v = new Vector<ILogEntry>(numOfLogs);
    for (int t = 0; t < numOfLogs; t++) {
        Date dt = new Date(now + t * 1000);
        StringBuffer dateSB = new StringBuffer();
        FieldPosition pos = new FieldPosition(0);
        df.format(dt, dateSB, pos);
        StringBuilder logStr = new StringBuilder("<");
        int typePos = rnd.nextInt(LogTypeHelper.values().length - 1);
        LogTypeHelper type = LogTypeHelper.values()[typePos];
        if (type == LogTypeHelper.TRACE) {
            type = LogTypeHelper.INFO;
        }
        logStr.append(type.logEntryType);
        logStr.append(logHeaderStr);
        logStr.append(dateSB.toString());
        logStr.append(logBodyStr);
        logStr.append(t);
        logStr.append(logFooterStr);
        logStr.append(type.logEntryType);
        logStr.append('>');
        if (parser == null) {
            parser = ACSLogParserFactory.getParser();
        }
        ILogEntry log = parser.parse(logStr.toString());
        v.add(log);
    }
    return v;
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) IsoDateFormat(alma.acs.util.IsoDateFormat) FieldPosition(java.text.FieldPosition) Date(java.util.Date) Random(java.util.Random) LogTypeHelper(com.cosylab.logging.engine.log.LogTypeHelper) SimpleDateFormat(java.text.SimpleDateFormat) Vector(java.util.Vector)

Aggregations

ILogEntry (com.cosylab.logging.engine.log.ILogEntry)85 Vector (java.util.Vector)15 ACSLogParser (alma.acs.logging.engine.parser.ACSLogParser)11 Date (java.util.Date)11 IsoDateFormat (alma.acs.util.IsoDateFormat)9 LogCacheException (com.cosylab.logging.client.cache.LogCacheException)9 AdditionalData (com.cosylab.logging.engine.log.ILogEntry.AdditionalData)9 SimpleDateFormat (java.text.SimpleDateFormat)9 FieldPosition (java.text.FieldPosition)8 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)7 LogEntry (com.cosylab.logging.engine.log.LogEntry)6 ParserTypes (alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes)5 LogBufferedFileCache (com.cosylab.logging.client.cache.LogBufferedFileCache)5 LogFileCache (com.cosylab.logging.client.cache.LogFileCache)5 Random (java.util.Random)5 IOHelper (alma.acs.logging.engine.io.IOHelper)4 LogCache (com.cosylab.logging.client.cache.LogCache)4 IOException (java.io.IOException)4 ILogMap (com.cosylab.logging.client.cache.ILogMap)3 LogField (com.cosylab.logging.engine.log.LogField)3