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