Search in sources :

Example 6 with ILogEntry

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

the class DeleteLogTest method testDeleteAllFromLogBufferedFileCache.

/**
	 * 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
	 * 
	 * The tests check 2 cases:
	 *    1 all the logs in the buffer
	 *    2 some log on disk and the others in the buffer
	 * 
	 * @throws Exception
	 */
public void testDeleteAllFromLogBufferedFileCache() throws Exception {
    //   - testN=1: the logs are part in the buffer and part on disk
    for (int testN = 0; testN < 2; testN++) {
        Vector<ILogEntry> v = (Vector<ILogEntry>) CacheUtils.generateLogs(512);
        HashMap<Integer, ILogEntry> logs = new HashMap<Integer, ILogEntry>();
        LogBufferedFileCache cache;
        try {
            if (testN == 0) {
                cache = new LogBufferedFileCache(v.size() + 1);
            } else {
                cache = new LogBufferedFileCache(v.size() / 2 + 1);
            }
        } catch (LogCacheException lce) {
            System.out.println("Error creating the LogBufferedFileCache");
            throw lce;
        }
        for (ILogEntry temp : v) {
            Integer key = cache.add(temp);
            logs.put(key, temp);
        }
        assertTrue("Wrong number of log in cache", cache.getSize() == v.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 : LogBufferedFileCache(com.cosylab.logging.client.cache.LogBufferedFileCache) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) HashMap(java.util.HashMap) LogCacheException(com.cosylab.logging.client.cache.LogCacheException) Random(java.util.Random) Vector(java.util.Vector)

Example 7 with ILogEntry

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

the class DeleteLogTest method testDeleteAllFromLogCache.

/**
	 * 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. Such test is done comparing the content 
	 * of the maessage of the log with the content of the collection
	 * The test check also the consistency of the arrays of times and types
	 * (logTimes and logTypes in LogCache)
	 * At each iteration we try to fill the in-memory cache because 
	 * we must stress this part.
	 * 
	 * @throws Exception
	 */
public void testDeleteAllFromLogCache() throws Exception {
    //	Create and populate the cache
    Vector<ILogEntry> v = (Vector<ILogEntry>) CacheUtils.generateLogs(512);
    HashMap<Integer, ILogEntry> logs = new HashMap<Integer, ILogEntry>();
    LogCache cache;
    try {
        cache = new LogCache(128);
    } catch (LogCacheException lce) {
        System.out.println("Error creating the LogFileCache");
        throw lce;
    }
    for (ILogEntry temp : v) {
        Integer 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) {
        // Fill the in-memory cache executing some getLog()
        int filled = 0;
        int index = rnd.nextInt(logs.size());
        Set<Integer> s = logs.keySet();
        Object[] keys = s.toArray();
        int temp = 0;
        while (temp < logs.size() && filled < 128) {
            Integer key = (Integer) keys[temp++];
            filled++;
            cache.getLog(key);
        }
        index = rnd.nextInt(logs.size());
        s = logs.keySet();
        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();
            // Compare the content of the Collection and that of the cache
            assertEquals("Content of LogCache and collection differs", cache.getLog(key).getField(LogField.LOGMESSAGE), logs.get(key).getField(LogField.LOGMESSAGE));
            assertEquals("The types differ", cache.getLog(key).getField(LogField.ENTRYTYPE), cache.getLogType(key));
            assertEquals("The times differ", ((Long) cache.getLog(key).getField(LogField.TIMESTAMP)), cache.getLogTimestamp(key));
        }
    }
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) HashMap(java.util.HashMap) LogCacheException(com.cosylab.logging.client.cache.LogCacheException) LogCache(com.cosylab.logging.client.cache.LogCache) Random(java.util.Random) Vector(java.util.Vector)

Example 8 with ILogEntry

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

the class DeleteLogTest method testGetLastLogLogFileCache.

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

Example 9 with ILogEntry

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

the class DeleteLogTest method testDeleteLogsFromLogFileCache.

/**
	 * Test the deletion of a collection of logs from
	 * LogFileCache
	 * 
	 * @throws Exception
	 */
public void testDeleteLogsFromLogFileCache() throws Exception {
    // Fills the cache
    LogFileCache cache = new LogFileCache();
    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(4094, 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 LogFileCache();
    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 : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogCacheException(com.cosylab.logging.client.cache.LogCacheException) Vector(java.util.Vector) LogFileCache(com.cosylab.logging.client.cache.LogFileCache)

Example 10 with ILogEntry

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

the class DeleteLogTest method testDeleteLogsFromLogCache.

/**
	 * Test the deletion of a collection of logs from
	 * LogCache
	 * 
	 * @throws Exception
	 */
public void testDeleteLogsFromLogCache() throws Exception {
    // Fills the cache
    LogCache cache = new LogCache();
    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 LogCache();
    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 : LogCache(com.cosylab.logging.client.cache.LogCache) 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