use of com.cosylab.logging.engine.ACS.ACSLogRetrieval in project ACS by ACS-Community.
the class EngineAudienceTest method setUp.
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
numOfReceivedLogs = 0;
numOfReceivedXMLLogs = 0;
dispatcher = new ACSListenersDispatcher();
assertNotNull(dispatcher);
logRetieval = new ACSLogRetrieval(dispatcher);
assertNotNull(logRetieval);
logRetieval.setFilters(null);
logRetieval.start();
dispatcher.addLogListener(this);
dispatcher.addRawLogListener(this);
}
use of com.cosylab.logging.engine.ACS.ACSLogRetrieval in project ACS by ACS-Community.
the class LogDispatcherTest method testXMLDispatch.
/**
* Test the dispatching of XML logs
*
* @throws Exception
*/
public void testXMLDispatch() throws Exception {
// Add the name of the test in the additional data
for (ILogEntry log : logs) {
log.addData("TestType", "XML");
}
ACSListenersDispatcher listenerDispatcher = new ACSListenersDispatcher();
assertNotNull("Null listener dispatcher!", listenerDispatcher);
ACSLogRetrieval logDispatcher = new ACSLogRetrieval(listenerDispatcher);
assertNotNull("Null log dispatcher!", logDispatcher);
logDispatcher.start();
listenerDispatcher.addLogListener(logRecv);
listenerDispatcher.addRawLogListener(logRecv);
stopWatch.reset();
for (ILogEntry log : logs) {
logDispatcher.addLog(log.toXMLString());
}
waitProcessingComplete(logDispatcher, 300);
long xmlTime = stopWatch.getLapTimeMillis() / 1000;
//String str ="Time to publish "+LOGS_NUMBER+" XML logs: "+xmlTime + " seconds.\n";
//System.out.print(str);
assertEquals("XML case: logs sent and logs received differ", LOGS_NUMBER, logsReceived);
assertEquals("XML case: logs sent and raw logs received differ", LOGS_NUMBER, rawLogsReceived);
logDispatcher.close(true);
}
use of com.cosylab.logging.engine.ACS.ACSLogRetrieval in project ACS by ACS-Community.
the class LogDispatcherTest method testGetSetDiscardLevel.
/**
* Test setting and getting of the discard level.
*
* @throws Exception
*/
public void testGetSetDiscardLevel() throws Exception {
ACSListenersDispatcher listenerDispatcher = new ACSListenersDispatcher();
assertNotNull("Null listener dispatcher!", listenerDispatcher);
ACSLogRetrieval logDispatcher = new ACSLogRetrieval(listenerDispatcher);
assertNotNull("Null log dispatcher!", logDispatcher);
logDispatcher.start();
logDispatcher.setDiscardLevel(null);
assertNull(logDispatcher.getDiscardLevel());
for (LogTypeHelper logType : LogTypeHelper.values()) {
logDispatcher.setDiscardLevel(logType);
assertEquals(logType, logDispatcher.getDiscardLevel());
}
logDispatcher.close(true);
}
use of com.cosylab.logging.engine.ACS.ACSLogRetrieval in project ACS by ACS-Community.
the class LogDispatcherTest method testDynamicDiscardLevel.
/**
* Test the changing of the discard level by simulating
* a low memory situation
* @throws Exception
*/
public void testDynamicDiscardLevel() throws Exception {
Checker checker = new Checker();
assertNotNull(checker);
ACSListenersDispatcher listenerDispatcher = new ACSListenersDispatcher();
assertNotNull("Null listener dispatcher!", listenerDispatcher);
ACSLogRetrieval logDispatcher = new ACSLogRetrieval(listenerDispatcher, false, null, checker);
assertNotNull("Null log dispatcher!", logDispatcher);
logDispatcher.start();
// Check increasing of the discard level
logDispatcher.setDiscardLevel(null);
checker.freemMem = Long.MAX_VALUE;
// Changes of the discard level should happens every 2 seconds
logDispatcher.enableDynamicDiscarding(8192, 1024, 2);
// the discard level does not change
try {
Thread.sleep(5);
} catch (InterruptedException ie) {
}
assertNull(logDispatcher.getActualDiscardLevel());
assertNull(logDispatcher.getDiscardLevel());
// The index of the next log type
int type = 0;
// Time to wait for the next change before giving up
int timeout = 10;
// start dynamic changes of discard level
checker.freemMem = 4096;
while (logDispatcher.getActualDiscardLevel() != LogTypeHelper.values()[LogTypeHelper.values().length - 1]) {
long to = System.currentTimeMillis() + 1000 * timeout;
boolean found = false;
while (!found && System.currentTimeMillis() < to) {
found = logDispatcher.getActualDiscardLevel() == LogTypeHelper.values()[type];
Thread.yield();
}
assertTrue("timeout waiting for level " + LogTypeHelper.values()[type], found);
// Original discard level does not change
assertNull(logDispatcher.getDiscardLevel());
type++;
}
// Now the level is the topmost and it should not change...
try {
Thread.sleep(10000);
} catch (InterruptedException ie) {
}
assertEquals(LogTypeHelper.values()[LogTypeHelper.values().length - 1], logDispatcher.getActualDiscardLevel());
assertNull(logDispatcher.getDiscardLevel());
// Now check the decreasing
// First set the free memory to a value between the threshold and the damping
checker.freemMem = 8192 + 512;
// The level does not change
try {
Thread.sleep(10000);
} catch (InterruptedException ie) {
}
assertEquals(LogTypeHelper.values()[LogTypeHelper.values().length - 1], logDispatcher.getActualDiscardLevel());
assertNull(logDispatcher.getDiscardLevel());
// Increase the free memory ===> the level start decreasing
type = LogTypeHelper.values()[LogTypeHelper.values().length - 1].ordinal();
checker.freemMem = 2 * 8192;
while (logDispatcher.getActualDiscardLevel() != null) {
long to = System.currentTimeMillis() + 1000 * timeout;
boolean found = false;
while (!found && System.currentTimeMillis() < to) {
if (type >= 0) {
found = logDispatcher.getActualDiscardLevel() == LogTypeHelper.values()[type];
} else {
found = logDispatcher.getActualDiscardLevel() == null;
}
Thread.yield();
}
if (type >= 0) {
assertTrue("timeout waiting for level " + LogTypeHelper.values()[type], found);
}
// Original discard level does not change
assertNull(logDispatcher.getDiscardLevel());
type--;
}
assertNull(logDispatcher.getActualDiscardLevel());
logDispatcher.close(true);
}
Aggregations