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