Search in sources :

Example 21 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry 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);
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) ACSLogRetrieval(com.cosylab.logging.engine.ACS.ACSLogRetrieval) ACSListenersDispatcher(com.cosylab.logging.engine.ACS.ACSListenersDispatcher)

Example 22 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.

the class LoadSaveTest method setUp.

/**
	 * @see junit.framework.TestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    bytesRead = 0;
    bytesWritten = 0;
    numOfLogsRead = 0;
    logs = CacheUtils.generateLogs(NUMBER_OF_LOGS);
    assertEquals(NUMBER_OF_LOGS, logs.size());
    // Read the folder name and generate the file name
    Properties props = System.getProperties();
    assertNotNull(props);
    folder = props.getProperty(USER_DIR);
    assertNotNull(folder);
    File folderFile = new File(folder);
    String folderPath = folderFile.getAbsolutePath();
    fileName = folderPath + "/logs.xml";
    gzipFileName = fileName + ".gz";
    // Check if folder is  a writable directory
    assertTrue(folderFile.isDirectory());
    assertTrue(folderFile.canWrite());
    logsRead = new Vector<ILogEntry>();
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) Properties(java.util.Properties) File(java.io.File)

Example 23 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.

the class LoadSaveTest method testSaveLoadCompressed.

/**
	 * Load and save a collection of logs in uncompressed files
	 * <P>
	 * The save is performed by passing the name of the file
	 *  
	 * @throws Exception
	 */
public void testSaveLoadCompressed() throws Exception {
    IOHelper ioHelper = new IOHelper();
    assertNotNull(ioHelper);
    // Save the logs on file
    ioHelper.saveLogs(gzipFileName, logs, this, false, true);
    assertEquals(logs.size(), numOfLogsWritten);
    // Read the logs
    ioHelper.loadLogs(gzipFileName, this, null, this, this, true);
    assertEquals(logs.size(), numOfLogsRead);
    // Compare the 2 collections
    assertEquals(logs.size(), logsRead.size());
    // Compare the 2 collections
    int t = 0;
    for (ILogEntry log : logs) {
        String logXML = log.toXMLString();
        String logReadXML = logsRead.get(t++).toXMLString();
        assertEquals(logXML, logReadXML);
    }
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) IOHelper(alma.acs.logging.engine.io.IOHelper)

Example 24 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.

the class LoadSaveTest method testSaveLoadIterator.

/**
	 * Check the load and save of logs by passing an <code>Iterator</code>
	 * 
	 * @throws Exception
	 */
public void testSaveLoadIterator() throws Exception {
    IOHelper ioHelper = new IOHelper();
    assertNotNull(ioHelper);
    Iterator<ILogEntry> iterator = logs.iterator();
    long assumedLen = 0;
    for (ILogEntry log : logs) {
        char[] chars = (log.toXMLString() + "\n").toCharArray();
        assumedLen += chars.length;
    }
    // Save the logs on file
    ioHelper.saveLogs(fileName, iterator, this, false, false);
    assertEquals(assumedLen, bytesWritten);
    assertEquals(logs.size(), numOfLogsWritten);
    // Read the logs
    ioHelper.loadLogs(fileName, this, null, this, this, false);
    assertEquals(logs.size(), numOfLogsRead);
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) IOHelper(alma.acs.logging.engine.io.IOHelper)

Example 25 with ILogEntry

use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.

the class LoadSaveTest method testSaveLoad.

/**
	 * Load and save a collection of logs in uncompressed files
	 * <P>
	 * The save is performed by passing the name of the file
	 *  
	 * @throws Exception
	 */
public void testSaveLoad() throws Exception {
    IOHelper ioHelper = new IOHelper();
    assertNotNull(ioHelper);
    long assumedLen = 0;
    for (ILogEntry log : logs) {
        char[] chars = (log.toXMLString() + "\n").toCharArray();
        assumedLen += chars.length;
    }
    // Save the logs on file
    ioHelper.saveLogs(fileName, logs, this, false, false);
    assertEquals(assumedLen, bytesWritten);
    assertEquals(logs.size(), numOfLogsWritten);
    // Read the logs
    ioHelper.loadLogs(fileName, this, null, this, this, false);
    assertEquals(logs.size(), numOfLogsRead);
    // bytes read includes the XML header
    assertTrue(bytesRead > assumedLen);
    // Compare the 2 collections
    assertEquals(logs.size(), logsRead.size());
    int t = 0;
    for (ILogEntry log : logs) {
        String logXML = log.toXMLString();
        String logReadXML = logsRead.get(t++).toXMLString();
        assertEquals(logXML, logReadXML);
    }
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) IOHelper(alma.acs.logging.engine.io.IOHelper)

Aggregations

ILogEntry (com.cosylab.logging.engine.log.ILogEntry)85 Vector (java.util.Vector)15 ACSLogParser (alma.acs.logging.engine.parser.ACSLogParser)11 Date (java.util.Date)11 IsoDateFormat (alma.acs.util.IsoDateFormat)9 LogCacheException (com.cosylab.logging.client.cache.LogCacheException)9 AdditionalData (com.cosylab.logging.engine.log.ILogEntry.AdditionalData)9 SimpleDateFormat (java.text.SimpleDateFormat)9 FieldPosition (java.text.FieldPosition)8 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)7 LogEntry (com.cosylab.logging.engine.log.LogEntry)6 ParserTypes (alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes)5 LogBufferedFileCache (com.cosylab.logging.client.cache.LogBufferedFileCache)5 LogFileCache (com.cosylab.logging.client.cache.LogFileCache)5 Random (java.util.Random)5 IOHelper (alma.acs.logging.engine.io.IOHelper)4 LogCache (com.cosylab.logging.client.cache.LogCache)4 IOException (java.io.IOException)4 ILogMap (com.cosylab.logging.client.cache.ILogMap)3 LogField (com.cosylab.logging.engine.log.LogField)3