1   package org.apache.jcs.auxiliary.remote;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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         // Thread.sleep( 2000 );
122 
123         /*
124          * // the receiver instance. JCS cacheReceiver = JCS.getInstance(
125          * "testCache" );
126          *
127          * log.info( "cache = " + cache );
128          *
129          * for ( int i = 0; i < numMes; i++ ) { System.out.println( "getting " +
130          * i ); Object data = cacheReceiver.get( "key" + i );
131          * System.out.println( i + " = " + data ); }
132          */
133     }
134 }