Search in sources :

Example 6 with LogCacheException

use of com.cosylab.logging.client.cache.LogCacheException in project ACS by ACS-Community.

the class LogEntryTableModelBase method getVisibleLogEntry.

/**
	 * Return the log shown in the passed row.
	 * <P>
	 * This must be called inside the EDT.
	 * 
	 * @param row The row of the table containing the log
	 * @return The log in the passed row
	 */
public ILogEntry getVisibleLogEntry(int row) {
    if (closed) {
        return null;
    }
    try {
        ILogEntry ret;
        ret = allLogs.getLog(rows.get(row));
        return ret;
    } catch (LogCacheException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogCacheException(com.cosylab.logging.client.cache.LogCacheException)

Example 7 with LogCacheException

use of com.cosylab.logging.client.cache.LogCacheException 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 8 with LogCacheException

use of com.cosylab.logging.client.cache.LogCacheException 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)

Example 9 with LogCacheException

use of com.cosylab.logging.client.cache.LogCacheException 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)

Aggregations

LogCacheException (com.cosylab.logging.client.cache.LogCacheException)9 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)9 Vector (java.util.Vector)5 LogBufferedFileCache (com.cosylab.logging.client.cache.LogBufferedFileCache)3 LogCache (com.cosylab.logging.client.cache.LogCache)3 LogFileCache (com.cosylab.logging.client.cache.LogFileCache)2 HashMap (java.util.HashMap)2 Random (java.util.Random)2