Search in sources :

Example 1 with ILogMap

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

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

the class LogIteratorTest method testIteratorWithException.

/**
	 * Test if the next() method works well.
	 * In this case hasNext is not used (an Exception signals that
	 * all the logs have been read)
	 * 
	 * @throws Exception
	 */
public void testIteratorWithException() 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();
        // Read all the logs to check if the hasNext returns always
        // true but for the last log in cache
        int logsRead = 0;
        ILogEntry log;
        do {
            try {
                log = iter.next();
            } catch (NoSuchElementException e) {
                // Check if we have read all the logs
                assertEquals("The numer of logs read is not complete (cache type " + type + ")", logsInCache, logsRead);
                return;
            }
            logsRead++;
        } while (log != null);
    }
}
Also used : ILogMap(com.cosylab.logging.client.cache.ILogMap) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with ILogMap

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

the class LogIteratorTest method testIterator.

/**
	 * Test if the next() and hasNext() methods work well together
	 * 
	 * @throws Exception
	 */
public void testIterator() 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 " + type + ")", logsInCache, cache.getSize());
        Iterator<ILogEntry> iter = cache.iterator();
        // Read all the logs to check if the hasNext returns always
        // true but for the last log in cache
        int logsRead = 0;
        while (iter.hasNext()) {
            iter.next();
            logsRead++;
        }
        assertEquals("The numer of logs read is not complete", logsRead, logsInCache);
    }
}
Also used : ILogMap(com.cosylab.logging.client.cache.ILogMap) ILogEntry(com.cosylab.logging.engine.log.ILogEntry)

Aggregations

ILogMap (com.cosylab.logging.client.cache.ILogMap)3 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)3 NoSuchElementException (java.util.NoSuchElementException)1