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.auxiliary.remote.behavior.IRemoteCacheAttributes;
25 import org.apache.jcs.engine.CacheElement;
26 import org.apache.jcs.engine.behavior.ICacheElement;
27 import org.apache.jcs.engine.behavior.ICacheElementSerialized;
28 import org.apache.jcs.utils.serialization.SerializationConversionUtil;
29
30 /***
31 * Unit Tests for the Remote Cache.
32 * <p>
33 * @author admin
34 */
35 public class RemoteCacheUnitTest
36 extends TestCase
37 {
38 /***
39 * Verify that the remote service update method is called. The remote cache serializes the obect
40 * first.
41 * <p>
42 * @throws Exception
43 */
44 public void testUpdate()
45 throws Exception
46 {
47
48 IRemoteCacheAttributes cattr = new RemoteCacheAttributes();
49 RemoteCacheServiceMockImpl service = new RemoteCacheServiceMockImpl();
50 RemoteCacheListenerMockImpl listener = new RemoteCacheListenerMockImpl();
51
52 RemoteCache remoteCache = new RemoteCache( cattr, service, listener );
53
54 String cacheName = "testUpdate";
55
56
57 ICacheElement element = new CacheElement( cacheName, "key", "value" );
58 remoteCache.update( element );
59
60
61 assertTrue( "The element should be in the serialized warapper.",
62 service.lastUpdate instanceof ICacheElementSerialized );
63 ICacheElement result = SerializationConversionUtil
64 .getDeSerializedCacheElement( (ICacheElementSerialized) service.lastUpdate, remoteCache
65 .getElementSerializer() );
66 assertEquals( "Wrong element updated.", element.getVal(), result.getVal() );
67 }
68
69 /***
70 * Verify that when we call fix events queued in the zombie are propagated to the new service.
71 * <p>
72 * @throws Exception
73 */
74 public void testUpdateZombieThenFix()
75 throws Exception
76 {
77
78 IRemoteCacheAttributes cattr = new RemoteCacheAttributes();
79 ZombieRemoteCacheService zombie = new ZombieRemoteCacheService( 10 );
80 RemoteCacheServiceMockImpl service = new RemoteCacheServiceMockImpl();
81 RemoteCacheListenerMockImpl listener = new RemoteCacheListenerMockImpl();
82
83
84 RemoteCache remoteCache = new RemoteCache( cattr, zombie, listener );
85
86 String cacheName = "testUpdate";
87
88
89 ICacheElement element = new CacheElement( cacheName, "key", "value" );
90 remoteCache.update( element );
91
92 remoteCache.fixCache( service );
93
94
95 assertTrue( "The element should be in the serialized warapper.",
96 service.lastUpdate instanceof ICacheElementSerialized );
97 ICacheElement result = SerializationConversionUtil
98 .getDeSerializedCacheElement( (ICacheElementSerialized) service.lastUpdate, remoteCache
99 .getElementSerializer() );
100 assertEquals( "Wrong element updated.", element.getVal(), result.getVal() );
101 }
102 }