1 package org.apache.commons.jcs.auxiliary.remote;
2
3 import java.util.Properties;
4
5 import org.apache.commons.jcs.JCS;
6 import org.apache.commons.jcs.access.CacheAccess;
7 import org.apache.commons.jcs.auxiliary.AuxiliaryCache;
8 import org.apache.commons.jcs.auxiliary.MockCacheEventLogger;
9 import org.apache.commons.jcs.auxiliary.remote.server.RemoteCacheServerFactory;
10 import org.apache.commons.jcs.engine.CacheElement;
11 import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
12 import org.apache.commons.jcs.engine.control.MockCompositeCacheManager;
13 import org.apache.commons.jcs.engine.control.MockElementSerializer;
14 import org.apache.commons.logging.Log;
15 import org.apache.commons.logging.LogFactory;
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 import junit.framework.TestCase;
37
38
39
40
41 public class TestRemoteCache
42 extends TestCase
43 {
44
45 private static final Log log = LogFactory.getLog( TestRemoteCache.class );
46
47
48
49
50 public TestRemoteCache()
51 {
52 super();
53 try
54 {
55 System.out.println( "main> creating registry on the localhost" );
56 RemoteUtils.createRegistry( 1101 );
57 Properties config = RemoteUtils.loadProps("/TestRemoteServer.ccf");
58
59 RemoteCacheServerFactory.startup( "localhost", 1101, config);
60 }
61 catch ( Exception e )
62 {
63 e.printStackTrace();
64 }
65 }
66
67
68
69
70 @Override
71 public void setUp()
72 {
73 JCS.setConfigFilename( "/TestRemoteClient.ccf" );
74 }
75
76
77
78
79
80
81 public void skiptestSimpleSend()
82 throws Exception
83 {
84 log.info( "testSimpleSend" );
85
86 CacheAccess<String, String> cache = JCS.getInstance( "testCache" );
87
88 log.info( "cache = " + cache );
89
90 for ( int i = 0; i < 1000; i++ )
91 {
92
93 cache.put( "key" + i, "data" + i );
94
95 log.info( "put " + i );
96 }
97 }
98
99
100
101
102 public void testService()
103 throws Exception
104 {
105
106 Thread.sleep( 100 );
107
108 ICompositeCacheManager cacheMgr = new MockCompositeCacheManager();
109
110 RemoteCacheAttributes rca = new RemoteCacheAttributes();
111 rca.setRemoteLocation( "localhost", 1101 );
112 rca.setCacheName( "testCache" );
113
114 RemoteCacheFactory factory = new RemoteCacheFactory();
115 factory.initialize();
116 RemoteCacheManager mgr = factory.getManager( rca, cacheMgr, new MockCacheEventLogger(), new MockElementSerializer() );
117 AuxiliaryCache<String, String> cache = mgr.getCache( rca );
118
119 int numMes = 100;
120 for ( int i = 0; i < numMes; i++ )
121 {
122 String message = "adsfasasfasfasdasf";
123 CacheElement<String, String> ce = new CacheElement<String, String>( "key" + 1, "data" + i, message );
124 cache.update( ce );
125
126 }
127
128
129
130
131
132
133
134
135
136
137
138
139
140 }
141 }