svn commit: r726149 [3/3] - in /jakarta/jcs/trunk: ./ src/conf/ src/java/org/apache/jcs/auxiliary/remote/ src/java/org/apache/jcs/auxiliary/remote/behavior/ src/java/org/apache/jcs/auxiliary/remote/http/behavior/ src/java/org/apache/jcs/auxiliary/remot...
[email protected] Fri, 12 Dec 2008 23:37:23 -0000
| Newsgroups | gmane.comp.jakarta.turbine.jcs.devel |
|---|---|
| Message-ID | <[email protected]> |
Added: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheMonitor.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheMonitor.java?rev=726149&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheMonitor.java (added)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheMonitor.java Fri Dec 12 15:37:22 2008
@@ -0,0 +1,250 @@
+package org.apache.jcs.auxiliary.remote.http.client;
+
+/*
+ * 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.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.engine.CacheConstants;
+
+/**
+ * Used to monitor and repair any failed connection for the remote cache service. By default the
+ * monitor operates in a failure driven mode. That is, it goes into a wait state until there is an
+ * error. TODO consider moving this into an active monitoring mode. Upon the notification of a
+ * connection error, the monitor changes to operate in a time driven mode. That is, it attempts to
+ * recover the connections on a periodic basis. When all failed connections are restored, it changes
+ * back to the failure driven mode.
+ * <p>
+ * This simply pings the service until it works.
+ */
+public class RemoteHttpCacheMonitor
+ implements Runnable
+{
+ /** The logger */
+ private final static Log log = LogFactory.getLog( RemoteHttpCacheMonitor.class );
+
+ /** The remote cache that we are monitoring */
+ private static RemoteHttpCacheMonitor instance;
+
+ /** Time between checks */
+ private static long idlePeriod = 3 * 1000;
+
+ /** Set of remote caches to monitor. This are added on error, if not before. */
+ private Set remoteHttpCaches = new HashSet();
+
+ /**
+ * Must make sure RemoteCacheMonitor is started before any remote error can be detected!
+ */
+ private boolean alright = true;
+
+ /** Time driven mode */
+ final static int TIME = 0;
+
+ /** Error driven mode -- only check on health if there is an error */
+ final static int ERROR = 1;
+
+ /** The mode to use */
+ static int mode = ERROR;
+
+ /**
+ * Configures the idle period between repairs.
+ * <p>
+ * @param idlePeriod The new idlePeriod value
+ */
+ public static void setIdlePeriod( long idlePeriod )
+ {
+ if ( idlePeriod > RemoteHttpCacheMonitor.idlePeriod )
+ {
+ RemoteHttpCacheMonitor.idlePeriod = idlePeriod;
+ }
+ }
+
+ /** Constructor for the RemoteCacheMonitor object */
+ private RemoteHttpCacheMonitor()
+ {
+ super();
+ }
+
+ /**
+ * Returns the singleton instance.
+ * <p>
+ * @return The instance value
+ */
+ static RemoteHttpCacheMonitor getInstance()
+ {
+ synchronized ( RemoteHttpCacheMonitor.class )
+ {
+ if ( instance == null )
+ {
+ return instance = new RemoteHttpCacheMonitor();
+ }
+ }
+ return instance;
+ }
+
+ /**
+ * Notifies the cache monitor that an error occurred, and kicks off the error recovery process.
+ * <p>
+ * @param remoteCache
+ */
+ public void notifyError( RemoteHttpCache remoteCache )
+ {
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "Notified of an error. " + remoteCache );
+ }
+ bad();
+ synchronized ( this )
+ {
+ remoteHttpCaches.add( remoteCache );
+ notify();
+ }
+ }
+
+ // Run forever.
+
+ // Avoid the use of any synchronization in the process of monitoring for
+ // performance reason.
+ // If exception is thrown owing to synchronization,
+ // just skip the monitoring until the next round.
+ /** Main processing method for the RemoteCacheMonitor object */
+ public void run()
+ {
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "Monitoring daemon started" );
+ }
+ do
+ {
+ if ( mode == ERROR )
+ {
+ synchronized ( this )
+ {
+ if ( alright )
+ {
+ // make this configurable, comment out wait to enter
+ // time driven mode
+ // Failure driven mode.
+ try
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "FAILURE DRIVEN MODE: cache monitor waiting for error" );
+ }
+ wait();
+ // wake up only if there is an error.
+ }
+ catch ( InterruptedException ignore )
+ {
+ // swallow
+ }
+ }
+ }
+ }
+ else
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "TIME DRIVEN MODE: cache monitor sleeping for " + idlePeriod );
+ }
+ // Time driven mode: sleep between each round of recovery
+ // attempt.
+ // will need to test not just check status
+ }
+
+ try
+ {
+ Thread.sleep( idlePeriod );
+ }
+ catch ( InterruptedException ex )
+ {
+ // ignore;
+ }
+
+ // The "alright" flag must be false here.
+ // Simply presume we can fix all the errors until proven otherwise.
+ synchronized ( this )
+ {
+ alright = true;
+ }
+
+ // Make a copy
+ Set remoteCachesToExamine = new HashSet();
+ synchronized ( this )
+ {
+ remoteCachesToExamine.addAll( this.remoteHttpCaches );
+ }
+ // If any cache is in error, it strongly suggests all caches
+ // managed by the
+ // same RmicCacheManager instance are in error. So we fix
+ // them once and for all.
+ Iterator itr2 = remoteCachesToExamine.iterator();
+ while ( itr2.hasNext() )
+ {
+ try
+ {
+ RemoteHttpCache remoteCache = (RemoteHttpCache) itr2.next();
+
+ if ( remoteCache.getStatus() == CacheConstants.STATUS_ERROR )
+ {
+ RemoteHttpCacheAttributes attributes = remoteCache.getRemoteHttpCacheAttributes();
+
+ RemoteHttpCacheClient remoteService = RemoteHttpCacheManager.getInstance()
+ .createRemoteHttpCacheClientForAttributes( attributes );
+
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "Performing Alive check on service " + remoteService );
+ }
+ // If we can't fix them, just skip and re-try in
+ // the next round.
+ if ( remoteService.isAlive() )
+ {
+ remoteCache.fixCache( remoteService );
+ }
+ else
+ {
+ bad();
+ }
+ break;
+ }
+ }
+ catch ( Exception ex )
+ {
+ bad();
+ // Problem encountered in fixing the caches managed by a
+ // RemoteCacheManager instance.
+ // Soldier on to the next RemoteHttpCache.
+ log.error( ex );
+ }
+ }
+ }
+ while ( true );
+ }
+
+ /** Sets the "aright" flag to false in a critical section. */
+ private synchronized void bad()
+ {
+ alright = false;
+ }
+}
Added: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpClientListener.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpClientListener.java?rev=726149&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpClientListener.java (added)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpClientListener.java Fri Dec 12 15:37:22 2008
@@ -0,0 +1,30 @@
+package org.apache.jcs.auxiliary.remote.http.client;
+
+import org.apache.jcs.auxiliary.remote.AbsractRemoteCacheListener;
+import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
+import org.apache.jcs.engine.behavior.ICompositeCacheManager;
+
+/** Does nothing */
+public class RemoteHttpClientListener
+ extends AbsractRemoteCacheListener
+{
+ /**
+ * Only need one since it does work for all regions, just reference by multiple region names.
+ * <p>
+ * The constructor exports this object, making it available to receive incoming calls. The
+ * callback port is anonymous unless a local port value was specified in the configuration.
+ * <p>
+ * @param irca
+ * @param cacheMgr
+ */
+ public RemoteHttpClientListener( IRemoteCacheAttributes irca, ICompositeCacheManager cacheMgr )
+ {
+ super( irca, cacheMgr );
+ }
+
+ /** Nothing */
+ public void dispose()
+ {
+ // noop
+ }
+}
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptor.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptor.java?rev=726149&r1=726148&r2=726149&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptor.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptor.java Fri Dec 12 15:37:22 2008
@@ -5,9 +5,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService;
-import org.apache.jcs.auxiliary.remote.http.behavior.IRemoteHttpCacheConstants;
-import org.apache.jcs.auxiliary.remote.http.value.RemoteHttpCacheRequest;
-import org.apache.jcs.auxiliary.remote.http.value.RemoteHttpCacheResponse;
+import org.apache.jcs.auxiliary.remote.value.RemoteCacheRequest;
+import org.apache.jcs.auxiliary.remote.value.RemoteCacheResponse;
import org.apache.jcs.engine.behavior.ICacheElement;
import org.apache.jcs.engine.control.CompositeCacheManager;
@@ -24,13 +23,13 @@
/** The service that does the work. */
private IRemoteCacheService remoteCacheService;
-
+
/** This is for testing without the factory. */
protected RemoteCacheServiceAdaptor()
{
// for testing.
}
-
+
/**
* Create a process with a cache manager.
* <p>
@@ -47,9 +46,9 @@
* @param request
* @return RemoteHttpCacheResponse, never null
*/
- public RemoteHttpCacheResponse processRequest( RemoteHttpCacheRequest request )
+ public RemoteCacheResponse processRequest( RemoteCacheRequest request )
{
- RemoteHttpCacheResponse response = new RemoteHttpCacheResponse();
+ RemoteCacheResponse response = new RemoteCacheResponse();
if ( request == null )
{
@@ -64,43 +63,45 @@
{
switch ( request.getRequestType() )
{
- case IRemoteHttpCacheConstants.REQUEST_TYPE_GET:
- ICacheElement element = getRemoteCacheService().get( request.getCacheName(),
- request.getKey(),
- request.getRequesterId() );
+ case RemoteCacheRequest.REQUEST_TYPE_GET:
+ ICacheElement element = getRemoteCacheService().get( request.getCacheName(), request.getKey(),
+ request.getRequesterId() );
if ( element != null )
{
response.getPayload().put( element.getKey(), element );
}
break;
- case IRemoteHttpCacheConstants.REQUEST_TYPE_GET_MULTIPLE:
+ case RemoteCacheRequest.REQUEST_TYPE_GET_MULTIPLE:
Map elementMap = getRemoteCacheService().getMultiple( request.getCacheName(),
- request.getKeySet(),
- request.getRequesterId() );
+ request.getKeySet(),
+ request.getRequesterId() );
if ( elementMap != null )
{
response.getPayload().putAll( elementMap );
}
break;
- case IRemoteHttpCacheConstants.REQUEST_TYPE_GET_MATCHING:
+ case RemoteCacheRequest.REQUEST_TYPE_GET_MATCHING:
Map elementMapMatching = getRemoteCacheService().getMatching( request.getCacheName(),
- request.getPattern(),
- request.getRequesterId() );
+ request.getPattern(),
+ request.getRequesterId() );
if ( elementMapMatching != null )
{
response.getPayload().putAll( elementMapMatching );
}
break;
- case IRemoteHttpCacheConstants.REQUEST_TYPE_REMOVE:
+ case RemoteCacheRequest.REQUEST_TYPE_REMOVE:
getRemoteCacheService().remove( request.getCacheName(), request.getKey(),
- request.getRequesterId() );
+ request.getRequesterId() );
break;
- case IRemoteHttpCacheConstants.REQUEST_TYPE_REMOVE_ALL:
+ case RemoteCacheRequest.REQUEST_TYPE_REMOVE_ALL:
getRemoteCacheService().removeAll( request.getCacheName(), request.getRequesterId() );
break;
- case IRemoteHttpCacheConstants.REQUEST_TYPE_UPDATE:
+ case RemoteCacheRequest.REQUEST_TYPE_UPDATE:
getRemoteCacheService().update( request.getCacheElement(), request.getRequesterId() );
break;
+ case RemoteCacheRequest.REQUEST_TYPE_ALIVE_CHECK:
+ response.setSuccess( true );
+ break;
default:
String message = "Unknown event type. Cannot process " + request;
log.warn( message );
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteHttpCacheServlet.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteHttpCacheServlet.java?rev=726149&r1=726148&r2=726149&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteHttpCacheServlet.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteHttpCacheServlet.java Fri Dec 12 15:37:22 2008
@@ -20,8 +20,9 @@
*/
import java.io.IOException;
+import java.io.InputStream;
import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.OutputStream;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
@@ -31,9 +32,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.jcs.auxiliary.remote.http.value.RemoteHttpCacheRequest;
-import org.apache.jcs.auxiliary.remote.http.value.RemoteHttpCacheResponse;
+import org.apache.jcs.auxiliary.remote.value.RemoteCacheRequest;
+import org.apache.jcs.auxiliary.remote.value.RemoteCacheResponse;
import org.apache.jcs.engine.control.CompositeCacheManager;
+import org.apache.jcs.utils.serialization.StandardSerializer;
/**
* This servlet simply reads and writes objects. The requests are packaged in a general wrapper. The
@@ -54,6 +56,9 @@
/** Processes requests */
private RemoteCacheServiceAdaptor remoteHttpCacheServiceAdaptor;
+ /** This needs to be standard, since the other side is standard */
+ private StandardSerializer serializer = new StandardSerializer();
+
/**
* Initializes the cache.
* <p>
@@ -88,9 +93,9 @@
log.debug( "Servicing a request." );
}
- RemoteHttpCacheRequest remoteRequest = readRequest( request );
+ RemoteCacheRequest remoteRequest = readRequest( request );
- RemoteHttpCacheResponse cacheResponse = getRemoteHttpCacheServiceAdaptor().processRequest( remoteRequest );
+ RemoteCacheResponse cacheResponse = getRemoteHttpCacheServiceAdaptor().processRequest( remoteRequest );
writeResponse( response, cacheResponse );
}
@@ -101,20 +106,18 @@
* @param request
* @return RemoteHttpCacheRequest
*/
- protected RemoteHttpCacheRequest readRequest( HttpServletRequest request )
+ protected RemoteCacheRequest readRequest( HttpServletRequest request )
{
- RemoteHttpCacheRequest remoteRequest = null;
+ RemoteCacheRequest remoteRequest = null;
try
{
- ObjectInputStream ois = new ObjectInputStream( request.getInputStream() );
-
+ InputStream inputStream = request.getInputStream();
if ( log.isDebugEnabled() )
{
log.debug( "after getting input stream and before reading it" );
}
- remoteRequest = (RemoteHttpCacheRequest) ois.readObject();
- ois.close();
+ remoteRequest = readRequestFromStream( inputStream );
}
catch ( Exception e )
{
@@ -124,28 +127,48 @@
}
/**
+ * Reads the response from the stream and then closes it.
+ * <p>
+ * @param inputStream
+ * @return RemoteHttpCacheRequest
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ protected RemoteCacheRequest readRequestFromStream( InputStream inputStream )
+ throws IOException, ClassNotFoundException
+ {
+ RemoteCacheRequest remoteRequest;
+ ObjectInputStream ois = new ObjectInputStream( inputStream );
+
+ remoteRequest = (RemoteCacheRequest) ois.readObject();
+ ois.close();
+ return remoteRequest;
+ }
+
+ /**
* Write the response to the output stream.
* <p>
* @param response
* @param cacheResponse
*/
- protected void writeResponse( HttpServletResponse response, RemoteHttpCacheResponse cacheResponse )
+ protected void writeResponse( HttpServletResponse response, RemoteCacheResponse cacheResponse )
{
try
{
response.setContentType( "application/octet-stream" );
- ObjectOutputStream oos = new ObjectOutputStream( response.getOutputStream() );
+ byte[] responseAsByteAray = serializer.serialize( cacheResponse );
+ response.setContentLength( responseAsByteAray.length );
+ OutputStream outputStream = response.getOutputStream();
if ( log.isDebugEnabled() )
{
- log.debug( "Opened output stream." );
+ log.debug( "Opened output stream. Response size: " + responseAsByteAray.length );
}
-
// WRITE
- oos.writeObject( cacheResponse );
- oos.flush();
- oos.close();
+ outputStream.write( responseAsByteAray );
+ outputStream.flush();
+ outputStream.close();
}
catch ( Exception e )
{
Copied: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java (from r724518, jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpClientRequestFactory.java)
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java?p2=jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java&p1=jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpClientRequestFactory.java&r1=724518&r2=726149&rev=726149&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpClientRequestFactory.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java Fri Dec 12 15:37:22 2008
@@ -1,22 +1,21 @@
-package org.apache.jcs.auxiliary.remote.http.client;
+package org.apache.jcs.auxiliary.remote.util;
import java.io.Serializable;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.jcs.auxiliary.remote.http.behavior.IRemoteHttpCacheConstants;
-import org.apache.jcs.auxiliary.remote.http.value.RemoteHttpCacheRequest;
+import org.apache.jcs.auxiliary.remote.value.RemoteCacheRequest;
import org.apache.jcs.engine.behavior.ICacheElement;
/**
* This creates request objects. You could write your own client and use the objects from this
* factory.
*/
-public class RemoteHttpClientRequestFactory
+public class RemoteCacheRequestFactory
{
/** The Logger. */
- private final static Log log = LogFactory.getLog( RemoteHttpClientRequestFactory.class );
+ private final static Log log = LogFactory.getLog( RemoteCacheRequestFactory.class );
/**
* Creates a get Request.
@@ -26,13 +25,13 @@
* @param requesterId
* @return RemoteHttpCacheRequest
*/
- public static RemoteHttpCacheRequest createGetRequest( String cacheName, Serializable key, long requesterId )
+ public static RemoteCacheRequest createGetRequest( String cacheName, Serializable key, long requesterId )
{
- RemoteHttpCacheRequest request = new RemoteHttpCacheRequest();
+ RemoteCacheRequest request = new RemoteCacheRequest();
request.setCacheName( cacheName );
request.setKey( key );
request.setRequesterId( requesterId );
- request.setRequestType( IRemoteHttpCacheConstants.REQUEST_TYPE_GET );
+ request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_GET );
if ( log.isDebugEnabled() )
{
@@ -41,7 +40,7 @@
return request;
}
-
+
/**
* Creates a getMatching Request.
* <p>
@@ -50,13 +49,13 @@
* @param requesterId
* @return RemoteHttpCacheRequest
*/
- public static RemoteHttpCacheRequest createGetMatchingRequest( String cacheName, String pattern, long requesterId )
+ public static RemoteCacheRequest createGetMatchingRequest( String cacheName, String pattern, long requesterId )
{
- RemoteHttpCacheRequest request = new RemoteHttpCacheRequest();
+ RemoteCacheRequest request = new RemoteCacheRequest();
request.setCacheName( cacheName );
request.setPattern( pattern );
request.setRequesterId( requesterId );
- request.setRequestType( IRemoteHttpCacheConstants.REQUEST_TYPE_GET_MATCHING );
+ request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_GET_MATCHING );
if ( log.isDebugEnabled() )
{
@@ -65,7 +64,7 @@
return request;
}
-
+
/**
* Creates a getMultiple Request.
* <p>
@@ -74,13 +73,13 @@
* @param requesterId
* @return RemoteHttpCacheRequest
*/
- public static RemoteHttpCacheRequest createGetMultipleRequest( String cacheName, Set keys, long requesterId )
+ public static RemoteCacheRequest createGetMultipleRequest( String cacheName, Set keys, long requesterId )
{
- RemoteHttpCacheRequest request = new RemoteHttpCacheRequest();
+ RemoteCacheRequest request = new RemoteCacheRequest();
request.setCacheName( cacheName );
request.setKeySet( keys );
request.setRequesterId( requesterId );
- request.setRequestType( IRemoteHttpCacheConstants.REQUEST_TYPE_GET_MULTIPLE );
+ request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_GET_MULTIPLE );
if ( log.isDebugEnabled() )
{
@@ -89,7 +88,7 @@
return request;
}
-
+
/**
* Creates a remove Request.
* <p>
@@ -98,13 +97,13 @@
* @param requesterId
* @return RemoteHttpCacheRequest
*/
- public static RemoteHttpCacheRequest createRemoveRequest( String cacheName, Serializable key, long requesterId )
+ public static RemoteCacheRequest createRemoveRequest( String cacheName, Serializable key, long requesterId )
{
- RemoteHttpCacheRequest request = new RemoteHttpCacheRequest();
+ RemoteCacheRequest request = new RemoteCacheRequest();
request.setCacheName( cacheName );
request.setKey( key );
request.setRequesterId( requesterId );
- request.setRequestType( IRemoteHttpCacheConstants.REQUEST_TYPE_REMOVE );
+ request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_REMOVE );
if ( log.isDebugEnabled() )
{
@@ -115,18 +114,64 @@
}
/**
+ * Creates a GetGroupKeys Request.
+ * <p>
+ * @param cacheName
+ * @param groupName
+ * @param requesterId
+ * @return RemoteHttpCacheRequest
+ */
+ public static RemoteCacheRequest createGetGroupKeysRequest( String cacheName, String groupName, long requesterId )
+ {
+ RemoteCacheRequest request = new RemoteCacheRequest();
+ request.setCacheName( cacheName );
+ request.setKey( groupName );
+ request.setRequesterId( requesterId );
+ request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_GET_GROUP_KEYS );
+
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Created: " + request );
+ }
+
+ return request;
+ }
+
+ /**
* Creates a removeAll Request.
* <p>
* @param cacheName
* @param requesterId
* @return RemoteHttpCacheRequest
*/
- public static RemoteHttpCacheRequest createRemoveAllRequest( String cacheName, long requesterId )
+ public static RemoteCacheRequest createRemoveAllRequest( String cacheName, long requesterId )
+ {
+ RemoteCacheRequest request = new RemoteCacheRequest();
+ request.setCacheName( cacheName );
+ request.setRequesterId( requesterId );
+ request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_REMOVE_ALL );
+
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Created: " + request );
+ }
+
+ return request;
+ }
+
+ /**
+ * Creates a dispose Request.
+ * <p>
+ * @param cacheName
+ * @param requesterId
+ * @return RemoteHttpCacheRequest
+ */
+ public static RemoteCacheRequest createDisposeRequest( String cacheName, long requesterId )
{
- RemoteHttpCacheRequest request = new RemoteHttpCacheRequest();
+ RemoteCacheRequest request = new RemoteCacheRequest();
request.setCacheName( cacheName );
request.setRequesterId( requesterId );
- request.setRequestType( IRemoteHttpCacheConstants.REQUEST_TYPE_REMOVE_ALL );
+ request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_DIPOSE );
if ( log.isDebugEnabled() )
{
@@ -143,9 +188,9 @@
* @param requesterId
* @return RemoteHttpCacheRequest
*/
- public static RemoteHttpCacheRequest createUpdateRequest( ICacheElement cacheElement, long requesterId )
+ public static RemoteCacheRequest createUpdateRequest( ICacheElement cacheElement, long requesterId )
{
- RemoteHttpCacheRequest request = new RemoteHttpCacheRequest();
+ RemoteCacheRequest request = new RemoteCacheRequest();
if ( cacheElement != null )
{
request.setCacheName( cacheElement.getCacheName() );
@@ -157,7 +202,27 @@
log.error( "Can't create a proper update request for a null cache element." );
}
request.setRequesterId( requesterId );
- request.setRequestType( IRemoteHttpCacheConstants.REQUEST_TYPE_UPDATE );
+ request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_UPDATE );
+
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Created: " + request );
+ }
+
+ return request;
+ }
+
+ /**
+ * Creates an alive check Request.
+ * <p>
+ * @param requesterId
+ * @return RemoteHttpCacheRequest
+ */
+ public static RemoteCacheRequest createAliveCheckRequest( long requesterId )
+ {
+ RemoteCacheRequest request = new RemoteCacheRequest();
+ request.setRequesterId( requesterId );
+ request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_ALIVE_CHECK );
if ( log.isDebugEnabled() )
{
Propchange: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java
------------------------------------------------------------------------------
svn:mergeinfo =
Added: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestUtil.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestUtil.java?rev=726149&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestUtil.java (added)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestUtil.java Fri Dec 12 15:37:22 2008
@@ -0,0 +1,38 @@
+package org.apache.jcs.auxiliary.remote.util;
+
+import org.apache.jcs.auxiliary.remote.value.RemoteCacheRequest;
+
+/** Utilities for the request object */
+public class RemoteCacheRequestUtil
+{
+ /**
+ * @param type
+ * @return name for the type
+ */
+ public static String getRequestTypeName( byte type )
+ {
+ switch ( type )
+ {
+ case RemoteCacheRequest.REQUEST_TYPE_ALIVE_CHECK:
+ return "AliveCheck";
+ case RemoteCacheRequest.REQUEST_TYPE_GET:
+ return "Get";
+ case RemoteCacheRequest.REQUEST_TYPE_GET_MULTIPLE:
+ return "GetMultiple";
+ case RemoteCacheRequest.REQUEST_TYPE_GET_MATCHING:
+ return "GetMatching";
+ case RemoteCacheRequest.REQUEST_TYPE_REMOVE:
+ return "Remove";
+ case RemoteCacheRequest.REQUEST_TYPE_REMOVE_ALL:
+ return "RemoveAll";
+ case RemoteCacheRequest.REQUEST_TYPE_UPDATE:
+ return "Update";
+ case RemoteCacheRequest.REQUEST_TYPE_GET_GROUP_KEYS:
+ return "GetGroupKeys";
+ case RemoteCacheRequest.REQUEST_TYPE_DIPOSE:
+ return "Dispose";
+ default:
+ return "Unknown";
+ }
+ }
+}
Copied: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheRequest.java (from r724518, jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/value/RemoteHttpCacheRequest.java)
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheRequest.java?p2=jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheRequest.java&p1=jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/value/RemoteHttpCacheRequest.java&r1=724518&r2=726149&rev=726149&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/value/RemoteHttpCacheRequest.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheRequest.java Fri Dec 12 15:37:22 2008
@@ -1,4 +1,4 @@
-package org.apache.jcs.auxiliary.remote.http.value;
+package org.apache.jcs.auxiliary.remote.value;
import java.io.Serializable;
import java.util.Set;
@@ -11,12 +11,39 @@
* Rather than creating sub object types, I created on object thsat has values for all types of
* requests.
*/
-public class RemoteHttpCacheRequest
+public class RemoteCacheRequest
implements Serializable
{
/** Don't change. */
private static final long serialVersionUID = -8858447417390442569L;
+ /** Alive check request type. */
+ public static final byte REQUEST_TYPE_ALIVE_CHECK = 0;
+
+ /** Get request type. */
+ public static final byte REQUEST_TYPE_GET = 1;
+
+ /** Get Multiple request type. */
+ public static final byte REQUEST_TYPE_GET_MULTIPLE = 2;
+
+ /** Get Matching request type. */
+ public static final byte REQUEST_TYPE_GET_MATCHING = 3;
+
+ /** Update request type. */
+ public static final byte REQUEST_TYPE_UPDATE = 4;
+
+ /** Remove request type. */
+ public static final byte REQUEST_TYPE_REMOVE = 5;
+
+ /** Remove All request type. */
+ public static final byte REQUEST_TYPE_REMOVE_ALL = 6;
+
+ /** Remove All request type. */
+ public static final byte REQUEST_TYPE_GET_GROUP_KEYS = 7;
+
+ /** Remove All request type. */
+ public static final byte REQUEST_TYPE_DIPOSE = 8;
+
/** The request type specifies the type of request: get, put, remove, . . */
private byte requestType = -1;
Propchange: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheRequest.java
------------------------------------------------------------------------------
svn:mergeinfo =
Copied: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheResponse.java (from r724518, jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/value/RemoteHttpCacheResponse.java)
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheResponse.java?p2=jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheResponse.java&p1=jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/value/RemoteHttpCacheResponse.java&r1=724518&r2=726149&rev=726149&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/value/RemoteHttpCacheResponse.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheResponse.java Fri Dec 12 15:37:22 2008
@@ -1,4 +1,4 @@
-package org.apache.jcs.auxiliary.remote.http.value;
+package org.apache.jcs.auxiliary.remote.value;
import java.io.Serializable;
import java.util.HashMap;
@@ -8,7 +8,7 @@
* This is the response wrapper. The servlet wraps all different type of responses in one of these
* objects.
*/
-public class RemoteHttpCacheResponse
+public class RemoteCacheResponse
implements Serializable
{
/** Don't change. */
Propchange: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheResponse.java
------------------------------------------------------------------------------
svn:mergeinfo =
Added: jakarta/jcs/trunk/src/test-conf/TestRemoteHttpCache.ccf
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test-conf/TestRemoteHttpCache.ccf?rev=726149&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test-conf/TestRemoteHttpCache.ccf (added)
+++ jakarta/jcs/trunk/src/test-conf/TestRemoteHttpCache.ccf Fri Dec 12 15:37:22 2008
@@ -0,0 +1,39 @@
+# 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.
+# #############################################################
+# ################# DEFAULT CACHE REGION #####################
+# sets the default aux value for any non configured caches
+jcs.default=RC
+jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
+jcs.default.cacheattributes.MaxObjects=0
+jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
+jcs.default.cacheattributes.UseMemoryShrinker=true
+jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
+jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
+jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
+jcs.default.elementattributes.IsEternal=false
+jcs.default.elementattributes.MaxLifeSeconds=700
+jcs.default.elementattributes.IdleTime=1800
+jcs.default.elementattributes.IsSpool=true
+jcs.default.elementattributes.IsRemote=true
+jcs.default.elementattributes.IsLateral=true
+
+
+## The Http Remote Cache Client
+jcs.auxiliary.RC=org.apache.jcs.auxiliary.remote.http.client.RemoteHttpCacheFactory
+jcs.auxiliary.RC.attributes=org.apache.jcs.auxiliary.remote.http.client.RemoteHttpCacheAttributes
+jcs.auxiliary.RC.attributes.url=http://localhost:8000/jcs-app/RemoteCache
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheClientTester.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheClientTester.java?rev=726149&r1=726148&r2=726149&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheClientTester.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheClientTester.java Fri Dec 12 15:37:22 2008
@@ -24,6 +24,7 @@
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
+import java.rmi.Remote;
import java.rmi.registry.Registry;
import java.rmi.server.ExportException;
import java.rmi.server.UnicastRemoteObject;
@@ -41,7 +42,7 @@
* Manual tester.
*/
public class RemoteCacheClientTester
- implements IRemoteCacheListener, IRemoteCacheConstants
+ implements IRemoteCacheListener, IRemoteCacheConstants, Remote
{
/** the observer */
protected ICacheObserver watch;
Added: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/MockRemoteCacheDispatcher.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/MockRemoteCacheDispatcher.java?rev=726149&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/MockRemoteCacheDispatcher.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/MockRemoteCacheDispatcher.java Fri Dec 12 15:37:22 2008
@@ -0,0 +1,30 @@
+package org.apache.jcs.auxiliary.remote.http.client;
+
+import java.io.IOException;
+
+import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheDispatcher;
+import org.apache.jcs.auxiliary.remote.value.RemoteCacheRequest;
+import org.apache.jcs.auxiliary.remote.value.RemoteCacheResponse;
+
+/** For testing the service. */
+public class MockRemoteCacheDispatcher
+ implements IRemoteCacheDispatcher
+{
+ /** The last request passes to dispatch */
+ public RemoteCacheRequest lastRemoteCacheRequest;
+
+ /** The response setup */
+ public RemoteCacheResponse setupRemoteCacheResponse;
+
+ /** Records the last and returns setupRemoteCacheResponse.
+ * <p>
+ * @param remoteCacheRequest
+ * @return RemoteCacheResponse
+ * @throws IOException */
+ public RemoteCacheResponse dispatchRequest( RemoteCacheRequest remoteCacheRequest )
+ throws IOException
+ {
+ this.lastRemoteCacheRequest = remoteCacheRequest;
+ return setupRemoteCacheResponse;
+ }
+}
Added: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheClientUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheClientUnitTest.java?rev=726149&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheClientUnitTest.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheClientUnitTest.java Fri Dec 12 15:37:22 2008
@@ -0,0 +1,249 @@
+package org.apache.jcs.auxiliary.remote.http.client;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.auxiliary.remote.value.RemoteCacheRequest;
+import org.apache.jcs.auxiliary.remote.value.RemoteCacheResponse;
+import org.apache.jcs.engine.CacheElement;
+import org.apache.jcs.engine.behavior.ICacheElement;
+
+/** Unit tests for the client. */
+public class RemoteHttpCacheClientUnitTest
+ extends TestCase
+{
+ /**
+ * Verify get functionality
+ * <p>
+ * @throws IOException
+ */
+ public void testGet_nullFromDispatcher()
+ throws IOException
+ {
+ // SETUP
+ RemoteHttpCacheAttributes attributes = new RemoteHttpCacheAttributes();
+ RemoteHttpCacheClient client = new RemoteHttpCacheClient( attributes );
+
+ MockRemoteCacheDispatcher mockDispatcher = new MockRemoteCacheDispatcher();
+ client.setRemoteDispatcher( mockDispatcher );
+
+ String cacheName = "test";
+ String key = "key";
+
+ mockDispatcher.setupRemoteCacheResponse = null;
+
+ // DO WORK
+ ICacheElement result = client.get( cacheName, key );
+
+ // VERIFY
+ assertNull( "Wrong result.", result );
+ assertEquals( "Wrong type.", RemoteCacheRequest.REQUEST_TYPE_GET, mockDispatcher.lastRemoteCacheRequest
+ .getRequestType() );
+ }
+
+ /**
+ * Verify get functionality
+ * <p>
+ * @throws IOException
+ */
+ public void testGet_normal()
+ throws IOException
+ {
+ // SETUP
+ RemoteHttpCacheAttributes attributes = new RemoteHttpCacheAttributes();
+ RemoteHttpCacheClient client = new RemoteHttpCacheClient( attributes );
+
+ MockRemoteCacheDispatcher mockDispatcher = new MockRemoteCacheDispatcher();
+ client.setRemoteDispatcher( mockDispatcher );
+
+ String cacheName = "test";
+ String key = "key";
+
+ ICacheElement expected = new CacheElement( cacheName, key, "value" );
+ RemoteCacheResponse remoteHttpCacheResponse = new RemoteCacheResponse();
+ remoteHttpCacheResponse.getPayload().put( key, expected );
+
+ mockDispatcher.setupRemoteCacheResponse = remoteHttpCacheResponse;
+
+ // DO WORK
+ ICacheElement result = client.get( cacheName, key );
+
+ // VERIFY
+ assertEquals( "Wrong result.", expected, result );
+ assertEquals( "Wrong type.", RemoteCacheRequest.REQUEST_TYPE_GET, mockDispatcher.lastRemoteCacheRequest
+ .getRequestType() );
+ }
+
+ /**
+ * Verify get functionality
+ * <p>
+ * @throws IOException
+ */
+ public void testGetMatching_normal()
+ throws IOException
+ {
+ // SETUP
+ RemoteHttpCacheAttributes attributes = new RemoteHttpCacheAttributes();
+ RemoteHttpCacheClient client = new RemoteHttpCacheClient( attributes );
+
+ MockRemoteCacheDispatcher mockDispatcher = new MockRemoteCacheDispatcher();
+ client.setRemoteDispatcher( mockDispatcher );
+
+ String cacheName = "test";
+ String pattern = "key";
+
+ ICacheElement expected = new CacheElement( cacheName, "key", "value" );
+ RemoteCacheResponse remoteHttpCacheResponse = new RemoteCacheResponse();
+ remoteHttpCacheResponse.getPayload().put( "key", expected );
+
+ mockDispatcher.setupRemoteCacheResponse = remoteHttpCacheResponse;
+
+ // DO WORK
+ Map result = client.getMatching( cacheName, pattern );
+
+ // VERIFY
+ assertEquals( "Wrong result.", expected, result.get( "key" ) );
+ assertEquals( "Wrong type.", RemoteCacheRequest.REQUEST_TYPE_GET_MATCHING,
+ mockDispatcher.lastRemoteCacheRequest.getRequestType() );
+ }
+
+ /**
+ * Verify get functionality
+ * <p>
+ * @throws IOException
+ */
+ public void testGetMultiple_normal()
+ throws IOException
+ {
+ // SETUP
+ RemoteHttpCacheAttributes attributes = new RemoteHttpCacheAttributes();
+ RemoteHttpCacheClient client = new RemoteHttpCacheClient( attributes );
+
+ MockRemoteCacheDispatcher mockDispatcher = new MockRemoteCacheDispatcher();
+ client.setRemoteDispatcher( mockDispatcher );
+
+ String cacheName = "test";
+ Set keys = Collections.EMPTY_SET;
+
+ ICacheElement expected = new CacheElement( cacheName, "key", "value" );
+ RemoteCacheResponse remoteHttpCacheResponse = new RemoteCacheResponse();
+ remoteHttpCacheResponse.getPayload().put( "key", expected );
+
+ mockDispatcher.setupRemoteCacheResponse = remoteHttpCacheResponse;
+
+ // DO WORK
+ Map result = client.getMultiple( cacheName, keys );
+
+ // VERIFY
+ assertEquals( "Wrong result.", expected, result.get( "key" ) );
+ assertEquals( "Wrong type.", RemoteCacheRequest.REQUEST_TYPE_GET_MULTIPLE,
+ mockDispatcher.lastRemoteCacheRequest.getRequestType() );
+ }
+
+ /**
+ * Verify remove functionality
+ * <p>
+ * @throws IOException
+ */
+ public void testRemove_normal()
+ throws IOException
+ {
+ // SETUP
+ RemoteHttpCacheAttributes attributes = new RemoteHttpCacheAttributes();
+ RemoteHttpCacheClient client = new RemoteHttpCacheClient( attributes );
+
+ MockRemoteCacheDispatcher mockDispatcher = new MockRemoteCacheDispatcher();
+ client.setRemoteDispatcher( mockDispatcher );
+
+ String cacheName = "test";
+ String key = "key";
+
+ // DO WORK
+ client.remove( cacheName, key );
+
+ // VERIFY
+ assertEquals( "Wrong type.", RemoteCacheRequest.REQUEST_TYPE_REMOVE, mockDispatcher.lastRemoteCacheRequest
+ .getRequestType() );
+ }
+
+ /**
+ * Verify removeall functionality
+ * <p>
+ * @throws IOException
+ */
+ public void testRemoveAll_normal()
+ throws IOException
+ {
+ // SETUP
+ RemoteHttpCacheAttributes attributes = new RemoteHttpCacheAttributes();
+ RemoteHttpCacheClient client = new RemoteHttpCacheClient( attributes );
+
+ MockRemoteCacheDispatcher mockDispatcher = new MockRemoteCacheDispatcher();
+ client.setRemoteDispatcher( mockDispatcher );
+
+ String cacheName = "test";
+
+ // DO WORK
+ client.removeAll( cacheName );
+
+ // VERIFY
+ assertEquals( "Wrong type.", RemoteCacheRequest.REQUEST_TYPE_REMOVE_ALL, mockDispatcher.lastRemoteCacheRequest
+ .getRequestType() );
+ }
+
+ /**
+ * Verify update functionality
+ * <p>
+ * @throws IOException
+ */
+ public void testUpdate_normal()
+ throws IOException
+ {
+ // SETUP
+ RemoteHttpCacheAttributes attributes = new RemoteHttpCacheAttributes();
+ RemoteHttpCacheClient client = new RemoteHttpCacheClient( attributes );
+
+ MockRemoteCacheDispatcher mockDispatcher = new MockRemoteCacheDispatcher();
+ client.setRemoteDispatcher( mockDispatcher );
+
+ String cacheName = "test";
+
+ ICacheElement element = new CacheElement( cacheName, "key", "value" );
+
+ // DO WORK
+ client.update( element );
+
+ // VERIFY
+ assertEquals( "Wrong type.", RemoteCacheRequest.REQUEST_TYPE_UPDATE, mockDispatcher.lastRemoteCacheRequest
+ .getRequestType() );
+ }
+
+ /**
+ * Verify dispose functionality
+ * <p>
+ * @throws IOException
+ */
+ public void testDispose_normal()
+ throws IOException
+ {
+ // SETUP
+ RemoteHttpCacheAttributes attributes = new RemoteHttpCacheAttributes();
+ RemoteHttpCacheClient client = new RemoteHttpCacheClient( attributes );
+
+ MockRemoteCacheDispatcher mockDispatcher = new MockRemoteCacheDispatcher();
+ client.setRemoteDispatcher( mockDispatcher );
+
+ String cacheName = "test";
+
+ // DO WORK
+ client.dispose( cacheName );
+
+ // VERIFY
+ assertEquals( "Wrong type.", RemoteCacheRequest.REQUEST_TYPE_DIPOSE, mockDispatcher.lastRemoteCacheRequest
+ .getRequestType() );
+ }
+}
Added: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheManualTester.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheManualTester.java?rev=726149&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheManualTester.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheManualTester.java Fri Dec 12 15:37:22 2008
@@ -0,0 +1,55 @@
+package org.apache.jcs.auxiliary.remote.http.client;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+
+/** Manual tester for a JCS instance configured to use the http client. */
+public class RemoteHttpCacheManualTester
+ extends TestCase
+{
+ /** number to use for the test */
+ private static int items = 100;
+
+ /**
+ * Test setup
+ */
+ public void setUp()
+ {
+ JCS.setConfigFilename( "/TestRemoteHttpCache.ccf" );
+ }
+
+ /**
+ * A unit test for JUnit
+ * @exception Exception Description of the Exception
+ */
+ public void testSimpleLoad()
+ throws Exception
+ {
+ JCS jcs = JCS.getInstance( "testCache1" );
+
+ jcs.put( "TestKey", "TestValue" );
+
+ System.out.println( jcs.getStats() );
+
+ for ( int i = 1; i <= items; i++ )
+ {
+ jcs.put( i + ":key", "data" + i );
+ }
+
+ for ( int i = items; i > 0; i-- )
+ {
+ String res = (String) jcs.get( i + ":key" );
+ if ( res == null )
+ {
+ //assertNotNull( "[" + i + ":key] should not be null", res );
+ }
+ }
+
+ // test removal
+ jcs.remove( "300:key" );
+ assertNull( jcs.get( "TestKey" ) );
+
+ System.out.println( jcs.getStats() );
+ }
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptorUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptorUnitTest.java?rev=726149&r1=726148&r2=726149&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptorUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptorUnitTest.java Fri Dec 12 15:37:22 2008
@@ -7,9 +7,9 @@
import junit.framework.TestCase;
import org.apache.jcs.auxiliary.remote.MockRemoteCacheService;
-import org.apache.jcs.auxiliary.remote.http.client.RemoteHttpClientRequestFactory;
-import org.apache.jcs.auxiliary.remote.http.value.RemoteHttpCacheRequest;
-import org.apache.jcs.auxiliary.remote.http.value.RemoteHttpCacheResponse;
+import org.apache.jcs.auxiliary.remote.util.RemoteCacheRequestFactory;
+import org.apache.jcs.auxiliary.remote.value.RemoteCacheRequest;
+import org.apache.jcs.auxiliary.remote.value.RemoteCacheResponse;
import org.apache.jcs.engine.CacheElement;
/** Unit tests for the adaptor. */
@@ -28,10 +28,10 @@
String cacheName = "test";
Serializable key = "key";
long requesterId = 2;
- RemoteHttpCacheRequest request = RemoteHttpClientRequestFactory.createGetRequest( cacheName, key, requesterId );
+ RemoteCacheRequest request = RemoteCacheRequestFactory.createGetRequest( cacheName, key, requesterId );
// DO WORK
- RemoteHttpCacheResponse result = adaptor.processRequest( request );
+ RemoteCacheResponse result = adaptor.processRequest( request );
// VERIFY
assertNotNull( "Should have a result.", result );
@@ -50,11 +50,11 @@
String cacheName = "test";
String pattern = "pattern";
long requesterId = 2;
- RemoteHttpCacheRequest request = RemoteHttpClientRequestFactory.createGetMatchingRequest( cacheName, pattern,
+ RemoteCacheRequest request = RemoteCacheRequestFactory.createGetMatchingRequest( cacheName, pattern,
requesterId );
// DO WORK
- RemoteHttpCacheResponse result = adaptor.processRequest( request );
+ RemoteCacheResponse result = adaptor.processRequest( request );
// VERIFY
assertNotNull( "Should have a result.", result );
@@ -73,11 +73,11 @@
String cacheName = "test";
Set keys = Collections.EMPTY_SET;
long requesterId = 2;
- RemoteHttpCacheRequest request = RemoteHttpClientRequestFactory.createGetMultipleRequest( cacheName, keys,
+ RemoteCacheRequest request = RemoteCacheRequestFactory.createGetMultipleRequest( cacheName, keys,
requesterId );
// DO WORK
- RemoteHttpCacheResponse result = adaptor.processRequest( request );
+ RemoteCacheResponse result = adaptor.processRequest( request );
// VERIFY
assertNotNull( "Should have a result.", result );
@@ -98,10 +98,10 @@
Serializable key = "key";
long requesterId = 2;
CacheElement element = new CacheElement( cacheName, key, null );
- RemoteHttpCacheRequest request = RemoteHttpClientRequestFactory.createUpdateRequest( element, requesterId );
+ RemoteCacheRequest request = RemoteCacheRequestFactory.createUpdateRequest( element, requesterId );
// DO WORK
- RemoteHttpCacheResponse result = adaptor.processRequest( request );
+ RemoteCacheResponse result = adaptor.processRequest( request );
// VERIFY
assertNotNull( "Should have a result.", result );
@@ -120,10 +120,10 @@
String cacheName = "test";
Serializable key = "key";
long requesterId = 2;
- RemoteHttpCacheRequest request = RemoteHttpClientRequestFactory.createRemoveRequest( cacheName, key, requesterId );
+ RemoteCacheRequest request = RemoteCacheRequestFactory.createRemoveRequest( cacheName, key, requesterId );
// DO WORK
- RemoteHttpCacheResponse result = adaptor.processRequest( request );
+ RemoteCacheResponse result = adaptor.processRequest( request );
// VERIFY
assertNotNull( "Should have a result.", result );
@@ -141,10 +141,10 @@
String cacheName = "testRemoveALl";
long requesterId = 2;
- RemoteHttpCacheRequest request = RemoteHttpClientRequestFactory.createRemoveAllRequest( cacheName, requesterId );
+ RemoteCacheRequest request = RemoteCacheRequestFactory.createRemoveAllRequest( cacheName, requesterId );
// DO WORK
- RemoteHttpCacheResponse result = adaptor.processRequest( request );
+ RemoteCacheResponse result = adaptor.processRequest( request );
// VERIFY
assertNotNull( "Should have a result.", result );
Copied: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactoryUnitTest.java (from r724518, jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpClientRequestFactoryUnitTest.java)
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactoryUnitTest.java?p2=jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactoryUnitTest.java&p1=jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpClientRequestFactoryUnitTest.java&r1=724518&r2=726149&rev=726149&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpClientRequestFactoryUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactoryUnitTest.java Fri Dec 12 15:37:22 2008
@@ -1,17 +1,17 @@
-package org.apache.jcs.auxiliary.remote.http.client;
+package org.apache.jcs.auxiliary.remote.util;
import java.io.Serializable;
import java.util.Collections;
import java.util.Set;
-import org.apache.jcs.auxiliary.remote.http.behavior.IRemoteHttpCacheConstants;
-import org.apache.jcs.auxiliary.remote.http.value.RemoteHttpCacheRequest;
-import org.apache.jcs.engine.CacheElement;
-
import junit.framework.TestCase;
+import org.apache.jcs.auxiliary.remote.util.RemoteCacheRequestFactory;
+import org.apache.jcs.auxiliary.remote.value.RemoteCacheRequest;
+import org.apache.jcs.engine.CacheElement;
+
/** Unit tests for the request creator. */
-public class RemoteHttpClientRequestFactoryUnitTest
+public class RemoteCacheRequestFactoryUnitTest
extends TestCase
{
/** Simple test */
@@ -21,16 +21,16 @@
String cacheName = "test";
Serializable key = "key";
long requesterId = 2;
-
+
// DO WORK
- RemoteHttpCacheRequest result = RemoteHttpClientRequestFactory.createGetRequest( cacheName, key, requesterId );
-
+ RemoteCacheRequest result = RemoteCacheRequestFactory.createGetRequest( cacheName, key, requesterId );
+
// VERIFY
assertNotNull( "Should have a result", result );
assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
- assertEquals( "Wrong type", IRemoteHttpCacheConstants.REQUEST_TYPE_GET, result.getRequestType() );
+ assertEquals( "Wrong type", RemoteCacheRequest.REQUEST_TYPE_GET, result.getRequestType() );
}
-
+
/** Simple test */
public void testCreateGetMatchingRequest_Normal()
{
@@ -38,16 +38,17 @@
String cacheName = "test";
String pattern = "pattern";
long requesterId = 2;
-
+
// DO WORK
- RemoteHttpCacheRequest result = RemoteHttpClientRequestFactory.createGetMatchingRequest( cacheName, pattern, requesterId );
-
+ RemoteCacheRequest result = RemoteCacheRequestFactory.createGetMatchingRequest( cacheName, pattern,
+ requesterId );
+
// VERIFY
assertNotNull( "Should have a result", result );
assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
- assertEquals( "Wrong type", IRemoteHttpCacheConstants.REQUEST_TYPE_GET_MATCHING, result.getRequestType() );
+ assertEquals( "Wrong type", RemoteCacheRequest.REQUEST_TYPE_GET_MATCHING, result.getRequestType() );
}
-
+
/** Simple test */
public void testCreateGetMultipleRequest_Normal()
{
@@ -55,17 +56,17 @@
String cacheName = "test";
Set keys = Collections.EMPTY_SET;
long requesterId = 2;
-
+
// DO WORK
- RemoteHttpCacheRequest result = RemoteHttpClientRequestFactory.createGetMultipleRequest( cacheName, keys, requesterId );
-
+ RemoteCacheRequest result = RemoteCacheRequestFactory.createGetMultipleRequest( cacheName, keys,
+ requesterId );
+
// VERIFY
assertNotNull( "Should have a result", result );
assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
- assertEquals( "Wrong type", IRemoteHttpCacheConstants.REQUEST_TYPE_GET_MULTIPLE, result.getRequestType() );
+ assertEquals( "Wrong type", RemoteCacheRequest.REQUEST_TYPE_GET_MULTIPLE, result.getRequestType() );
}
-
-
+
/** Simple test */
public void testCreateRemoveRequest_Normal()
{
@@ -73,33 +74,33 @@
String cacheName = "test";
Serializable key = "key";
long requesterId = 2;
-
+
// DO WORK
- RemoteHttpCacheRequest result = RemoteHttpClientRequestFactory.createRemoveRequest( cacheName, key, requesterId );
-
+ RemoteCacheRequest result = RemoteCacheRequestFactory
+ .createRemoveRequest( cacheName, key, requesterId );
+
// VERIFY
assertNotNull( "Should have a result", result );
assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
- assertEquals( "Wrong type", IRemoteHttpCacheConstants.REQUEST_TYPE_REMOVE, result.getRequestType() );
+ assertEquals( "Wrong type", RemoteCacheRequest.REQUEST_TYPE_REMOVE, result.getRequestType() );
}
-
-
+
/** Simple test */
public void testCreateRemoveAllRequest_Normal()
{
// SETUP
String cacheName = "test";
long requesterId = 2;
-
+
// DO WORK
- RemoteHttpCacheRequest result = RemoteHttpClientRequestFactory.createRemoveAllRequest( cacheName, requesterId );
-
+ RemoteCacheRequest result = RemoteCacheRequestFactory.createRemoveAllRequest( cacheName, requesterId );
+
// VERIFY
assertNotNull( "Should have a result", result );
assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
- assertEquals( "Wrong type", IRemoteHttpCacheConstants.REQUEST_TYPE_REMOVE_ALL, result.getRequestType() );
+ assertEquals( "Wrong type", RemoteCacheRequest.REQUEST_TYPE_REMOVE_ALL, result.getRequestType() );
}
-
+
/** Simple test */
public void testCreateUpdateRequest_Normal()
{
@@ -107,15 +108,15 @@
String cacheName = "test";
Serializable key = "key";
long requesterId = 2;
-
+
CacheElement element = new CacheElement( cacheName, key, null );
-
+
// DO WORK
- RemoteHttpCacheRequest result = RemoteHttpClientRequestFactory.createUpdateRequest( element, requesterId );
-
+ RemoteCacheRequest result = RemoteCacheRequestFactory.createUpdateRequest( element, requesterId );
+
// VERIFY
assertNotNull( "Should have a result", result );
assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
- assertEquals( "Wrong type", IRemoteHttpCacheConstants.REQUEST_TYPE_UPDATE, result.getRequestType() );
+ assertEquals( "Wrong type", RemoteCacheRequest.REQUEST_TYPE_UPDATE, result.getRequestType() );
}
}
Propchange: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactoryUnitTest.java
------------------------------------------------------------------------------
svn:mergeinfo =