|
Groovy example source code file (LRUProtectionStorageTest.groovy)
The Groovy LRUProtectionStorageTest.groovy source codepackage 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: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.