01: package org.shiftone.cache.policy.fifo;
02:
03: import org.shiftone.cache.CacheFactory;
04: import org.shiftone.cache.util.TestCaseBase;
05:
06: /**
07: * Class FifoCacheTestCase
08: *
09: *
10: * @author <a href="mailto:jeff@shiftone.org">Jeff Drost</a>
11: * @version $Revision: 1.2 $
12: */
13: public class FifoCacheTestCase extends TestCaseBase {
14:
15: public FifoCacheTestCase(String name) {
16: super (name);
17: }
18:
19: /**
20: * Method getCacheFactory
21: */
22: public CacheFactory getCacheFactory() {
23: return new FifoCacheFactory();
24: }
25:
26: /**
27: * Method testPut
28: */
29: public void testFifo() {
30:
31: FifoCache cache = new FifoCache("fifo", 5000, 10);
32:
33: cache.addObject("A", "A"); //1
34: cache.addObject("B", "B"); //2
35: cache.addObject("C", "C"); //3
36: cache.addObject("D", "D"); //4
37: cache.addObject("E", "E"); //5
38: cache.addObject("F", "F"); //6
39: cache.addObject("G", "G"); //7
40: cache.addObject("H", "H"); //8
41: cache.addObject("I", "I"); //9
42: cache.addObject("J", "J"); //10
43: assertEquals("JIHGFEDCBA", cache.dumpFifoKeys());
44:
45: // getObject should have no effect
46: assertNotNull(cache.getObject("A"));
47: assertEquals("JIHGFEDCBA", cache.dumpFifoKeys());
48: assertNotNull(cache.getObject("B"));
49: assertEquals("JIHGFEDCBA", cache.dumpFifoKeys());
50: assertNotNull(cache.getObject("C"));
51: assertEquals("JIHGFEDCBA", cache.dumpFifoKeys());
52: assertNotNull(cache.getObject("D"));
53: assertEquals("JIHGFEDCBA", cache.dumpFifoKeys());
54: assertNotNull(cache.getObject("E"));
55: assertEquals("JIHGFEDCBA", cache.dumpFifoKeys());
56:
57: // addObject should bump out elements
58: cache.addObject("K", "K"); //11
59: assertEquals("KJIHGFEDCB", cache.dumpFifoKeys());
60: cache.addObject("L", "L"); //12
61: assertEquals("LKJIHGFEDC", cache.dumpFifoKeys());
62: cache.addObject("M", "M"); //13
63: assertEquals("MLKJIHGFED", cache.dumpFifoKeys());
64: cache.addObject("N", "N"); //14
65: assertEquals("NMLKJIHGFE", cache.dumpFifoKeys());
66: cache.addObject("O", "O"); //15
67: assertEquals("ONMLKJIHGF", cache.dumpFifoKeys());
68: }
69: }
|