Search in sources :

Example 71 with ILogEntry

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

the class MultiFileCacheTest method testGetFirstLog.

/**
	 * Test getFirstLog()
	 */
public void testGetFirstLog() throws Exception {
    System.out.println("testGetFirstLog 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());
    int start = cache.getFirstLog();
    int end = cache.getLastLog();
    for (int t = start; t <= end; t++) {
        cache.deleteLog(t);
        if (t < end) {
            assertEquals(Integer.valueOf(t + 1), cache.getFirstLog());
        } else {
            assertNull(cache.getFirstLog());
        }
    }
    System.out.println("testGetFirstLog done");
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry)

Example 72 with ILogEntry

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

the class MultiFileCacheTest method testGetLastLog.

/**
	 * Test getLastLog()
	 */
public void testGetLastLog() throws Exception {
    System.out.println("testGetLastLog 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());
    int start = cache.getFirstLog();
    int end = cache.getLastLog();
    for (int t = end; t >= start; t--) {
        System.out.println("Deleting " + t + ", size=" + cache.getSize());
        cache.deleteLog(t);
        if (t > start) {
            assertEquals(Integer.valueOf(t - 1), cache.getLastLog());
        } else {
            cache.printFileTableInfo();
            assertNull(cache.getLastLog());
        }
    }
    System.out.println("testGetLastLog done");
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry)

Example 73 with ILogEntry

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

the class MultiFileCacheTest method testFileCreation.

public void testFileCreation() throws Exception {
    // Create and populate the cache
    Collection<ILogEntry> logCollection = CacheUtils.generateLogsType(100, LogTypeHelper.TRACE);
    assertEquals(100, logCollection.size());
    long fileSize = 0;
    Iterator<ILogEntry> ii = logCollection.iterator();
    System.out.println("Start testFileCreation1");
    cache.setDebugTrace(true);
    // The cache is empty ... no logs have been added, therefore
    // the deletion of a log should fail.
    System.out.println("\nACTION : Delete log from empty cache");
    try {
        cache.deleteLog(12);
    } catch (Exception e) {
        System.out.println("Delete Log FAILS : cache is empty");
    }
    // Add logs until a new file is generated
    System.out.println("\nACTION : fill half of the cache with logs");
    while (fileSize < TESTCACHE_SIZE / 2) {
        fileSize = cache.getLogFileSize();
        ILogEntry log = ii.next();
        cache.add(log);
    }
    cache.printFileTableInfo();
    System.out.println("\nACTION : add single log");
    ILogEntry log = ii.next();
    cache.add(log);
    cache.printFileTableInfo();
    System.out.println("\nACTION : delete two logs");
    // Delete last log and check that the new file is not deleted
    cache.deleteLog(12);
    cache.deleteLog(2);
    cache.printFileTableInfo();
    System.out.println("\nACTION : fill cache and create a new log file");
    while (fileSize < TESTCACHE_SIZE) {
        fileSize = cache.getLogFileSize();
        log = ii.next();
        cache.add(log);
    }
    cache.printFileTableInfo();
    System.out.println("\nACTION : delete first log of the new file");
    cache.deleteLog(26);
    cache.printFileTableInfo();
    System.out.println("\nACTION : Add single log");
    log = ii.next();
    cache.add(log);
    cache.printFileTableInfo();
    // Delete log twice : the log key has already been deleted
    // therefore the delete should fail.
    System.out.println("\nACTION : Delete a log twice");
    try {
        cache.deleteLog(27);
    } catch (Exception e) {
        System.out.println("Delete Log FAILS : log has already been deleted");
    }
    cache.printFileTableInfo();
    System.out.println("\nACTION : fill cache and create a new log file");
    while ((fileSize = cache.getLogFileSize()) < TESTCACHE_SIZE) {
        log = ii.next();
        cache.add(log);
    }
    cache.printFileTableInfo();
    System.out.println("\nACTION : fill cache and create a new log file");
    log = ii.next();
    cache.add(log);
    while ((fileSize = cache.getLogFileSize()) < TESTCACHE_SIZE) {
        log = ii.next();
        cache.add(log);
    }
    cache.printFileTableInfo();
    System.out.println("\nACTION : add one more log ");
    log = ii.next();
    cache.add(log);
    cache.printFileTableInfo();
    System.out.println("\nACTION : Delete all log keys within a log file");
    cache.setDebugTrace(false);
    for (int logKey = 28; logKey < 52; logKey++) {
        cache.deleteLog(logKey);
    }
    cache.setDebugTrace(true);
    cache.printFileTableInfo();
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry)

Example 74 with ILogEntry

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

the class DeleteLogTest method testLogBufferedFileCacheDelete.

/**
	 * Test the deletion of logs in LogBufferedFileCache
	 * with all the logs in the buffer (i.e. the size of the buffer
	 * is so big to store all the allocated logs)
	 * 
	 * @throws Exception
	 */
public void testLogBufferedFileCacheDelete() throws Exception {
    //	Create and populate the cache
    Collection<ILogEntry> c = CacheUtils.generateLogs(512);
    LogBufferedFileCache cache;
    try {
        // Enough room for all the logs in the collection
        cache = new LogBufferedFileCache(c.size() + 1);
    } catch (LogCacheException lce) {
        System.out.println("Error creating the LogBufferedFileCache");
        throw lce;
    }
    for (ILogEntry temp : c) {
        cache.add(temp);
    }
    assertEquals("Wrong number of log in cache", cache.getSize(), c.size());
    assertEquals("Wrong number of logs in buffer ", cache.getBufferSize(), c.size());
    // Delete the first log (this is not in the buffer)
    cache.deleteLog(0);
    ILogEntry log = null;
    boolean deletedLog = false;
    try {
        log = cache.getLog(0);
    } catch (LogCacheException e) {
        deletedLog = true;
    }
    assertEquals("The LogBufferedFileCache has wrong size", cache.getSize(), 511);
    assertEquals("Wrong number of logs in buffer ", cache.getBufferSize(), 511);
    assertTrue("The log is still in cache", deletedLog);
    // Remove the last log in cache
    cache.deleteLog(511);
    assertEquals("Wrong number of log in cache", cache.getSize(), 510);
    assertEquals("Wrong number of logs in buffer ", cache.getBufferSize(), 510);
    log = cache.getLog(510);
    int logNum = Integer.parseInt((String) (log.getField(LogField.LOGMESSAGE)));
    assertEquals("Wrong content", logNum, 510);
    // Remove one log from the middle
    // The content in pos 100 (its content is 101 because 0 was deleted)
    cache.deleteLog(100);
    assertEquals("Wrong number of log in cache", cache.getSize(), 509);
    assertEquals("Wrong number of logs in buffer ", cache.getBufferSize(), 509);
    ILogEntry log1 = cache.getLog(99);
    logNum = Integer.parseInt((String) (log1.getField(LogField.LOGMESSAGE)));
    assertEquals("Wrong content", logNum, 99);
    ILogEntry log2 = cache.getLog(101);
    logNum = Integer.parseInt((String) (log2.getField(LogField.LOGMESSAGE)));
    assertEquals("Wrong content", logNum, 101);
}
Also used : LogBufferedFileCache(com.cosylab.logging.client.cache.LogBufferedFileCache) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogCacheException(com.cosylab.logging.client.cache.LogCacheException)

Example 75 with ILogEntry

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

the class DeleteLogTest method testDeleteLogsFromLogBufferedFileCache.

/**
	 * Test the deletion of a collection of logs from
	 * LogBufferedFileCache
	 * 
	 * @throws Exception
	 */
public void testDeleteLogsFromLogBufferedFileCache() throws Exception {
    // Fills the cache
    LogBufferedFileCache cache = new LogBufferedFileCache();
    assertNull("Error getting the first log from an empty cache", cache.getFirstLog());
    Vector<ILogEntry> c = (Vector<ILogEntry>) CacheUtils.generateLogs(4096);
    Vector<Integer> keysInCache = new Vector<Integer>(c.size());
    for (ILogEntry temp : c) {
        Integer key = cache.add(temp);
        keysInCache.add(key);
    }
    assertEquals("Wrong number of logs in cache", cache.getSize(), c.size());
    // Delete an empty collection of keys
    Vector<Integer> empty = new Vector<Integer>();
    cache.deleteLogs(empty);
    assertEquals("Wrong size after deleting an empty collection of keys", c.size(), cache.getSize());
    // Delete a collection with the first and last key
    Vector<Integer> firstLast = new Vector<Integer>(2);
    firstLast.add(0);
    firstLast.add(4095);
    cache.deleteLogs(firstLast);
    assertEquals("Wrong size after deletion", c.size() - 2, cache.getSize());
    // Check if 0 and 4095 in cache
    ILogEntry log0;
    try {
        log0 = cache.getLog(0);
    } catch (LogCacheException e) {
        log0 = null;
    }
    assertNull("The log with key 0 is still in cache", log0);
    ILogEntry log4095;
    try {
        log4095 = cache.getLog(4095);
    } catch (LogCacheException e) {
        log4095 = null;
    }
    assertNull("The log with key 4095 is still in cache", log4095);
    // Remove a random collection
    keysInCache.remove(new Integer(0));
    keysInCache.remove(new Integer(4095));
    Collection<Integer> keys = CacheUtils.generateKeys(4095, false, 1, 4094, keysInCache);
    int oldSz = cache.getSize();
    cache.deleteLogs(keys);
    assertEquals("Wrong size after deletion", oldSz - keys.size(), cache.getSize());
    // Check the content of the cache after deletion
    for (Integer key : keysInCache) {
        ILogEntry log;
        try {
            log = cache.getLog(key);
        } catch (LogCacheException e) {
            log = null;
        }
        if (keys.contains(key)) {
            // This log should have been deleted
            assertNull("The log should have been deleted", log);
        } else {
            assertNotNull("The log should have not been deleted", log);
        }
    }
    // Release the cache
    cache.clear();
    keysInCache.clear();
    keysInCache = null;
    c.clear();
    c = null;
    cache = null;
    // Create a new cache to test the deletion of the whole cache
    cache = new LogBufferedFileCache();
    c = (Vector<ILogEntry>) CacheUtils.generateLogs(1024);
    keysInCache = new Vector<Integer>(c.size());
    for (ILogEntry temp : c) {
        Integer key = cache.add(temp);
        keysInCache.add(key);
    }
    assertEquals("Wrong number of logs in cache", cache.getSize(), c.size());
    cache.deleteLogs(keysInCache);
    assertEquals("Not all the logs have been deleted", cache.getSize(), 0);
}
Also used : LogBufferedFileCache(com.cosylab.logging.client.cache.LogBufferedFileCache) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogCacheException(com.cosylab.logging.client.cache.LogCacheException) Vector(java.util.Vector)

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