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.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.jcs.JCS;
27 import org.apache.jcs.auxiliary.AuxiliaryCache;
28 import org.apache.jcs.auxiliary.remote.server.RemoteCacheServerFactory;
29 import org.apache.jcs.engine.CacheElement;
30 import org.apache.jcs.engine.behavior.ICompositeCacheManager;
31 import org.apache.jcs.engine.control.CompositeCacheManagerMockImpl;
32
33 /***
34 * @author asmuts
35 */
36 public class TestRemoteCache
37 extends TestCase
38 {
39
40 private final static Log log = LogFactory.getLog( TestRemoteCache.class );
41
42 /***
43 *
44 *
45 */
46 public TestRemoteCache()
47 {
48 super();
49 try
50 {
51 System.out.println( "main> creating registry on the localhost" );
52 RemoteUtils.createRegistry( 1101 );
53
54 RemoteCacheServerFactory.startup( "localhost", 1101, "/TestRemoteServer.ccf" );
55 }
56 catch ( Exception e )
57 {
58 e.printStackTrace();
59 }
60 }
61
62 /***
63 * Test setup
64 */
65 public void setUp()
66 {
67 JCS.setConfigFilename( "/TestRemoteClient.ccf" );
68 }
69
70 /***
71 * @throws Exception
72 *
73 *
74 */
75 public void skiptestSimpleSend()
76 throws Exception
77 {
78 log.info( "testSimpleSend" );
79 System.out.println( "testSimpleSend" );
80
81 JCS cache = JCS.getInstance( "testCache" );
82
83 log.info( "cache = " + cache );
84
85 for ( int i = 0; i < 1000; i++ )
86 {
87 System.out.println( "puttting " + i );
88 cache.put( "key" + i, "data" + i );
89 System.out.println( "put " + i );
90 log.info( "put " + i );
91 }
92 }
93
94 /***
95 * @throws Exception
96 */
97 public void testService()
98 throws Exception
99 {
100
101 Thread.sleep( 100 );
102
103 ICompositeCacheManager cacheMgr = new CompositeCacheManagerMockImpl();
104
105 RemoteCacheAttributes rca = new RemoteCacheAttributes();
106 rca.setRemoteHost( "localhost" );
107 rca.setRemotePort( 1101 );
108
109 RemoteCacheManager mgr = RemoteCacheManager.getInstance( rca, cacheMgr );
110 AuxiliaryCache cache = mgr.getCache( "testCache" );
111
112 int numMes = 100;
113 for ( int i = 0; i < numMes; i++ )
114 {
115 String message = "adsfasasfasfasdasf";
116 CacheElement ce = new CacheElement( "key" + 1, "data" + i, message );
117 cache.update( ce );
118 System.out.println( "put " + ce );
119 }
120
121
122
123
124
125
126
127
128
129
130
131
132
133 }
134 }