Search in sources :

Example 11 with ILogEntry

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

the class MultiFileCacheTest method testClear.

/**
	 * Test the clearing of the cache
	 */
public void testClear() throws Exception {
    System.out.println("testClear started");
    // 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());
    cache.clear();
    assertEquals(0, cache.getSize());
    assertEquals(0, cache.getNumberOfCacheFiles());
    assertNull(cache.getFirstLog());
    assertNull(cache.getLastLog());
    System.out.println("testClear done");
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry)

Example 12 with ILogEntry

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

the class AntennaSourceReductionTest method testIsReducible.

/**
	 * Check {@link AntennaRule#isReducible()}
	 * @throws Exception
	 */
public void testIsReducible() throws Exception {
    String msg = "In position";
    // Reducible
    ILogEntry log1 = createLog(msg, "CONTROL/DA41/WVR");
    SourceAntennaRule sar = new SourceAntennaRule(log1);
    if (!sar.isReducible()) {
        System.out.println("Error: log1 should be reducible!!!");
    }
    // NOT reducible!
    ILogEntry log2 = createLog(msg, "maci");
    sar = new SourceAntennaRule(log2);
    if (sar.isReducible()) {
        System.out.println("Error: log2 should not be reducible!!!");
    }
    // NOT reducible!
    ILogEntry log3 = createLog(msg, "");
    sar = new SourceAntennaRule(log3);
    if (sar.isReducible()) {
        System.out.println("Error: log3 should not be reducible!!!");
    }
    // Reducible!
    ILogEntry log4 = createLog(msg, "PM02");
    sar = new SourceAntennaRule(log4);
    if (!sar.isReducible()) {
        System.out.println("Error: log4 should be reducible!!!");
    }
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) SourceAntennaRule(alma.acs.logging.table.reduction.SourceAntennaRule)

Example 13 with ILogEntry

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

the class DeleteLogTest method testLogCacheDelete.

/**
	 * Test the deletion of logs in the LogFileCache
	 * The test delete the first log, the last log and one log in the
	 * middel of the cache. After each deletion a bounce of checks assure
	 * the integrity of the cache
	 * 
	 * LogFileCache has no cache/buffering inmemory se we can
	 * test with few logs
	 *
	 */
public void testLogCacheDelete() throws Exception {
    // Create and populate the cache
    Collection<ILogEntry> c = CacheUtils.generateLogs(512);
    LogCache cache;
    try {
        cache = new LogCache(128);
    } catch (LogCacheException lce) {
        System.out.println("Error creating the LogFileCache");
        throw lce;
    }
    for (ILogEntry temp : c) {
        cache.add(temp);
    }
    assertTrue("Wrong number of log in cache", cache.getSize() == c.size());
    // move logs into the in-memory cache
    for (int t = 0; t < 128; t++) {
        cache.getLog(t);
    }
    // Delete the log in pos 0 (it is also in the in-memory cache)
    cache.deleteLog(0);
    // Check if the right log has been deleted
    ILogEntry log;
    boolean logDeleted = false;
    try {
        log = cache.getLog(0);
    } catch (LogCacheException e) {
        logDeleted = true;
    }
    assertTrue("The log has not been deleted", logDeleted);
    assertEquals("The size of the cache is wrong", cache.getSize(), 511);
    // Fill again the cache
    for (int t = 1; t < 129; t++) {
        cache.getLog(t);
    }
    // Delete the last log in cache (it is not in the in-memory cache)
    cache.deleteLog(510);
    assertEquals("The size of the cache is wrong", cache.getSize(), 510);
    log = cache.getLog(509);
    int logNum = Integer.parseInt((String) log.getField(LogField.LOGMESSAGE));
    assertEquals("The log in last position is wrong", logNum, 509);
    // Get one log from the middle (it is till in the in-memory cache)
    // The content in pos 100 is 101 because 0 was deleted
    cache.deleteLog(100);
    assertEquals("Wrong number of log in cache", cache.getSize(), 509);
    ILogEntry log1 = cache.getLog(99);
    logNum = Integer.parseInt((String) (log1.getField(LogField.LOGMESSAGE)));
    assertEquals("Wrong content", logNum, 99);
    ILogEntry log3 = cache.getLog(101);
    logNum = Integer.parseInt((String) (log3.getField(LogField.LOGMESSAGE)));
    assertEquals("Wrong content", logNum, 101);
    logDeleted = false;
    try {
        log = cache.getLog(100);
    } catch (LogCacheException e) {
        logDeleted = true;
    }
    assertTrue("The log has not been deleted", logDeleted);
}
Also used : LogCache(com.cosylab.logging.client.cache.LogCache) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogCacheException(com.cosylab.logging.client.cache.LogCacheException)

Example 14 with ILogEntry

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

the class LogIteratorTest method testRemove.

/**
	 * Test the remove method deleting all the logs in cache
	 * 
	 * @throws Exception
	 */
public void testRemove() throws Exception {
    for (int type = 0; type < CacheUtils.NUMOFCACHETYPES; type++) {
        ILogMap cache = CacheUtils.getCache(type, null);
        assertNotNull("The cache (type " + type + ") is null", cache);
        // The cache is empty!
        Iterator<ILogEntry> emptyIter = cache.iterator();
        assertFalse("The cache (type )" + type + ") is empty but the iterator thinks it is not", emptyIter.hasNext());
        // Release the iterator
        emptyIter = null;
        // Populate the cache with some logs
        int logsInCache = 1024;
        CacheUtils.populateCache(cache, logsInCache);
        assertEquals("Wrong num. of logs in cache (cache type (cache type " + type + ")" + type + ")", logsInCache, cache.getSize());
        Iterator<ILogEntry> iter = cache.iterator();
        // Try to remove a log before calling next: it causes an exception
        boolean gotAnException = false;
        try {
            iter.remove();
        } catch (IllegalStateException e) {
            // This is ok
            gotAnException = true;
        }
        assertTrue("The remove did not throw the (excpected) exception", gotAnException);
        // Iterate over the logs
        while (iter.hasNext()) {
            iter.next();
            iter.remove();
            assertEquals("The logs has not been removed", cache.getSize(), --logsInCache);
        }
    }
}
Also used : ILogMap(com.cosylab.logging.client.cache.ILogMap) ILogEntry(com.cosylab.logging.engine.log.ILogEntry)

Example 15 with ILogEntry

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

the class MultiFileCacheTest method testGet.

/**
	 * Test the getting of logs out of the cache
	 * 
	 * @throws Exception
	 */
public void testGet() throws Exception {
    System.out.println("testGet started");
    // 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++) {
        ILogEntry log = cache.getLog(t);
        // To be sure the log is what we expect, it checks if the log message
        // contains the key
        String message = (String) log.getField(LogField.LOGMESSAGE);
        assertNotNull(message);
        assertTrue(message.contains(t.toString()));
    }
    System.out.println("testGet done");
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry)

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