Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheServiceMockImpl.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheServiceMockImpl.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheServiceMockImpl.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheServiceMockImpl.java Thu May 10 09:03:42 2007
@@ -1,151 +1,170 @@
-package org.apache.jcs.auxiliary.remote;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.rmi.RemoteException;
-import java.util.Set;
-
-import org.apache.jcs.access.exception.ObjectExistsException;
-import org.apache.jcs.access.exception.ObjectNotFoundException;
-import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService;
-import org.apache.jcs.engine.behavior.ICacheElement;
-
-/**
- * This is a mock impl of the remote cache service.
- * <p>
- * @author admin
- */
-public class RemoteCacheServiceMockImpl
- implements IRemoteCacheService
-{
- /** The object that was last passed to update. */
- public Object lastUpdate;
-
- /** The key that was last passed to remove. */
- public Object lastRemoveKey;
-
- /**
- * The cache name that was last passed to removeAll.
- */
- public String lastRemoveAllCacheName;
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#get(java.lang.String,
- * java.io.Serializable, long)
- */
- public ICacheElement get( String cacheName, Serializable key, long requesterId )
- throws IOException
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#getGroupKeys(java.lang.String,
- * java.lang.String)
- */
- public Set getGroupKeys( String cacheName, String groupName )
- throws RemoteException
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#remove(java.lang.String,
- * java.io.Serializable, long)
- */
- public void remove( String cacheName, Serializable key, long requesterId )
- throws IOException
- {
- lastRemoveKey = key;
- }
-
- /**
- * Set the lastRemoveAllCacheName to the cacheName.
- * <p>
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#removeAll(java.lang.String,
- * long)
- */
- public void removeAll( String cacheName, long requesterId )
- throws IOException
- {
- lastRemoveAllCacheName = cacheName;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#update(org.apache.jcs.engine.behavior.ICacheElement,
- * long)
- */
- public void update( ICacheElement item, long requesterId )
- throws ObjectExistsException, IOException
- {
- lastUpdate = item;
- }
-
- public void dispose( String cacheName )
- throws IOException
- {
- // TODO Auto-generated method stub
-
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.engine.behavior.ICacheService#get(java.lang.String, java.io.Serializable)
- */
- public ICacheElement get( String cacheName, Serializable key )
- throws ObjectNotFoundException, IOException
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.engine.behavior.ICacheService#release()
- */
- public void release()
- throws IOException
- {
- // TODO Auto-generated method stub
-
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.engine.behavior.ICacheService#remove(java.lang.String,
- * java.io.Serializable)
- */
- public void remove( String cacheName, Serializable key )
- throws IOException
- {
- lastRemoveKey = key;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.engine.behavior.ICacheService#removeAll(java.lang.String)
- */
- public void removeAll( String cacheName )
- throws IOException
- {
- lastRemoveAllCacheName = cacheName;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.engine.behavior.ICacheService#update(org.apache.jcs.engine.behavior.ICacheElement)
- */
- public void update( ICacheElement item )
- throws ObjectExistsException, IOException
- {
- lastUpdate = item;
- }
-
-}
+package org.apache.jcs.auxiliary.remote;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.rmi.RemoteException;
+import java.util.Set;
+
+import org.apache.jcs.access.exception.ObjectExistsException;
+import org.apache.jcs.access.exception.ObjectNotFoundException;
+import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService;
+import org.apache.jcs.engine.behavior.ICacheElement;
+
+/**
+ * This is a mock impl of the remote cache service.
+ * <p>
+ * @author admin
+ */
+public class RemoteCacheServiceMockImpl
+ implements IRemoteCacheService
+{
+ /** The object that was last passed to update. */
+ public Object lastUpdate;
+
+ /** The key that was last passed to remove. */
+ public Object lastRemoveKey;
+
+ /**
+ * The cache name that was last passed to removeAll.
+ */
+ public String lastRemoveAllCacheName;
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#get(java.lang.String,
+ * java.io.Serializable, long)
+ */
+ public ICacheElement get( String cacheName, Serializable key, long requesterId )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#getGroupKeys(java.lang.String,
+ * java.lang.String)
+ */
+ public Set getGroupKeys( String cacheName, String groupName )
+ throws RemoteException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#remove(java.lang.String,
+ * java.io.Serializable, long)
+ */
+ public void remove( String cacheName, Serializable key, long requesterId )
+ throws IOException
+ {
+ lastRemoveKey = key;
+ }
+
+ /**
+ * Set the lastRemoveAllCacheName to the cacheName.
+ * <p>
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#removeAll(java.lang.String,
+ * long)
+ */
+ public void removeAll( String cacheName, long requesterId )
+ throws IOException
+ {
+ lastRemoveAllCacheName = cacheName;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#update(org.apache.jcs.engine.behavior.ICacheElement,
+ * long)
+ */
+ public void update( ICacheElement item, long requesterId )
+ throws ObjectExistsException, IOException
+ {
+ lastUpdate = item;
+ }
+
+ public void dispose( String cacheName )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.engine.behavior.ICacheService#get(java.lang.String, java.io.Serializable)
+ */
+ public ICacheElement get( String cacheName, Serializable key )
+ throws ObjectNotFoundException, IOException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.engine.behavior.ICacheService#release()
+ */
+ public void release()
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.engine.behavior.ICacheService#remove(java.lang.String,
+ * java.io.Serializable)
+ */
+ public void remove( String cacheName, Serializable key )
+ throws IOException
+ {
+ lastRemoveKey = key;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.engine.behavior.ICacheService#removeAll(java.lang.String)
+ */
+ public void removeAll( String cacheName )
+ throws IOException
+ {
+ lastRemoveAllCacheName = cacheName;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.engine.behavior.ICacheService#update(org.apache.jcs.engine.behavior.ICacheElement)
+ */
+ public void update( ICacheElement item )
+ throws ObjectExistsException, IOException
+ {
+ lastUpdate = item;
+ }
+
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheUnitTest.java Thu May 10 09:03:42 2007
@@ -1,94 +1,102 @@
-package org.apache.jcs.auxiliary.remote;
-
-/*
- * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache
- * License, Version 2.0 (the "License") you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
- */
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
-import org.apache.jcs.engine.CacheElement;
-import org.apache.jcs.engine.behavior.ICacheElement;
-import org.apache.jcs.engine.behavior.ICacheElementSerialized;
-import org.apache.jcs.utils.serialization.SerializationConversionUtil;
-
-/**
- * Unit Tests for the Remote Cache.
- * <p>
- * @author admin
- */
-public class RemoteCacheUnitTest
- extends TestCase
-{
- /**
- * Verify that the remote service update method is called. The remote cache serializes the obect
- * first.
- * <p>
- * @throws Exception
- */
- public void testUpdate()
- throws Exception
- {
- // SETUP
- IRemoteCacheAttributes cattr = new RemoteCacheAttributes();
- RemoteCacheServiceMockImpl service = new RemoteCacheServiceMockImpl();
- RemoteCacheListenerMockImpl listener = new RemoteCacheListenerMockImpl();
-
- RemoteCache remoteCache = new RemoteCache( cattr, service, listener );
-
- String cacheName = "testUpdate";
-
- // DO WORK
- ICacheElement element = new CacheElement( cacheName, "key", "value" );
- remoteCache.update( element );
-
- // VERIFY
- assertTrue( "The element should be in the serialized warapper.",
- service.lastUpdate instanceof ICacheElementSerialized );
- ICacheElement result = SerializationConversionUtil
- .getDeSerializedCacheElement( (ICacheElementSerialized) service.lastUpdate, remoteCache
- .getElementSerializer() );
- assertEquals( "Wrong element updated.", element.getVal(), result.getVal() );
- }
-
- /**
- * Verify that when we call fix events queued in the zombie are propagated to the new service.
- * <p>
- * @throws Exception
- */
- public void testUpdateZombieThenFix()
- throws Exception
- {
- // SETUP
- IRemoteCacheAttributes cattr = new RemoteCacheAttributes();
- ZombieRemoteCacheService zombie = new ZombieRemoteCacheService( 10 );
- RemoteCacheServiceMockImpl service = new RemoteCacheServiceMockImpl();
- RemoteCacheListenerMockImpl listener = new RemoteCacheListenerMockImpl();
-
- // set the zombir
- RemoteCache remoteCache = new RemoteCache( cattr, zombie, listener );
-
- String cacheName = "testUpdate";
-
- // DO WORK
- ICacheElement element = new CacheElement( cacheName, "key", "value" );
- remoteCache.update( element );
- // set the new service, this should call propogate
- remoteCache.fixCache( service );
-
- // VERIFY
- assertTrue( "The element should be in the serialized warapper.",
- service.lastUpdate instanceof ICacheElementSerialized );
- ICacheElement result = SerializationConversionUtil
- .getDeSerializedCacheElement( (ICacheElementSerialized) service.lastUpdate, remoteCache
- .getElementSerializer() );
- assertEquals( "Wrong element updated.", element.getVal(), result.getVal() );
- }
-}
+package org.apache.jcs.auxiliary.remote;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
+import org.apache.jcs.engine.CacheElement;
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.behavior.ICacheElementSerialized;
+import org.apache.jcs.utils.serialization.SerializationConversionUtil;
+
+/**
+ * Unit Tests for the Remote Cache.
+ * <p>
+ * @author admin
+ */
+public class RemoteCacheUnitTest
+ extends TestCase
+{
+ /**
+ * Verify that the remote service update method is called. The remote cache serializes the obect
+ * first.
+ * <p>
+ * @throws Exception
+ */
+ public void testUpdate()
+ throws Exception
+ {
+ // SETUP
+ IRemoteCacheAttributes cattr = new RemoteCacheAttributes();
+ RemoteCacheServiceMockImpl service = new RemoteCacheServiceMockImpl();
+ RemoteCacheListenerMockImpl listener = new RemoteCacheListenerMockImpl();
+
+ RemoteCache remoteCache = new RemoteCache( cattr, service, listener );
+
+ String cacheName = "testUpdate";
+
+ // DO WORK
+ ICacheElement element = new CacheElement( cacheName, "key", "value" );
+ remoteCache.update( element );
+
+ // VERIFY
+ assertTrue( "The element should be in the serialized warapper.",
+ service.lastUpdate instanceof ICacheElementSerialized );
+ ICacheElement result = SerializationConversionUtil
+ .getDeSerializedCacheElement( (ICacheElementSerialized) service.lastUpdate, remoteCache
+ .getElementSerializer() );
+ assertEquals( "Wrong element updated.", element.getVal(), result.getVal() );
+ }
+
+ /**
+ * Verify that when we call fix events queued in the zombie are propagated to the new service.
+ * <p>
+ * @throws Exception
+ */
+ public void testUpdateZombieThenFix()
+ throws Exception
+ {
+ // SETUP
+ IRemoteCacheAttributes cattr = new RemoteCacheAttributes();
+ ZombieRemoteCacheService zombie = new ZombieRemoteCacheService( 10 );
+ RemoteCacheServiceMockImpl service = new RemoteCacheServiceMockImpl();
+ RemoteCacheListenerMockImpl listener = new RemoteCacheListenerMockImpl();
+
+ // set the zombir
+ RemoteCache remoteCache = new RemoteCache( cattr, zombie, listener );
+
+ String cacheName = "testUpdate";
+
+ // DO WORK
+ ICacheElement element = new CacheElement( cacheName, "key", "value" );
+ remoteCache.update( element );
+ // set the new service, this should call propogate
+ remoteCache.fixCache( service );
+
+ // VERIFY
+ assertTrue( "The element should be in the serialized warapper.",
+ service.lastUpdate instanceof ICacheElementSerialized );
+ ICacheElement result = SerializationConversionUtil
+ .getDeSerializedCacheElement( (ICacheElementSerialized) service.lastUpdate, remoteCache
+ .getElementSerializer() );
+ assertEquals( "Wrong element updated.", element.getVal(), result.getVal() );
+ }
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteUtilsUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteUtilsUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteUtilsUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteUtilsUnitTest.java Thu May 10 09:03:42 2007
@@ -1,60 +1,68 @@
-package org.apache.jcs.auxiliary.remote;
-
-/*
- * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache
- * License, Version 2.0 (the "License") you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
- */
-
-import java.rmi.RemoteException;
-
-import junit.framework.TestCase;
-
-/**
- * Simple tests for remote utils. It is difficult to verify most of the things is does.
- *
- * @author Aaron Smuts
- *
- */
-public class RemoteUtilsUnitTest
- extends TestCase
-{
-
- /**
- * Call create registry twice.
- *
- * <p>
- * The exception is in the security manager setting.
- *
- */
- public void testCreateRegistryTwice()
- {
- try
- {
- RemoteUtils.createRegistry( 1102 );
- }
- catch ( RemoteException e )
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- try
- {
- RemoteUtils.createRegistry( 1102 );
- }
- catch ( Exception e )
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
-
-}
+package org.apache.jcs.auxiliary.remote;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.rmi.RemoteException;
+
+import junit.framework.TestCase;
+
+/**
+ * Simple tests for remote utils. It is difficult to verify most of the things is does.
+ *
+ * @author Aaron Smuts
+ *
+ */
+public class RemoteUtilsUnitTest
+ extends TestCase
+{
+
+ /**
+ * Call create registry twice.
+ *
+ * <p>
+ * The exception is in the security manager setting.
+ *
+ */
+ public void testCreateRegistryTwice()
+ {
+ try
+ {
+ RemoteUtils.createRegistry( 1102 );
+ }
+ catch ( RemoteException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ try
+ {
+ RemoteUtils.createRegistry( 1102 );
+ }
+ catch ( Exception e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/TestRemoteCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/TestRemoteCache.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/TestRemoteCache.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/TestRemoteCache.java Thu May 10 09:03:42 2007
@@ -1,126 +1,134 @@
-package org.apache.jcs.auxiliary.remote;
-
-/*
- * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache
- * License, Version 2.0 (the "License") you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
- */
-
-import junit.framework.TestCase;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jcs.JCS;
-import org.apache.jcs.auxiliary.AuxiliaryCache;
-import org.apache.jcs.auxiliary.remote.server.RemoteCacheServerFactory;
-import org.apache.jcs.engine.CacheElement;
-import org.apache.jcs.engine.behavior.ICompositeCacheManager;
-import org.apache.jcs.engine.control.CompositeCacheManagerMockImpl;
-
-/**
- * @author asmuts
- */
-public class TestRemoteCache
- extends TestCase
-{
-
- private final static Log log = LogFactory.getLog( TestRemoteCache.class );
-
- /**
- *
- *
- */
- public TestRemoteCache()
- {
- super();
- try
- {
- System.out.println( "main> creating registry on the localhost" );
- RemoteUtils.createRegistry( 1101 );
-
- RemoteCacheServerFactory.startup( "localhost", 1101, "/TestRemoteServer.ccf" );
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
- }
-
- /**
- * Test setup
- */
- public void setUp()
- {
- JCS.setConfigFilename( "/TestRemoteClient.ccf" );
- }
-
- /**
- * @throws Exception
- *
- *
- */
- public void skiptestSimpleSend()
- throws Exception
- {
- log.info( "testSimpleSend" );
- System.out.println( "testSimpleSend" );
-
- JCS cache = JCS.getInstance( "testCache" );
-
- log.info( "cache = " + cache );
-
- for ( int i = 0; i < 1000; i++ )
- {
- System.out.println( "puttting " + i );
- cache.put( "key" + i, "data" + i );
- System.out.println( "put " + i );
- log.info( "put " + i );
- }
- }
-
- /**
- * @throws Exception
- */
- public void testService()
- throws Exception
- {
-
- Thread.sleep( 100 );
-
- ICompositeCacheManager cacheMgr = new CompositeCacheManagerMockImpl();
-
- RemoteCacheAttributes rca = new RemoteCacheAttributes();
- rca.setRemoteHost( "localhost" );
- rca.setRemotePort( 1101 );
-
- RemoteCacheManager mgr = RemoteCacheManager.getInstance( rca, cacheMgr );
- AuxiliaryCache cache = mgr.getCache( "testCache" );
-
- int numMes = 100;
- for ( int i = 0; i < numMes; i++ )
- {
- String message = "adsfasasfasfasdasf";
- CacheElement ce = new CacheElement( "key" + 1, "data" + i, message );
- cache.update( ce );
- System.out.println( "put " + ce );
- }
-
- // Thread.sleep( 2000 );
-
- /*
- * // the receiver instance. JCS cacheReceiver = JCS.getInstance(
- * "testCache" );
- *
- * log.info( "cache = " + cache );
- *
- * for ( int i = 0; i < numMes; i++ ) { System.out.println( "getting " +
- * i ); Object data = cacheReceiver.get( "key" + i );
- * System.out.println( i + " = " + data ); }
- */
- }
-}
+package org.apache.jcs.auxiliary.remote;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.JCS;
+import org.apache.jcs.auxiliary.AuxiliaryCache;
+import org.apache.jcs.auxiliary.remote.server.RemoteCacheServerFactory;
+import org.apache.jcs.engine.CacheElement;
+import org.apache.jcs.engine.behavior.ICompositeCacheManager;
+import org.apache.jcs.engine.control.CompositeCacheManagerMockImpl;
+
+/**
+ * @author asmuts
+ */
+public class TestRemoteCache
+ extends TestCase
+{
+
+ private final static Log log = LogFactory.getLog( TestRemoteCache.class );
+
+ /**
+ *
+ *
+ */
+ public TestRemoteCache()
+ {
+ super();
+ try
+ {
+ System.out.println( "main> creating registry on the localhost" );
+ RemoteUtils.createRegistry( 1101 );
+
+ RemoteCacheServerFactory.startup( "localhost", 1101, "/TestRemoteServer.ccf" );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Test setup
+ */
+ public void setUp()
+ {
+ JCS.setConfigFilename( "/TestRemoteClient.ccf" );
+ }
+
+ /**
+ * @throws Exception
+ *
+ *
+ */
+ public void skiptestSimpleSend()
+ throws Exception
+ {
+ log.info( "testSimpleSend" );
+ System.out.println( "testSimpleSend" );
+
+ JCS cache = JCS.getInstance( "testCache" );
+
+ log.info( "cache = " + cache );
+
+ for ( int i = 0; i < 1000; i++ )
+ {
+ System.out.println( "puttting " + i );
+ cache.put( "key" + i, "data" + i );
+ System.out.println( "put " + i );
+ log.info( "put " + i );
+ }
+ }
+
+ /**
+ * @throws Exception
+ */
+ public void testService()
+ throws Exception
+ {
+
+ Thread.sleep( 100 );
+
+ ICompositeCacheManager cacheMgr = new CompositeCacheManagerMockImpl();
+
+ RemoteCacheAttributes rca = new RemoteCacheAttributes();
+ rca.setRemoteHost( "localhost" );
+ rca.setRemotePort( 1101 );
+
+ RemoteCacheManager mgr = RemoteCacheManager.getInstance( rca, cacheMgr );
+ AuxiliaryCache cache = mgr.getCache( "testCache" );
+
+ int numMes = 100;
+ for ( int i = 0; i < numMes; i++ )
+ {
+ String message = "adsfasasfasfasdasf";
+ CacheElement ce = new CacheElement( "key" + 1, "data" + i, message );
+ cache.update( ce );
+ System.out.println( "put " + ce );
+ }
+
+ // Thread.sleep( 2000 );
+
+ /*
+ * // the receiver instance. JCS cacheReceiver = JCS.getInstance(
+ * "testCache" );
+ *
+ * log.info( "cache = " + cache );
+ *
+ * for ( int i = 0; i < numMes; i++ ) { System.out.println( "getting " +
+ * i ); Object data = cacheReceiver.get( "key" + i );
+ * System.out.println( i + " = " + data ); }
+ */
+ }
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheServiceUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheServiceUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheServiceUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheServiceUnitTest.java Thu May 10 09:03:42 2007
@@ -1,119 +1,127 @@
-package org.apache.jcs.auxiliary.remote;
-
-/*
- * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache
- * License, Version 2.0 (the "License") you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
- */
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.engine.CacheElement;
-import org.apache.jcs.engine.behavior.ICacheElement;
-
-/**
- * Tests for the zombie remote cache service.
- */
-public class ZombieRemoteCacheServiceUnitTest
- extends TestCase
-{
- /**
- * Verify that an update event gets added and then is sent to the service passed to propagate.
- * <p>
- * @throws Exception
- */
- public void testUpdateThenWalk()
- throws Exception
- {
- // SETUP
- RemoteCacheServiceMockImpl service = new RemoteCacheServiceMockImpl();
-
- ZombieRemoteCacheService zombie = new ZombieRemoteCacheService( 10 );
-
- String cacheName = "testUpdate";
-
- // DO WORK
- ICacheElement element = new CacheElement( cacheName, "key", "value" );
- zombie.update( element, 123l );
- zombie.propagateEvents( service );
-
- // VERIFY
- assertEquals( "Updated element is not as expected.", element, service.lastUpdate );
- }
-
- /**
- * Verify that nothing is added if the max is set to 0.
- * <p>
- * @throws Exception
- */
- public void testUpdateThenWalk_zeroSize()
- throws Exception
- {
- // SETUP
- RemoteCacheServiceMockImpl service = new RemoteCacheServiceMockImpl();
-
- ZombieRemoteCacheService zombie = new ZombieRemoteCacheService( 0 );
-
- String cacheName = "testUpdate";
-
- // DO WORK
- ICacheElement element = new CacheElement( cacheName, "key", "value" );
- zombie.update( element, 123l );
- zombie.propagateEvents( service );
-
- // VERIFY
- assertNull( "Nothing should have been put to the service.", service.lastUpdate );
- }
-
- /**
- * Verify that a remove event gets added and then is sent to the service passed to propagate.
- * <p>
- * @throws Exception
- */
- public void testRemoveThenWalk()
- throws Exception
- {
- // SETUP
- RemoteCacheServiceMockImpl service = new RemoteCacheServiceMockImpl();
-
- ZombieRemoteCacheService zombie = new ZombieRemoteCacheService( 10 );
-
- String cacheName = "testRemoveThenWalk";
- String key = "myKey";
-
- // DO WORK
- zombie.remove( cacheName, key, 123l );
- zombie.propagateEvents( service );
-
- // VERIFY
- assertEquals( "Updated element is not as expected.", key, service.lastRemoveKey );
- }
-
- /**
- * Verify that a removeAll event gets added and then is sent to the service passed to propagate.
- * <p>
- * @throws Exception
- */
- public void testRemoveAllThenWalk()
- throws Exception
- {
- // SETUP
- RemoteCacheServiceMockImpl service = new RemoteCacheServiceMockImpl();
-
- ZombieRemoteCacheService zombie = new ZombieRemoteCacheService( 10 );
-
- String cacheName = "testRemoveThenWalk";
-
- // DO WORK
- zombie.removeAll( cacheName, 123l );
- zombie.propagateEvents( service );
-
- // VERIFY
- assertEquals( "Updated element is not as expected.", cacheName, service.lastRemoveAllCacheName);
- }
-}
+package org.apache.jcs.auxiliary.remote;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.engine.CacheElement;
+import org.apache.jcs.engine.behavior.ICacheElement;
+
+/**
+ * Tests for the zombie remote cache service.
+ */
+public class ZombieRemoteCacheServiceUnitTest
+ extends TestCase
+{
+ /**
+ * Verify that an update event gets added and then is sent to the service passed to propagate.
+ * <p>
+ * @throws Exception
+ */
+ public void testUpdateThenWalk()
+ throws Exception
+ {
+ // SETUP
+ RemoteCacheServiceMockImpl service = new RemoteCacheServiceMockImpl();
+
+ ZombieRemoteCacheService zombie = new ZombieRemoteCacheService( 10 );
+
+ String cacheName = "testUpdate";
+
+ // DO WORK
+ ICacheElement element = new CacheElement( cacheName, "key", "value" );
+ zombie.update( element, 123l );
+ zombie.propagateEvents( service );
+
+ // VERIFY
+ assertEquals( "Updated element is not as expected.", element, service.lastUpdate );
+ }
+
+ /**
+ * Verify that nothing is added if the max is set to 0.
+ * <p>
+ * @throws Exception
+ */
+ public void testUpdateThenWalk_zeroSize()
+ throws Exception
+ {
+ // SETUP
+ RemoteCacheServiceMockImpl service = new RemoteCacheServiceMockImpl();
+
+ ZombieRemoteCacheService zombie = new ZombieRemoteCacheService( 0 );
+
+ String cacheName = "testUpdate";
+
+ // DO WORK
+ ICacheElement element = new CacheElement( cacheName, "key", "value" );
+ zombie.update( element, 123l );
+ zombie.propagateEvents( service );
+
+ // VERIFY
+ assertNull( "Nothing should have been put to the service.", service.lastUpdate );
+ }
+
+ /**
+ * Verify that a remove event gets added and then is sent to the service passed to propagate.
+ * <p>
+ * @throws Exception
+ */
+ public void testRemoveThenWalk()
+ throws Exception
+ {
+ // SETUP
+ RemoteCacheServiceMockImpl service = new RemoteCacheServiceMockImpl();
+
+ ZombieRemoteCacheService zombie = new ZombieRemoteCacheService( 10 );
+
+ String cacheName = "testRemoveThenWalk";
+ String key = "myKey";
+
+ // DO WORK
+ zombie.remove( cacheName, key, 123l );
+ zombie.propagateEvents( service );
+
+ // VERIFY
+ assertEquals( "Updated element is not as expected.", key, service.lastRemoveKey );
+ }
+
+ /**
+ * Verify that a removeAll event gets added and then is sent to the service passed to propagate.
+ * <p>
+ * @throws Exception
+ */
+ public void testRemoveAllThenWalk()
+ throws Exception
+ {
+ // SETUP
+ RemoteCacheServiceMockImpl service = new RemoteCacheServiceMockImpl();
+
+ ZombieRemoteCacheService zombie = new ZombieRemoteCacheService( 10 );
+
+ String cacheName = "testRemoveThenWalk";
+
+ // DO WORK
+ zombie.removeAll( cacheName, 123l );
+ zombie.propagateEvents( service );
+
+ // VERIFY
+ assertEquals( "Updated element is not as expected.", cacheName, service.lastRemoveAllCacheName);
+ }
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java Thu May 10 09:03:42 2007
@@ -1,210 +1,220 @@
-package org.apache.jcs.auxiliary.remote.server;
-
-/*
- * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache License, Version
- * 2.0 (the "License") you may not use this file except in compliance with the License. You may
- * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
- * applicable law or agreed to in writing, software distributed under the License is distributed on
- * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
- * the License for the specific language governing permissions and limitations under the License.
- */
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.auxiliary.AuxiliaryCache;
-import org.apache.jcs.auxiliary.remote.RemoteCacheAttributes;
-import org.apache.jcs.auxiliary.remote.RemoteCacheListenerMockImpl;
-import org.apache.jcs.auxiliary.remote.RemoteCacheManager;
-import org.apache.jcs.engine.CacheElement;
-import org.apache.jcs.engine.behavior.ICacheElement;
-import org.apache.jcs.engine.control.CompositeCacheManagerMockImpl;
-import org.apache.jcs.utils.timing.SleepUtil;
-
-/**
- * These tests startup the remote server and make requests to it.
- * <p>
- * @author Aaron Smuts
- */
-public class BasicRemoteCacheClientServerUnitTest
- extends TestCase
-{
- RemoteCacheServer server = null;
-
- /**
- * Starts the server. This is not in a setup, since the server is slow to kill right now.
- */
- public BasicRemoteCacheClientServerUnitTest()
- {
- String configFile = "TestRemoteCacheClientServer.ccf";
- server = RemoteCacheServerStartupUtil.startServerUsingProperties( configFile );
- }
-
- /**
- * Verify that we can start the remote cache server. Send an item to the remote. Verify that the
- * remote put count goes up. If we go through JCS, the manager will be shared and we will get
- * into an endless loop. We will use a mock cache manager instead.
- * <p>
- * The remote server uses the real JCS. We can verify that items are added to JCS behind the
- * server by calling get. We cannot access it directly via JCS since it is serialized.
- * <p>
- * This test uses a mock injected client to test a normal server.
- * <p>
- * @throws Exception
- */
- public void testSinglePut()
- throws Exception
- {
- // SETUP
- CompositeCacheManagerMockImpl compositeCacheManager = new CompositeCacheManagerMockImpl();
-
- RemoteCacheAttributes attributes = new RemoteCacheAttributes();
- attributes.setRemoteHost( "localhost" );
- attributes.setLocalPort( 1202 );
- attributes.setRemotePort( 1101 );
-
- RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes, compositeCacheManager );
- String regionName = "testSinglePut";
- AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
-
- // DO WORK
- int numPutsPrior = server.getPutCount();
- ICacheElement element = new CacheElement( regionName, "key", "value" );
- cache.update( element );
- SleepUtil.sleepAtLeast( 50 );
-
- // VERIFY
- System.out.println( server.getStats() );
- assertEquals( "Wrong number of puts", 1, server.getPutCount() - numPutsPrior );
-
- // DO WORK
- ICacheElement result = cache.get( "key" );
-
- // VERIFY
- assertEquals( "Wrong element.", element.getVal(), result.getVal() );
- }
-
- /**
- * Verify that we can remove an item via the remote server.
- * <p>
- * @throws Exception
- */
- public void testPutRemove()
- throws Exception
- {
- // SETUP
- CompositeCacheManagerMockImpl compositeCacheManager = new CompositeCacheManagerMockImpl();
-
- RemoteCacheAttributes attributes = new RemoteCacheAttributes();
- attributes.setRemoteHost( "localhost" );
- attributes.setLocalPort( 1202 );
- attributes.setRemotePort( 1101 );
-
- RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes, compositeCacheManager );
- String regionName = "testPutRemove";
- AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
-
- // DO WORK
- int numPutsPrior = server.getPutCount();
- ICacheElement element = new CacheElement( regionName, "key", "value" );
- cache.update( element );
- SleepUtil.sleepAtLeast( 50 );
-
- // VERIFY
- System.out.println( server.getStats() );
- assertEquals( "Wrong number of puts", 1, server.getPutCount() - numPutsPrior );
-
- // DO WORK
- ICacheElement result = cache.get( "key" );
-
- // VERIFY
- assertEquals( "Wrong element.", element.getVal(), result.getVal() );
-
- // DO WORK
- cache.remove( "key" );
- SleepUtil.sleepAtLeast( 50 );
- ICacheElement resultAfterRemote = cache.get( "key" );
-
- // VERIFY
- assertNull( "Element resultAfterRemote should be null.", resultAfterRemote );
- }
-
- /**
- * Register a listener with the server. Send an update. Verify that the listener received it.
- * @throws Exception
- */
- public void testPutAndListen()
- throws Exception
- {
- // SETUP
- CompositeCacheManagerMockImpl compositeCacheManager = new CompositeCacheManagerMockImpl();
-
- RemoteCacheAttributes attributes = new RemoteCacheAttributes();
- attributes.setRemoteHost( "localhost" );
- attributes.setLocalPort( 1202 );
- attributes.setRemotePort( 1101 );
-
- RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes, compositeCacheManager );
- String regionName = "testPutAndListen";
- AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
-
- RemoteCacheListenerMockImpl listener = new RemoteCacheListenerMockImpl();
- server.addCacheListener( regionName, listener );
-
- // DO WORK
- int numPutsPrior = server.getPutCount();
- ICacheElement element = new CacheElement( regionName, "key", "value" );
- cache.update( element );
- SleepUtil.sleepAtLeast( 50 );
-
- // VERIFY
- try
- {
- System.out.println( server.getStats() );
- assertEquals( "Wrong number of puts", 1, server.getPutCount() - numPutsPrior );
- assertEquals( "Wrong number of puts to listener.", 1, listener.putCount );
- }
- finally
- {
- // remove from all regions.
- server.removeCacheListener( listener );
- }
- }
-
- /**
- * Register a listener with the server. Send an update. Verify that the listener received it.
- * @throws Exception
- */
- public void testPutaMultipleAndListen()
- throws Exception
- {
- // SETUP
- CompositeCacheManagerMockImpl compositeCacheManager = new CompositeCacheManagerMockImpl();
-
- RemoteCacheAttributes attributes = new RemoteCacheAttributes();
- attributes.setRemoteHost( "localhost" );
- attributes.setLocalPort( 1202 );
- attributes.setRemotePort( 1101 );
-
- RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes, compositeCacheManager );
- String regionName = "testPutAndListen";
- AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
-
- RemoteCacheListenerMockImpl listener = new RemoteCacheListenerMockImpl();
- server.addCacheListener( regionName, listener );
-
- // DO WORK
- int numPutsPrior = server.getPutCount();
- int numToPut = 100;
- for ( int i = 0; i < numToPut; i++ )
- {
- ICacheElement element = new CacheElement( regionName, "key" + 1, "value" + i );
- cache.update( element );
- }
- SleepUtil.sleepAtLeast( 500 );
-
- // VERIFY
- System.out.println( server.getStats() );
- assertEquals( "Wrong number of puts", numToPut, server.getPutCount() - numPutsPrior );
- assertEquals( "Wrong number of puts to listener.", numToPut, listener.putCount );
- }
-}
+package org.apache.jcs.auxiliary.remote.server;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.auxiliary.AuxiliaryCache;
+import org.apache.jcs.auxiliary.remote.RemoteCacheAttributes;
+import org.apache.jcs.auxiliary.remote.RemoteCacheListenerMockImpl;
+import org.apache.jcs.auxiliary.remote.RemoteCacheManager;
+import org.apache.jcs.engine.CacheElement;
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.control.CompositeCacheManagerMockImpl;
+import org.apache.jcs.utils.timing.SleepUtil;
+
+/**
+ * These tests startup the remote server and make requests to it.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class BasicRemoteCacheClientServerUnitTest
+ extends TestCase
+{
+ RemoteCacheServer server = null;
+
+ /**
+ * Starts the server. This is not in a setup, since the server is slow to kill right now.
+ */
+ public BasicRemoteCacheClientServerUnitTest()
+ {
+ String configFile = "TestRemoteCacheClientServer.ccf";
+ server = RemoteCacheServerStartupUtil.startServerUsingProperties( configFile );
+ }
+
+ /**
+ * Verify that we can start the remote cache server. Send an item to the remote. Verify that the
+ * remote put count goes up. If we go through JCS, the manager will be shared and we will get
+ * into an endless loop. We will use a mock cache manager instead.
+ * <p>
+ * The remote server uses the real JCS. We can verify that items are added to JCS behind the
+ * server by calling get. We cannot access it directly via JCS since it is serialized.
+ * <p>
+ * This test uses a mock injected client to test a normal server.
+ * <p>
+ * @throws Exception
+ */
+ public void testSinglePut()
+ throws Exception
+ {
+ // SETUP
+ CompositeCacheManagerMockImpl compositeCacheManager = new CompositeCacheManagerMockImpl();
+
+ RemoteCacheAttributes attributes = new RemoteCacheAttributes();
+ attributes.setRemoteHost( "localhost" );
+ attributes.setLocalPort( 1202 );
+ attributes.setRemotePort( 1101 );
+
+ RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes, compositeCacheManager );
+ String regionName = "testSinglePut";
+ AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
+
+ // DO WORK
+ int numPutsPrior = server.getPutCount();
+ ICacheElement element = new CacheElement( regionName, "key", "value" );
+ cache.update( element );
+ SleepUtil.sleepAtLeast( 50 );
+
+ // VERIFY
+ System.out.println( server.getStats() );
+ assertEquals( "Wrong number of puts", 1, server.getPutCount() - numPutsPrior );
+
+ // DO WORK
+ ICacheElement result = cache.get( "key" );
+
+ // VERIFY
+ assertEquals( "Wrong element.", element.getVal(), result.getVal() );
+ }
+
+ /**
+ * Verify that we can remove an item via the remote server.
+ * <p>
+ * @throws Exception
+ */
+ public void testPutRemove()
+ throws Exception
+ {
+ // SETUP
+ CompositeCacheManagerMockImpl compositeCacheManager = new CompositeCacheManagerMockImpl();
+
+ RemoteCacheAttributes attributes = new RemoteCacheAttributes();
+ attributes.setRemoteHost( "localhost" );
+ attributes.setLocalPort( 1202 );
+ attributes.setRemotePort( 1101 );
+
+ RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes, compositeCacheManager );
+ String regionName = "testPutRemove";
+ AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
+
+ // DO WORK
+ int numPutsPrior = server.getPutCount();
+ ICacheElement element = new CacheElement( regionName, "key", "value" );
+ cache.update( element );
+ SleepUtil.sleepAtLeast( 50 );
+
+ // VERIFY
+ System.out.println( server.getStats() );
+ assertEquals( "Wrong number of puts", 1, server.getPutCount() - numPutsPrior );
+
+ // DO WORK
+ ICacheElement result = cache.get( "key" );
+
+ // VERIFY
+ assertEquals( "Wrong element.", element.getVal(), result.getVal() );
+
+ // DO WORK
+ cache.remove( "key" );
+ SleepUtil.sleepAtLeast( 50 );
+ ICacheElement resultAfterRemote = cache.get( "key" );
+
+ // VERIFY
+ assertNull( "Element resultAfterRemote should be null.", resultAfterRemote );
+ }
+
+ /**
+ * Register a listener with the server. Send an update. Verify that the listener received it.
+ * @throws Exception
+ */
+ public void testPutAndListen()
+ throws Exception
+ {
+ // SETUP
+ CompositeCacheManagerMockImpl compositeCacheManager = new CompositeCacheManagerMockImpl();
+
+ RemoteCacheAttributes attributes = new RemoteCacheAttributes();
+ attributes.setRemoteHost( "localhost" );
+ attributes.setLocalPort( 1202 );
+ attributes.setRemotePort( 1101 );
+
+ RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes, compositeCacheManager );
+ String regionName = "testPutAndListen";
+ AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
+
+ RemoteCacheListenerMockImpl listener = new RemoteCacheListenerMockImpl();
+ server.addCacheListener( regionName, listener );
+
+ // DO WORK
+ int numPutsPrior = server.getPutCount();
+ ICacheElement element = new CacheElement( regionName, "key", "value" );
+ cache.update( element );
+ SleepUtil.sleepAtLeast( 50 );
+
+ // VERIFY
+ try
+ {
+ System.out.println( server.getStats() );
+ assertEquals( "Wrong number of puts", 1, server.getPutCount() - numPutsPrior );
+ assertEquals( "Wrong number of puts to listener.", 1, listener.putCount );
+ }
+ finally
+ {
+ // remove from all regions.
+ server.removeCacheListener( listener );
+ }
+ }
+
+ /**
+ * Register a listener with the server. Send an update. Verify that the listener received it.
+ * @throws Exception
+ */
+ public void testPutaMultipleAndListen()
+ throws Exception
+ {
+ // SETUP
+ CompositeCacheManagerMockImpl compositeCacheManager = new CompositeCacheManagerMockImpl();
+
+ RemoteCacheAttributes attributes = new RemoteCacheAttributes();
+ attributes.setRemoteHost( "localhost" );
+ attributes.setLocalPort( 1202 );
+ attributes.setRemotePort( 1101 );
+
+ RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes, compositeCacheManager );
+ String regionName = "testPutAndListen";
+ AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
+
+ RemoteCacheListenerMockImpl listener = new RemoteCacheListenerMockImpl();
+ server.addCacheListener( regionName, listener );
+
+ // DO WORK
+ int numPutsPrior = server.getPutCount();
+ int numToPut = 100;
+ for ( int i = 0; i < numToPut; i++ )
+ {
+ ICacheElement element = new CacheElement( regionName, "key" + 1, "value" + i );
+ cache.update( element );
+ }
+ SleepUtil.sleepAtLeast( 500 );
+
+ // VERIFY
+ System.out.println( server.getStats() );
+ assertEquals( "Wrong number of puts", numToPut, server.getPutCount() - numPutsPrior );
+ assertEquals( "Wrong number of puts to listener.", numToPut, listener.putCount );
+ }
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerAttributesUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerAttributesUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerAttributesUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerAttributesUnitTest.java Thu May 10 09:03:42 2007
@@ -1,55 +1,65 @@
-package org.apache.jcs.auxiliary.remote.server;
-
-/*
- * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache License, Version
- * 2.0 (the "License") you may not use this file except in compliance with the License. You may
- * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
- * applicable law or agreed to in writing, software distributed under the License is distributed on
- * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
- * the License for the specific language governing permissions and limitations under the License.
- */
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.auxiliary.remote.server.behavior.IRemoteCacheServerAttributes;
-
-/**
- * Tests for the remote cache server attributes.
- * <p>
- * @author Aaron Smuts
- */
-public class RemoteCacheServerAttributesUnitTest
- extends TestCase
-{
-
- /**
- * Verify that we get a string, even if not attributes are set.
- */
- public void testToString()
- {
- RemoteCacheServerAttributes attributes = new RemoteCacheServerAttributes();
- assertNotNull( "Should have a string.", attributes.toString() );
- }
-
- /**
- * Verify that the type is set correctly and that the correct name is returned for the type.
- */
- public void testSetRemoteTypeName_local()
- {
- RemoteCacheServerAttributes attributes = new RemoteCacheServerAttributes();
- attributes.setRemoteTypeName( "LOCAL" );
- assertEquals( "Wrong type.", IRemoteCacheServerAttributes.LOCAL, attributes.getRemoteType() );
- assertEquals( "Wrong name", "LOCAL", attributes.getRemoteTypeName() );
- }
-
- /**
- * Verify that the type is set correctly and that the correct name is returned for the type.
- */
- public void testSetRemoteTypeName_cluster()
- {
- RemoteCacheServerAttributes attributes = new RemoteCacheServerAttributes();
- attributes.setRemoteTypeName( "CLUSTER" );
- assertEquals( "Wrong type.", IRemoteCacheServerAttributes.CLUSTER, attributes.getRemoteType() );
- assertEquals( "Wrong name", "CLUSTER", attributes.getRemoteTypeName() );
- }
-}
+package org.apache.jcs.auxiliary.remote.server;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.auxiliary.remote.server.behavior.IRemoteCacheServerAttributes;
+
+/**
+ * Tests for the remote cache server attributes.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class RemoteCacheServerAttributesUnitTest
+ extends TestCase
+{
+
+ /**
+ * Verify that we get a string, even if not attributes are set.
+ */
+ public void testToString()
+ {
+ RemoteCacheServerAttributes attributes = new RemoteCacheServerAttributes();
+ assertNotNull( "Should have a string.", attributes.toString() );
+ }
+
+ /**
+ * Verify that the type is set correctly and that the correct name is returned for the type.
+ */
+ public void testSetRemoteTypeName_local()
+ {
+ RemoteCacheServerAttributes attributes = new RemoteCacheServerAttributes();
+ attributes.setRemoteTypeName( "LOCAL" );
+ assertEquals( "Wrong type.", IRemoteCacheServerAttributes.LOCAL, attributes.getRemoteType() );
+ assertEquals( "Wrong name", "LOCAL", attributes.getRemoteTypeName() );
+ }
+
+ /**
+ * Verify that the type is set correctly and that the correct name is returned for the type.
+ */
+ public void testSetRemoteTypeName_cluster()
+ {
+ RemoteCacheServerAttributes attributes = new RemoteCacheServerAttributes();
+ attributes.setRemoteTypeName( "CLUSTER" );
+ assertEquals( "Wrong type.", IRemoteCacheServerAttributes.CLUSTER, attributes.getRemoteType() );
+ assertEquals( "Wrong name", "CLUSTER", attributes.getRemoteTypeName() );
+ }
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerStartupUtil.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerStartupUtil.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerStartupUtil.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerStartupUtil.java Thu May 10 09:03:42 2007
@@ -1,126 +1,136 @@
-package org.apache.jcs.auxiliary.remote.server;
-
-/*
- * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache License, Version
- * 2.0 (the "License") you may not use this file except in compliance with the License. You may
- * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
- * applicable law or agreed to in writing, software distributed under the License is distributed on
- * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
- * the License for the specific language governing permissions and limitations under the License.
- */
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.rmi.RemoteException;
-import java.rmi.registry.LocateRegistry;
-import java.util.Properties;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jcs.utils.props.PropertyLoader;
-
-/**
- *Starts the registry and runs the server via the factory.
- *<p>
- * @author Aaron Smuts
- *
- */
-public class RemoteCacheServerStartupUtil
-{
- private final static Log log = LogFactory.getLog( RemoteCacheServerStartupUtil.class );
-
- private static final int DEFAULT_REGISTRY_PORT = 1101;
-
-
- /**
- * Starts the registry on port "registry.port"
- * <p>
- * @param propsFileName
- * @return RemoteCacheServer
- */
- public static RemoteCacheServer startServerUsingProperties( String propsFileName )
- {
- // TODO load from props file or get as init param or get from jndi, or
- // all three
- int registryPort = DEFAULT_REGISTRY_PORT;
-
- try
- {
- Properties props = PropertyLoader.loadProperties( propsFileName );
- if ( props != null )
- {
- String portS = props.getProperty( "registry.port", String.valueOf( DEFAULT_REGISTRY_PORT ) );
-
- try
- {
- registryPort = Integer.parseInt( portS );
- }
- catch ( NumberFormatException e )
- {
- log.error( "Problem converting port to an int.", e );
- }
- }
- }
- catch ( Exception e )
- {
- log.error( "Problem loading props.", e );
- }
- catch ( Throwable t )
- {
- log.error( "Problem loading props.", t );
- }
-
- // we will always use the local machine for the registry
- String registryHost;
- try
- {
- registryHost = InetAddress.getLocalHost().getHostAddress();
-
- if ( log.isDebugEnabled() )
- {
- log.debug( "registryHost = [" + registryHost + "]" );
- }
-
- if ( "localhost".equals( registryHost ) || "127.0.0.1".equals( registryHost ) )
- {
- log.warn( "The local address [" + registryHost
- + "] is INVALID. Other machines must be able to use the address to reach this server." );
- }
-
- try
- {
- LocateRegistry.createRegistry( registryPort );
- }
- catch ( RemoteException e )
- {
- log.error( "Problem creating registry. It may already be started. " + e.getMessage() );
- }
- catch ( Throwable t )
- {
- log.error( "Problem creating registry.", t );
- }
-
- try
- {
- RemoteCacheServerFactory.startup( registryHost, registryPort, "/" + propsFileName );
- }
- catch ( IOException e )
- {
- log.error( "Problem starting remote cache server.", e );
- }
-
- catch ( Throwable t )
- {
- log.error( "Problem starting remote cache server.", t );
- }
- }
- catch ( UnknownHostException e )
- {
- log.error( "Could not get local address to use for the registry!", e );
- }
-
- return RemoteCacheServerFactory.getRemoteCacheServer();
- }
-
-}
+package org.apache.jcs.auxiliary.remote.server;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.utils.props.PropertyLoader;
+
+/**
+ *Starts the registry and runs the server via the factory.
+ *<p>
+ * @author Aaron Smuts
+ *
+ */
+public class RemoteCacheServerStartupUtil
+{
+ private final static Log log = LogFactory.getLog( RemoteCacheServerStartupUtil.class );
+
+ private static final int DEFAULT_REGISTRY_PORT = 1101;
+
+
+ /**
+ * Starts the registry on port "registry.port"
+ * <p>
+ * @param propsFileName
+ * @return RemoteCacheServer
+ */
+ public static RemoteCacheServer startServerUsingProperties( String propsFileName )
+ {
+ // TODO load from props file or get as init param or get from jndi, or
+ // all three
+ int registryPort = DEFAULT_REGISTRY_PORT;
+
+ try
+ {
+ Properties props = PropertyLoader.loadProperties( propsFileName );
+ if ( props != null )
+ {
+ String portS = props.getProperty( "registry.port", String.valueOf( DEFAULT_REGISTRY_PORT ) );
+
+ try
+ {
+ registryPort = Integer.parseInt( portS );
+ }
+ catch ( NumberFormatException e )
+ {
+ log.error( "Problem converting port to an int.", e );
+ }
+ }
+ }
+ catch ( Exception e )
+ {
+ log.error( "Problem loading props.", e );
+ }
+ catch ( Throwable t )
+ {
+ log.error( "Problem loading props.", t );
+ }
+
+ // we will always use the local machine for the registry
+ String registryHost;
+ try
+ {
+ registryHost = InetAddress.getLocalHost().getHostAddress();
+
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "registryHost = [" + registryHost + "]" );
+ }
+
+ if ( "localhost".equals( registryHost ) || "127.0.0.1".equals( registryHost ) )
+ {
+ log.warn( "The local address [" + registryHost
+ + "] is INVALID. Other machines must be able to use the address to reach this server." );
+ }
+
+ try
+ {
+ LocateRegistry.createRegistry( registryPort );
+ }
+ catch ( RemoteException e )
+ {
+ log.error( "Problem creating registry. It may already be started. " + e.getMessage() );
+ }
+ catch ( Throwable t )
+ {
+ log.error( "Problem creating registry.", t );
+ }
+
+ try
+ {
+ RemoteCacheServerFactory.startup( registryHost, registryPort, "/" + propsFileName );
+ }
+ catch ( IOException e )
+ {
+ log.error( "Problem starting remote cache server.", e );
+ }
+
+ catch ( Throwable t )
+ {
+ log.error( "Problem starting remote cache server.", t );
+ }
+ }
+ catch ( UnknownHostException e )
+ {
+ log.error( "Could not get local address to use for the registry!", e );
+ }
+
+ return RemoteCacheServerFactory.getRemoteCacheServer();
+ }
+
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.