use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.
the class MultiFileCacheTest method testFileDeletion.
/**
* Test deletion of logs
*
* @throws Exception
*/
public void testFileDeletion() throws Exception {
// Create and populate the cache
Collection<ILogEntry> logCollection = CacheUtils.generateLogs(1000);
assertEquals(1000, logCollection.size());
for (ILogEntry log : logCollection) {
cache.add(log);
}
assertTrue(cache.getNumberOfCacheFiles() > 0);
assertEquals(Integer.valueOf(0), cache.getFirstLog());
assertEquals(Integer.valueOf(999), cache.getLastLog());
cache.printFileTableInfo();
int start = cache.getFirstLog();
int end = cache.getLastLog();
for (int t = start; t <= end; t++) {
System.out.println(">>>>" + t);
cache.deleteLog(t);
}
System.out.println("First " + cache.getFirstLog() + ", Last " + cache.getLastLog());
cache.printFileTableInfo();
assertEquals(0, cache.getSize());
assertEquals(0, cache.getNumberOfCacheFiles());
}
use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.
the class MultiFileCacheTest method testGetSize.
/**
* Test the functioning of getSize()
* @throws Exception
*/
public void testGetSize() throws Exception {
// Create and populate the cache
Collection<ILogEntry> logCollection = CacheUtils.generateLogs(1000);
assertEquals(1000, logCollection.size());
for (ILogEntry log : logCollection) {
cache.add(log);
}
assertEquals(Integer.valueOf(0), cache.getFirstLog());
assertEquals(Integer.valueOf(999), cache.getLastLog());
assertEquals(logCollection.size(), cache.getSize());
// Remove the logs and check the size
int removed = 0;
int start = cache.getFirstLog();
int end = cache.getLastLog();
for (int t = start; t <= end; t++) {
cache.deleteLog(t);
assertEquals(logCollection.size() - (++removed), cache.getSize());
}
assertEquals(0, cache.getSize());
}
use of com.cosylab.logging.engine.log.ILogEntry 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 com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.
the class EngineFilteringTest method testFiltering.
/**
* Set a filter and checks if the logs received are those passing a filters.
* <P>
* In this case we do not need to check the correctness of the logs received
* in the listeners but only if they are received or not because it means that
* the engine is using the filters.
* <P>
* For this example, the test defines 1 filter based on the type of the logs.
* <P>
* The correctness of the filtering is also tested in another test because the engine
* uses the same filters used by the table.
*
* @throws Exception
*/
public void testFiltering() throws Exception {
// Randomly generate the logs
Collection<ILogEntry> logs = CacheUtils.generateLogs(NUMBER_OF_LOGS);
assertNotNull(logs);
assertEquals(NUMBER_OF_LOGS, logs.size());
Collection<ILogEntry> flushLogs = CacheUtils.generateLogsType(100, LogTypeHelper.NOTICE);
// Create a filter for the type INFO
Filter f = new ExactFilter(LogField.ENTRYTYPE, false, LogTypeHelper.INFO, false);
assertNotNull(f);
// And a filter for the source name
Filter nameFilter = new ExactFilter(LogField.ROUTINE, false, getName(), false);
assertNotNull(nameFilter);
// No filters exists in the engine
assertNull(engine.getFilters());
// Add the filters
engine.addFilter(f);
engine.addFilter(nameFilter);
assertNotNull(engine.getFilters());
assertEquals("Size differ", 2, engine.getFilters().size());
// connect the engine
engine.connect();
// wait until the engine is connected
int iterCount = 0;
while (iterCount < TIMEOUT && !engine.isConnected()) {
iterCount++;
try {
Thread.sleep(1000);
} catch (Exception e) {
}
}
assertTrue(engine.isConnected());
// publish all the logs and count the number of INFO logs
int infos = 0;
for (ILogEntry log : logs) {
AcsLogLevel level = AcsLogLevel.fromAcsCoreLevel(log.getType().acsCoreLevel);
m_logger.log(level, (String) log.getField(LogField.LOGMESSAGE));
if (log.getType() == LogTypeHelper.INFO) {
infos++;
}
}
// If it is possible then it is better this second option then sending logs..
try {
Thread.sleep(1000);
} catch (Exception e) {
}
System.out.println("Flushing");
for (ILogEntry log : flushLogs) {
AcsLogLevel level = AcsLogLevel.fromAcsCoreLevel(log.getType().acsCoreLevel);
m_logger.log(level, (String) log.getField(LogField.LOGMESSAGE));
}
// wait till all the logs are received
//
// It additionally waits for TIMEOUT seconds after the last log has been
// received to be sure there are no further logs delayed because of caching
// or similar problems
// The number of seconds after the last log has been received
int elapsed = 0;
// The number of logs at the previous iteration
int count = 0;
while (elapsed < TIMEOUT) {
synchronized (receivedLogs) {
if (receivedLogs.size() != count) {
count = receivedLogs.size();
elapsed = 0;
continue;
}
}
// No new logs received
try {
Thread.sleep(1000);
} catch (Exception e) {
}
elapsed++;
}
// If all the logs have been received then xmlLogsCount must be greater then NUMBER_OF_LOGS
// Not equal because the xml logs are not filtered and there can be logs generated
// outside of this object
assertTrue("Received only " + xmlLogsCount.get() + " xml logs, when there should have been at least " + NUMBER_OF_LOGS, xmlLogsCount.get() >= NUMBER_OF_LOGS);
// Check if the number of received logs is as expected
assertEquals(infos, receivedLogs.size());
}
use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.
the class EngineFilteringTest method setUp.
/**
* Setup the environment by creating the engine with a null set of filters.
* The engine is disconnected because some of the tests do not need the
* connection alive.
*
* @see alma.acs.component.client.ComponentClientTestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
receivedLogs = new Vector<ILogEntry>();
assertNotNull(receivedLogs);
receivedLogs.clear();
xmlLogsCount = new AtomicInteger(0);
xmlInfos = 0;
assertNotNull(m_logger);
AcsLogger acsLogger = m_logger;
LogConfig config = new LogConfig();
acsLogger.configureLogging(config);
engine = new LCEngine();
assertNotNull(engine);
engine.addLogErrorListener(this);
engine.addLogConnectionListener(this);
engine.addLogListener(this);
engine.addRawLogListener(this);
}
Aggregations