Search in sources :

Example 76 with ILogEntry

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

the class DeleteLogTest method testContent.

/**
	 * Check the content of the cache (LogCache)
	 * 
	 * @throws Exception
	 */
public void testContent() throws Exception {
    LogCache cache = new LogCache();
    Vector<ILogEntry> c = (Vector<ILogEntry>) CacheUtils.generateLogs(4096);
    for (ILogEntry temp : c) {
        cache.add(temp);
    }
    assertEquals("Lengths differ", cache.getSize(), c.size());
    for (int t = 0; t < c.size(); t++) {
        ILogEntry logCache = cache.getLog(t);
        ILogEntry logVector = c.get(t);
        assertEquals("Log msgs differ", logCache.getField(LogField.LOGMESSAGE), logVector.getField(LogField.LOGMESSAGE));
        assertEquals("Log type differ", logCache.getField(LogField.ENTRYTYPE), logVector.getField(LogField.ENTRYTYPE));
        assertEquals("Log time differ", logCache.getField(LogField.TIMESTAMP), logVector.getField(LogField.TIMESTAMP));
    }
}
Also used : LogCache(com.cosylab.logging.client.cache.LogCache) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) Vector(java.util.Vector)

Example 77 with ILogEntry

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

the class DeleteLogTest method testGetLastLogLogBufferedFileCache.

/**
	 * Test the getLastLog after deletion of logs for LogBufferedFileCache
	 * 
	 * @throws Exception
	 */
public void testGetLastLogLogBufferedFileCache() throws Exception {
    // First test the LogFileCache
    Vector<ILogEntry> c = (Vector<ILogEntry>) CacheUtils.generateLogs(4096);
    LogBufferedFileCache cache = new LogBufferedFileCache(2049);
    assertNull("Error getting the first log from an empty cache", cache.getFirstLog());
    for (ILogEntry temp : c) {
        cache.add(temp);
    }
    assertEquals("Wrong number of logs in cache", cache.getSize(), c.size());
    // We have half logs in the buffer
    assertEquals("Wrong number of logs in buffer", cache.getBufferSize(), 2047);
    for (int t = 4095; t < 1000; t++) {
        cache.deleteLog(t);
        assertEquals("Error getting the first log", cache.getLastLog(), new Integer(t - 1));
    }
}
Also used : LogBufferedFileCache(com.cosylab.logging.client.cache.LogBufferedFileCache) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) Vector(java.util.Vector)

Example 78 with ILogEntry

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

the class DeleteLogTest method testLogFileCacheDelete.

/**
	 * 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 testLogFileCacheDelete() throws Exception {
    // Create and populate the cache
    Collection<ILogEntry> c = CacheUtils.generateLogs(512);
    LogFileCache cache;
    cache = new LogFileCache();
    for (ILogEntry temp : c) {
        cache.add(temp);
    }
    assertEquals("Wrong number of log in cache", cache.getSize(), c.size());
    // Delete the first log
    cache.deleteLog(0);
    // Check if the right log has been deleted
    ILogEntry log = null;
    boolean deletedLog = false;
    try {
        log = cache.getLog(0);
    } catch (LogCacheException e) {
        deletedLog = true;
    }
    assertTrue("The deleted log is still in cache", deletedLog);
    assertEquals("The size of the cache is wrong", cache.getSize(), 511);
    // Delete the last log
    cache.deleteLog(511);
    // Check if the last log is ok
    assertEquals("The size of the cache is wrong", cache.getSize(), 510);
    log = cache.getLog(510);
    int logNumber = Integer.parseInt((String) log.getField(LogField.LOGMESSAGE));
    assertEquals("The log in last position is wrong", logNumber, 510);
    // Delete a log in pos 100 
    cache.deleteLog(100);
    assertEquals("The size of the cache is wrong", cache.getSize(), 509);
    // The record before the deleted record
    ILogEntry log1 = cache.getLog(99);
    logNumber = Integer.parseInt((String) log1.getField(LogField.LOGMESSAGE));
    assertEquals("The log in position 99 is wrong", logNumber, 99);
    // The record after the deleted one
    ILogEntry log2 = cache.getLog(101);
    logNumber = Integer.parseInt((String) log2.getField(LogField.LOGMESSAGE));
    assertEquals("The log in position 101 is wrong", logNumber, 101);
    // Try to delete a log not in the cache
    boolean gotAnException = false;
    try {
        cache.deleteLog(1500);
    } catch (LogCacheException e) {
        gotAnException = true;
    }
    assertTrue("Error deleting a log not in cache", gotAnException);
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogCacheException(com.cosylab.logging.client.cache.LogCacheException) LogFileCache(com.cosylab.logging.client.cache.LogFileCache)

Example 79 with ILogEntry

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

the class DeleteLogTest method testGetFirstLogLogBufferedFileCache.

/**
	 * Test the getFirstLog after deletion of logs for LogBufferedFileCache
	 * 
	 * @throws Exception
	 */
