use of alma.acs.logging.engine.parser.ACSLogParser in project ACS by ACS-Community.
the class MultiFileCacheTest method testReplace.
/**
* Test replacement of logs
*
* @throws Exception
*/
public void testReplace() throws Exception {
System.out.println("testReplace started");
ACSLogParser parser = ACSLogParserFactory.getParser();
assertNotNull(parser);
// Create and populate the cache
Collection<ILogEntry> logCollection = CacheUtils.generateLogs(5000);
assertEquals(5000, logCollection.size());
for (ILogEntry log : logCollection) {
cache.add(log);
}
assertEquals(Integer.valueOf(0), cache.getFirstLog());
assertEquals(Integer.valueOf(4999), cache.getLastLog());
assertEquals(logCollection.size(), cache.getSize());
for (Integer t = cache.getFirstLog(); t <= cache.getLastLog(); t++) {
String logMsg = "This log replaced the log with key " + t;
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);
cache.replaceLog(t, newLog);
ILogEntry replacedLog = cache.getLog(t);
assertEquals(newLog.getField(LogField.LOGMESSAGE), replacedLog.getField(LogField.LOGMESSAGE));
}
System.out.println("testReplace done");
}
use of alma.acs.logging.engine.parser.ACSLogParser in project ACS by ACS-Community.
the class LoadSaveTest method testSaveLoadFields.
/**
* Save and Load the special logs then check their fields.
* <P>
* This test is performed comparing the fields of the special logs one by one
* instead of comparing the XMLs.
* The test does the following steps:
* <OL>
* <LI>build vector of logs to save from the XMLs in <code>specialLogs</code>
* <LI>save the vector of logs with an <code>IOHelper</code> object
* <LI>load the logs from file
* <LI>compare each field of the logs read from the file with those in <code>specialLogs</code>
* <LI>compare the additional data names and values
* </OL>
* <P>
* The test implicitly checks the conversion between XML and ILogEntry too.
*/
public void testSaveLoadFields() throws Exception {
ACSLogParser parser = ACSLogParserFactory.getParser();
assertNotNull(parser);
//Build the logs from the XML
Vector<ILogEntry> logsToCheck = new Vector<ILogEntry>();
for (int t = 0; t < specialLogs.length; t++) {
ILogEntry log = parser.parse(specialLogs[t]);
assertNotNull(log);
logsToCheck.add(log);
}
// Save the logs on disk
IOHelper ioHelper = new IOHelper();
assertNotNull(ioHelper);
ioHelper.saveLogs(fileName, logsToCheck, this, false, false);
assertEquals(logsToCheck.size(), numOfLogsWritten);
// Load the logs from disk
ioHelper.loadLogs(fileName, this, null, this, this, false);
assertEquals(logsRead.size(), logsToCheck.size());
// Iterate over the logs comparing each field
for (int t = 0; t < logsToCheck.size(); t++) {
ILogEntry originalLog = logsToCheck.elementAt(t);
assertNotNull(originalLog);
ILogEntry savedLog = logsRead.elementAt(t);
assertNotNull(savedLog);
// Check the fields
for (LogField f : LogField.values()) {
Object original = originalLog.getField(f);
Object saved = savedLog.getField(f);
assertEquals("Fields " + f + " differ", original, saved);
}
// Check additional data
assertEquals(originalLog.hasDatas(), savedLog.hasDatas());
if (originalLog.hasDatas()) {
Vector<AdditionalData> originalData = originalLog.getAdditionalData();
assertNotNull(originalData);
Vector<AdditionalData> savedData = savedLog.getAdditionalData();
assertNotNull(savedData);
assertEquals(originalData.size(), savedData.size());
for (int count = 0; count < originalData.size(); count++) {
AdditionalData originalDataItem = originalData.elementAt(count);
assertNotNull(originalDataItem);
AdditionalData savedDataItem = savedData.elementAt(count);
assertNotNull(savedDataItem);
assertEquals("Data names differ", originalDataItem.name, savedDataItem.name);
assertEquals("Data values differ", originalDataItem.value, savedDataItem.value);
}
}
}
}
use of alma.acs.logging.engine.parser.ACSLogParser in project ACS by ACS-Community.
the class CacheTest method testLogExceedingTimeFrame.
/**
* Check if the method returning the logs exceeding the time frame is
* working as expected.
*
* @throws Exception
*/
public void testLogExceedingTimeFrame() throws Exception {
ACSLogParser parser = ACSLogParserFactory.getParser();
// Create some logs
// The important fields here are the times (we'll test against a time frame of 30 secs)
// It is also important the message that is used to check which messages
// are added in the collection and which not
String logStr1 = "<Info TimeStamp=\"2005-11-29T15:33:55.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:10.000\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[Test3]]></Info>";
String logStr4 = "<Info TimeStamp=\"2005-11-29T15:34:15.000\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[Test4]]></Info>";
String logStr5 = "<Info TimeStamp=\"2005-11-29T15:33:12.000\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[Test5]]></Info>";
String logStr6 = "<Info TimeStamp=\"2005-11-29T15:34:05.000\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[Test6]]></Info>";
String logStr7 = "<Info TimeStamp=\"2005-11-29T15:34:15.000\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[Test7]]></Info>";
String logStr8 = "<Info TimeStamp=\"2005-11-29T15:34:10.000\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[Test8]]></Info>";
String logStr9 = "<Info TimeStamp=\"2005-11-29T15:33:25.000\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[Test9]]></Info>";
cache.clear();
cache.add(parser.parse(logStr1));
cache.add(parser.parse(logStr2));
cache.add(parser.parse(logStr3));
cache.add(parser.parse(logStr4));
cache.add(parser.parse(logStr5));
cache.add(parser.parse(logStr6));
cache.add(parser.parse(logStr7));
cache.add(parser.parse(logStr8));
cache.add(parser.parse(logStr9));
assertEquals("Wrong cache size", 9, cache.getSize());
// An array of boolean: the items marked as true should appear in the Collection
boolean[] b = { true, false, false, true, false, true, true, true, false };
// Get the logs exceeding a time frame of 30 secs
Collection<Integer> logs = cache.getLogExceedingTimeFrame(30 * 1000);
assertEquals("Wrong number of logs exceeding time frame", 5, logs.size());
// Check if the logs returned by getLogExceedingTimeFrame are ok
boolean[] returned = new boolean[9];
for (int t = 0; t < returned.length; t++) {
// Init all as false
returned[t] = false;
}
// Mark as true the logs in the Collection
for (Integer logN : logs) {
ILogEntry log = cache.getLog(logN);
String msg = (String) log.getField(LogField.LOGMESSAGE);
msg = msg.replaceFirst("Test", "");
Integer pos = Integer.parseInt(msg);
returned[pos - 1] = true;
}
// Compare the expected array (b) with the returned values (returned)
for (int t = 0; t < b.length; t++) {
assertEquals("The log " + t + " is/isn't in the Collection of logs", b[t], returned[t]);
}
}
use of alma.acs.logging.engine.parser.ACSLogParser in project ACS by ACS-Community.
the class ConvertersTest method setUp.
/**
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
ParserTypes type = ParserTypes.VTD;
ACSLogParser parser = ACSLogParserFactory.getParser(type);
logToConvert = parser.parse(xmlLog);
}
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;
}
Aggregations