Search in sources :

Example 6 with ACSLogParser

use of alma.acs.logging.engine.parser.ACSLogParser in project ACS by ACS-Community.

the class CacheTest method fillCache.

/**
	 * Fill the cache with dynamically generated logs
	 * The number of logs inserted in the list is greater than the 
	 * memory cache size to stress the disk cache also.
	 * 
	 * @return The number of logs inserted in the cache
	 * 
	 * @throws Exception
	 */
private long fillCache() throws Exception {
    ACSLogParser parser = ACSLogParserFactory.getParser();
    String logMsg = "Test log nr. ";
    // Yesterday
    long now = Calendar.getInstance().getTimeInMillis() - 1000 * 60 * 60 * 24;
    SimpleDateFormat df = new IsoDateFormat();
    cache.clear();
    long logToInsert = 2 * cache.getCacheSize();
    for (int t = 0; t < logToInsert; t++) {
        Date dt = new Date(now + t * 1000);
        StringBuffer dateSB = new StringBuffer();
        FieldPosition pos = new FieldPosition(0);
        df.format(dt, dateSB, pos);
        String newLogMsg = logMsg + "t";
        StringBuilder logStr = new StringBuilder("<Info TimeStamp=\"");
        logStr.append(dateSB.toString());
        logStr.append("\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[");
        logStr.append(newLogMsg);
        logStr.append("]]></Info>");
        ILogEntry newLog = parser.parse(logStr.toString());
        cache.add(newLog);
    }
    return logToInsert;
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) ACSLogParser(alma.acs.logging.engine.parser.ACSLogParser) IsoDateFormat(alma.acs.util.IsoDateFormat) FieldPosition(java.text.FieldPosition) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 7 with ACSLogParser

use of alma.acs.logging.engine.parser.ACSLogParser in project ACS by ACS-Community.

the class CacheTest method testTimeFrameCalc.

/**
	 * Check the calculation of the time frame 
	 * 
	 * @throws Exception
	 */
public void testTimeFrameCalc() throws Exception {
    ACSLogParser parser = ACSLogParserFactory.getParser();
    // Create some logs with a time frame of 10sec
    String logStr1 = "<Info TimeStamp=\"2005-11-29T15:33:10.000\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[Test1]]></Info>";
    String logStr2 = "<Info TimeStamp=\"2005-11-29T15:33:20.000\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[Test2]]></Info>";
    String logStr3 = "<Info TimeStamp=\"2005-11-29T15:33:15.000\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[Test3]]></Info>";
    String logStr4 = "<Info TimeStamp=\"2005-11-29T15:33:12.000\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[Test4]]></Info>";
    cache.clear();
    cache.add(parser.parse(logStr1));
    cache.add(parser.parse(logStr2));
    cache.add(parser.parse(logStr3));
    cache.add(parser.parse(logStr4));
    Calendar cal = cache.getTimeFrame();
    assertEquals("The time frame is wrong", 10 * 1000, cal.getTimeInMillis());
}
Also used : Calendar(java.util.Calendar) ACSLogParser(alma.acs.logging.engine.parser.ACSLogParser)

Example 8 with ACSLogParser

use of alma.acs.logging.engine.parser.ACSLogParser in project ACS by ACS-Community.

the class CacheTest method testReplace.

/**
	 * Test the replacement of a log
	 *
	 */
public void testReplace() throws Exception {
    ACSLogParser parser = ACSLogParserFactory.getParser();
    String logMsg = "Replaced test log";
    String logStr = "<Info TimeStamp=\"2005-11-29T16:00:00.000\" Routine=\"CacheTest::testReplace\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[" + logMsg + "]]></Info>";
    ILogEntry newLog = parser.parse(logStr);
    // Replace the first log
    cache.replaceLog(0, newLog);
    assertEquals("Error replacing log " + 0, logMsg, (String) cache.getLog(0).getField(LogField.LOGMESSAGE));
    // Replace the last log
    cache.replaceLog(cache.getSize() - 1, newLog);
    assertEquals("Error replacing log " + (cache.getSize() - 1), logMsg, (String) cache.getLog(cache.getSize() - 1).getField(LogField.LOGMESSAGE));
    // Replace a log in the middle
    int pos = cache.getSize() / 2;
    cache.replaceLog(pos, newLog);
    assertEquals("Error replacing log " + pos, logMsg, (String) cache.getLog(pos).getField(LogField.LOGMESSAGE));
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) ACSLogParser(alma.acs.logging.engine.parser.ACSLogParser)

Example 9 with ACSLogParser

use of alma.acs.logging.engine.parser.ACSLogParser in project ACS by ACS-Community.

the class CacheTest method testAddLog.

/**
	 * Check the add method by inserting and reading a log
	 *
	 */
public void testAddLog() throws Exception {
    ACSLogParser parser = ACSLogParserFactory.getParser();
    int oldSize = cache.getSize();
    String logMsg = "Test log";
    String logStr = "<Info TimeStamp=\"2005-11-29T15:33:10.592\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[" + logMsg + "]]></Info>";
    ILogEntry newLog = parser.parse(logStr);
    cache.add(newLog);
    assertEquals("Error adding a log", cache.getSize(), oldSize + 1);
    ILogEntry log = cache.getLog(cache.getSize() - 1);
    String msg = (String) log.getField(LogField.LOGMESSAGE);
    assertEquals("Error adding a log", logMsg, msg);
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) ACSLogParser(alma.acs.logging.engine.parser.ACSLogParser)

Example 10 with ACSLogParser

use of alma.acs.logging.engine.parser.ACSLogParser in project ACS by ACS-Community.

the class AntennaSourceReductionTest method createLog.

/**
	 * Create a log entry with the passed message and source
	 * 
	 * @param logMsg The message
	 * @param logSrc The source
	 * @return The log entry
	 * @throws Exception
	 */
private ILogEntry createLog(String logMsg, String logSrc) throws Exception {
    ACSLogParser parser = ACSLogParserFactory.getParser();
    long now = Calendar.getInstance().getTimeInMillis();
    SimpleDateFormat df = new IsoDateFormat();
    Date dt = new Date(now);
    StringBuffer dateSB = new StringBuffer();
    FieldPosition pos = new FieldPosition(0);
    df.format(dt, dateSB, pos);
    StringBuilder logStr = new StringBuilder("<Info TimeStamp=\"");
    logStr.append(dateSB.toString());
    logStr.append("\" Routine=\"CacheTest::testGet\" SourceObject=\"");
    logStr.append(logSrc);
    logStr.append("\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[");
    logStr.append(logMsg);
    logStr.append("]]></Info>");
    ILogEntry newLog = parser.parse(logStr.toString());
    return newLog;
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) ACSLogParser(alma.acs.logging.engine.parser.ACSLogParser) IsoDateFormat(alma.acs.util.IsoDateFormat) FieldPosition(java.text.FieldPosition) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

ACSLogParser (alma.acs.logging.engine.parser.ACSLogParser)13 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)11 IsoDateFormat (alma.acs.util.IsoDateFormat)5 FieldPosition (java.text.FieldPosition)5 SimpleDateFormat (java.text.SimpleDateFormat)5 Date (java.util.Date)5 ParserTypes (alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes)2 AdditionalData (com.cosylab.logging.engine.log.ILogEntry.AdditionalData)2 LogField (com.cosylab.logging.engine.log.LogField)2 Vector (java.util.Vector)2 IOHelper (alma.acs.logging.engine.io.IOHelper)1 XMLConverter (alma.acs.logging.tools.XMLConverter)1 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)1 Calendar (java.util.Calendar)1