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;
}
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());
}
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));
}
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);
}
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;
}
Aggregations