home | career | drupal | java | mac | mysql | perl | scala | uml | unix

Groovy example source code file (LRUProtectionStorageTest.groovy)

This example Groovy source code file (LRUProtectionStorageTest.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

groovytestcase, groovytestcase, lruprotectionstorage, lruprotectionstorage, lruprotectionstoragetest, lruprotectionstoragetest

The Groovy LRUProtectionStorageTest.groovy source code

package org.codehaus.groovy.runtime.memoize

/**
 * @author Vaclav Pech
 */
public class LRUProtectionStorageTest extends GroovyTestCase {
    public void testLRUStrategyWithOneElement() {
        def storage = new LRUProtectionStorage(1)
        assert storage.size() == 0
        storage['key1'] = 1
        assert storage.size() == 1
        storage['key2'] = 2
        assert storage.size() == 1
        assertEquals 2, storage['key2']
        storage['key1'] = 1
        assert storage.size() == 1
        assertNull storage['key2']
        assertEquals 1, storage['key1']

    }

    public void testLRUStrategy() {
        def storage = new LRUProtectionStorage(3)
        assert storage.size() == 0
        storage['key1'] = 1
        assert storage.size() == 1
        storage['key2'] = 2
        storage['key3'] = 3
        assert storage.size() == 3
        assertEquals 1, storage['key1']
        assertEquals 2, storage['key2']
        assertEquals 3, storage['key3']
        storage['key4'] = 4
        assert storage.size() == 3
        assertNull storage['key1']
        assertEquals 2, storage['key2']
        assertEquals 3, storage['key3']
        assertEquals 4, storage['key4']
        storage['key4']
        storage['key2']
        storage['key5'] = 5
        assert storage.size() == 3
        assertNull storage['key3']
        assertEquals 2, storage['key2']
        assertEquals 4, storage['key4']
        assertEquals 5, storage['key5']
    }

    public void testTouch() {
        def storage = new LRUProtectionStorage(3)
        storage['key1'] = 1
        storage['key2'] = 2
        storage['key3'] = 3
        storage.touch('key1', 11)
        storage['key4'] = 4
        assert storage.size() == 3
        assertEquals 11, storage['key1']
        assertEquals 4, storage['key4']
        assertEquals 3, storage['key3']
        assertNull storage['key2']
    }
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy LRUProtectionStorageTest.groovy source code file:

new blog posts

 

Copyright 1998-2014 Alvin Alexander, alvinalexander.com
All Rights Reserved.