Search in sources :

Example 1 with IOHelper

use of alma.acs.logging.engine.io.IOHelper 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);
            }
        }
    }
}
Also used : AdditionalData(com.cosylab.logging.engine.log.ILogEntry.AdditionalData) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) IOHelper(alma.acs.logging.engine.io.IOHelper) ACSLogParser(alma.acs.logging.engine.parser.ACSLogParser) Vector(java.util.Vector) LogField(com.cosylab.logging.engine.log.LogField)

Example 2 with IOHelper

use of alma.acs.logging.engine.io.IOHelper in project ACS by ACS-Community.

the class LoadSaveTest method testAppend.

/**
	 * Test the append switch while saving logs by saving the same
	 * collection twice in the same file but with the append switch set to
	 * <code>true</code>.
	 * @throws Exception
	 */
public void testAppend() throws Exception {
    IOHelper ioHelper = new IOHelper();
    assertNotNull(ioHelper);
    // First save with no append
    ioHelper.saveLogs(fileName, logs, this, false, false);
    // Second save with append
    ioHelper.saveLogs(fileName, logs, this, true, false);
    // Load the logs
    ioHelper.loadLogs(fileName, this, null, this, this, false);
    assertEquals(2 * logs.size(), logsRead.size());
    assertEquals(2 * logs.size(), numOfLogsRead);
}
Also used : IOHelper(alma.acs.logging.engine.io.IOHelper)

Example 3 with IOHelper

use of alma.acs.logging.engine.io.IOHelper 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 4 with IOHelper

use of alma.acs.logging.engine.io.IOHelper 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 5 with IOHelper

use of alma.acs.logging.engine.io.IOHelper 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

IOHelper (alma.acs.logging.engine.io.IOHelper)8 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)4 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 ACSLogParser (alma.acs.logging.engine.parser.ACSLogParser)1 AdditionalData (com.cosylab.logging.engine.log.ILogEntry.AdditionalData)1 LogField (com.cosylab.logging.engine.log.LogField)1 FileWriter (java.io.FileWriter)1 Vector (java.util.Vector)1