KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > cache > FIFOCacheTest


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.cache;
4
5 import junit.framework.TestCase;
6 import jodd.util.ThreadUtil;
7
8 public class FIFOCacheTest extends TestCase {
9
10     public void testCache() {
11         Cache cache = new FIFOCache(3);
12         cache.put("1", "1");
13         cache.put("2", "2");
14         assertFalse(cache.isFull());
15         cache.put("3", "3");
16         assertTrue(cache.isFull());
17
18         assertNotNull(cache.get("1"));
19         assertNotNull(cache.get("2"));
20         cache.put("4", "4"); // new element, cache is full, prune is invoked
21
assertNull(cache.get("1"));
22         assertNotNull(cache.get("2"));
23         assertNotNull(cache.get("3"));
24         assertNotNull(cache.get("4"));
25         cache.put("1", "1");
26
27         assertNull(cache.get("2"));
28         assertNotNull(cache.get("3"));
29         assertNotNull(cache.get("4"));
30         assertNotNull(cache.get("1"));
31     }
32
33     public void testCacheTime() {
34         Cache cache = new FIFOCache(3);
35         cache.put("1", "1");
36         cache.put("2", "2");
37         cache.put("3", "3", 50);
38
39         ThreadUtil.sleep(100);
40         cache.put("4", "4");
41
42         assertNotNull(cache.get("1"));
43         assertNotNull(cache.get("2"));
44         assertNull(cache.get("3"));
45         assertNotNull(cache.get("4"));
46
47     }
48
49 }
50
Popular Tags