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