public void testGetFirstLogLogBufferedFileCache() throws Exception {
    // First test the LogFileCache
    Vector<ILogEntry> c = (Vector<ILogEntry>) CacheUtils.generateLogs(4096);
    LogBufferedFileCache cache = new LogBufferedFileCache(2049);
    assertNull("Error getting the first log from an empty cache", cache.getFirstLog());
    for (ILogEntry temp : c) {
        cache.add(temp);
    }
    assertEquals("Wrong number of logs in cache", cache.getSize(), c.size());
    // We have half logs in the buffer
    assertEquals("Wrong number of logs in buffer", cache.getBufferSize(), 2047);
    for (int t = 0; t < 3000; t++) {
        cache.deleteLog(t);
        assertEquals("Error getting the first log", cache.getFirstLog(), new Integer(t + 1));
    }
}
Also used : LogBufferedFileCache(com.cosylab.logging.client.cache.LogBufferedFileCache) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) Vector(java.util.Vector)

Example 80 with ILogEntry

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

the class DeleteLogTest method testDeleteAllFromLogFileCache.

/**
	 * Generate a cache and randomly delete all its logs
	 * For each deleted log, the content of the cache is
	 * checked against the content of the collection to verify 
	 * the consistency its content 
	 * 
	 * @throws Exception
	 */
public void testDeleteAllFromLogFileCache() throws Exception {
    //	Create and populate the cache
    Vector<ILogEntry> v = (Vector<ILogEntry>) CacheUtils.generateLogs(512);
    HashMap<Integer, ILogEntry> logs = new HashMap<Integer, ILogEntry>();
    LogFileCache cache;
    cache = new LogFileCache();
    for (ILogEntry temp : v) {
        int key = cache.add(temp);
        logs.put(key, temp);
    }
    assertEquals("Wrong number of log in cache", cache.getSize(), logs.size());
    Random rnd = new Random(Calendar.getInstance().getTimeInMillis());
    while (logs.size() > 0) {
        int index = rnd.nextInt(logs.size());
        Set<Integer> s = logs.keySet();
        Object[] keys = s.toArray();
        Integer key = (Integer) keys[index];
        cache.deleteLog(key);
        logs.remove(key);
        assertEquals("The size of the cache and the collection differs", logs.size(), cache.getSize());
        s = logs.keySet();
        Iterator<Integer> iter = s.iterator();
        while (iter.hasNext()) {
            key = iter.next();
            assertEquals("Content of LogFileCache and collection differs", cache.getLog(key).getField(LogField.LOGMESSAGE), logs.get(key).getField(LogField.LOGMESSAGE));
        }
    }
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) HashMap(java.util.HashMap) Random(java.util.Random) Vector(java.util.Vector) LogFileCache(com.cosylab.logging.client.cache.LogFileCache)

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