1 package org.apache.commons.jcs3.engine;
2
3 import org.apache.commons.jcs3.engine.behavior.ICacheElement;
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import junit.framework.TestCase;
25
26
27
28
29 public class ZombieCacheServiceNonLocalUnitTest
30 extends TestCase
31 {
32
33
34
35
36
37 public void testUpdateThenWalk()
38 throws Exception
39 {
40
41 final MockCacheServiceNonLocal<String, String> service = new MockCacheServiceNonLocal<>();
42
43 final ZombieCacheServiceNonLocal<String, String> zombie = new ZombieCacheServiceNonLocal<>( 10 );
44
45 final String cacheName = "testUpdate";
46
47
48 final ICacheElement<String, String> element = new CacheElement<>( cacheName, "key", "value" );
49 zombie.update( element, 123L );
50 zombie.propagateEvents( service );
51
52
53 assertEquals( "Updated element is not as expected.", element, service.lastUpdate );
54 }
55
56
57
58
59
60
61 public void testUpdateThenWalk_zeroSize()
62 throws Exception
63 {
64
65 final MockCacheServiceNonLocal<String, String> service = new MockCacheServiceNonLocal<>();
66
67 final ZombieCacheServiceNonLocal<String, String> zombie = new ZombieCacheServiceNonLocal<>( 0 );
68
69 final String cacheName = "testUpdate";
70
71
72 final ICacheElement<String, String> element = new CacheElement<>( cacheName, "key", "value" );
73 zombie.update( element, 123L );
74 zombie.propagateEvents( service );
75
76
77 assertNull( "Nothing should have been put to the service.", service.lastUpdate );
78 }
79
80
81
82
83
84
85 public void testRemoveThenWalk()
86 throws Exception
87 {
88
89 final MockCacheServiceNonLocal<String, String> service = new MockCacheServiceNonLocal<>();
90
91 final ZombieCacheServiceNonLocal<String, String> zombie = new ZombieCacheServiceNonLocal<>( 10 );
92
93 final String cacheName = "testRemoveThenWalk";
94 final String key = "myKey";
95
96
97 zombie.remove( cacheName, key, 123L );
98 zombie.propagateEvents( service );
99
100
101 assertEquals( "Updated element is not as expected.", key, service.lastRemoveKey );
102 }
103
104
105
106
107
108
109 public void testRemoveAllThenWalk()
110 throws Exception
111 {
112
113 final MockCacheServiceNonLocal<String, String> service = new MockCacheServiceNonLocal<>();
114
115 final ZombieCacheServiceNonLocal<String, String> zombie = new ZombieCacheServiceNonLocal<>( 10 );
116
117 final String cacheName = "testRemoveThenWalk";
118
119
120 zombie.removeAll( cacheName, 123L );
121 zombie.propagateEvents( service );
122
123
124 assertEquals( "Updated element is not as expected.", cacheName, service.lastRemoveAllCacheName );
125 }
126 }