jakarta-jcs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asm...@apache.org
Subject svn commit: r433622 - in /jakarta/jcs/trunk/src: java/org/apache/jcs/auxiliary/remote/ test/org/apache/jcs/auxiliary/remote/
Date Tue, 22 Aug 2006 13:15:19 GMT
Author: asmuts
Date: Tue Aug 22 06:15:18 2006
New Revision: 433622

URL: http://svn.apache.org/viewvc?rev=433622&view=rev
Log:
started making the remote zombie queue messages.
i'll change the list into a bounded queue in a bit.

Added:
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerMockImpl.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheServiceMockImpl.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheUnitTest.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheServiceUnitTest.java
Modified:
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheService.java

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java?rev=433622&r1=433621&r2=433622&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java Tue Aug 22
06:15:18 2006
@@ -184,6 +184,7 @@
         {
             if ( !this.irca.getGetOnly() )
             {
+                ICacheElementSerialized serialized = null;
                 try
                 {
                     if ( log.isDebugEnabled() )
@@ -193,7 +194,7 @@
 
                     // convert so we don't have to know about the object on the
                     // other end.
-                    ICacheElementSerialized serialized = SerializationConversionUtil
+                    serialized = SerializationConversionUtil
                         .getSerializedCacheElement( ce, this.elementSerializer );
 
                     remote.update( serialized, getListenerId() );
@@ -205,6 +206,7 @@
                 }
                 catch ( Exception ex )
                 {
+                    // event queue will wait and retry
                     handleException( ex, "Failed to put [" + ce.getKey() + "] to " + ce.getCacheName()
);
                 }
             }
@@ -221,7 +223,7 @@
     /**
      * Synchronously get from the remote cache; if failed, replace the remote handle with
a zombie.
      * <p>
-     * Use threadpool to timeout is a value is set for GetTimeoutMillis
+     * Use threadpool to timeout if a value is set for GetTimeoutMillis
      * <p>
      * If we are a cluster client, we need to leave the Element in its serilaized form. Cluster
      * cients cannot deserialize objects. Cluster clients get ICacheElementSerialized objects
from
@@ -272,7 +274,7 @@
      * This allows gets to timeout in case of remote server machine shutdown.
      * <p>
      * @param key
-     * @return
+     * @return ICacheElement
      * @throws IOException
      */
     public ICacheElement getUsingPool( final Serializable key )
@@ -332,7 +334,7 @@
      * Returns all the keys for a group.
      * <p>
      * @param groupName
-     * @return
+     * @return Set
      * @throws java.rmi.RemoteException
      */
     public Set getGroupKeys( String groupName )
@@ -465,7 +467,7 @@
 
         if ( this.irca.getRemoteType() == IRemoteCacheAttributes.CLUSTER )
         {
-            // somethign cluster specific
+            // something cluster specific
         }
 
         // no data gathered here
@@ -488,6 +490,14 @@
             elems.add( se );
         }
 
+        if ( remote instanceof ZombieRemoteCacheService )
+        {
+            se = new StatElement();
+            se.setName( "Zombie Queue Size" );
+            se.setData( "" + ((ZombieRemoteCacheService)remote).getQueueSize() );
+            elems.add( se );            
+        }
+        
         // get an array and put them in the Stats object
         IStatElement[] ses = (IStatElement[]) elems.toArray( new StatElement[0] );
         stats.setStatElements( ses );
@@ -524,13 +534,38 @@
     }
 
     /**
-     * Replaces the current remote cache service handle with the given handle.
+     * Replaces the current remote cache service handle with the given handle.  
+     * If the current remote is a Zombie, the propagate teh events that may be 
+     * queued to the restored service.
      * <p>
      * @param remote IRemoteCacheService -- the remote server or proxy to the remote server
      */
     public void fixCache( IRemoteCacheService remote )
     {
-        this.remote = remote;
+        if ( this.remote != null && this.remote instanceof ZombieRemoteCacheService
)
+        {
+            ZombieRemoteCacheService zombie = (ZombieRemoteCacheService)this.remote;
+            this.remote = remote;
+            try
+            {
+                zombie.propagateEvents(  remote );
+            }
+            catch ( Exception e )
+            {
+                try
+                {
+                    handleException( e, "Problem propagating events from Zombie Queue to
new Remote Service." );
+                }
+                catch ( IOException e1 )
+                {
+                    // swallow, since this is just expected kick back.  Handle always throws
+                }
+            }
+        }
+        else
+        {
+            this.remote = remote;
+        }
         return;
     }
 
@@ -545,10 +580,14 @@
     private void handleException( Exception ex, String msg )
         throws IOException
     {
-        log.error( "Disabling remote cache due to error " + msg );
-        log.error( ex );
+        log.error( "Disabling remote cache due to error: " + msg , ex );
 
-        remote = new ZombieRemoteCacheService();
+        // we should not switch if the existing is a zombie.
+        if ( remote == null || !(remote instanceof ZombieRemoteCacheService) )
+        {
+            // TODO make configurable
+            remote = new ZombieRemoteCacheService( 1000 );
+        }
         // may want to flush if region specifies
         // Notify the cache monitor about the error, and kick off the recovery
         // process.

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheService.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheService.java?rev=433622&r1=433621&r2=433622&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheService.java
(original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheService.java
Tue Aug 22 06:15:18 2006
@@ -1,80 +1,134 @@
 package org.apache.jcs.auxiliary.remote;
 
 /*
- * Copyright 2002-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.
+ * Copyright 2002-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.io.Serializable;
-import java.util.Set;
 import java.util.Collections;
+import java.util.LinkedList;
+import java.util.Set;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService;
-
 import org.apache.jcs.engine.ZombieCacheService;
-
 import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.utils.timing.ElapsedTimer;
 
 /**
- * Zombie adapter for the remote cache service. It just balks.
- * 
+ * Zombie adapter for the remote cache service. It just balks if there is no queue configured.
If a
+ * queue is configured, then events will be added to the queue. The idea is that when proper
+ * operation is restored, the remote cache will walk the queue. The queue must be bounded
so it does
+ * not eat memory.
+ * <p>
+ * Much of this is potentially reusable.
+ * <p>
+ * TODO figure out a way to get the propagate method into an interface for Zombies.
  */
 public class ZombieRemoteCacheService
     extends ZombieCacheService
     implements IRemoteCacheService
 {
+    private final static Log log = LogFactory.getLog( ZombieRemoteCacheService.class );
+
+    private int maxQueueSize = 0;
+
+    // substitute the BoundedQueue tomorrow.
+    private LinkedList queue = new LinkedList();
 
-    /*
+    /**
+     * Default.
+     */
+    public ZombieRemoteCacheService()
+    {
+        // nothing
+    }
+
+    /**
+     * Sets the maximum number of items that will be allowed on the queue.
+     * <p>
+     * @param maxQueueSize
+     */
+    public ZombieRemoteCacheService( int maxQueueSize )
+    {
+        this.maxQueueSize = maxQueueSize;
+    }
+
+    /**
+     * Gets the number of items on the queue.
+     * <p>
+     * @return size of the queue.
+     */
+    public int getQueueSize()
+    {
+        return queue.size();
+    }
+    
+    /**
+     * Adds an update event to the queue if the maxSize is greater than 0;
+     * <p>
      * (non-Javadoc)
-     * 
      * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#update(org.apache.jcs.engine.behavior.ICacheElement,
      *      long)
      */
     public void update( ICacheElement item, long listenerId )
     {
+        if ( maxQueueSize > 0 )
+        {
+            PutEvent event = new PutEvent( item, listenerId );
+            queue.addLast( event );
+        }
         // Zombies have no inner life
         return;
     }
 
-    /*
+    /**
+     * Adds a removeAll event to the queue if the maxSize is greater than 0;
+     * <p>
      * (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 listenerId )
     {
+        if ( maxQueueSize > 0 )
+        {
+            RemoveEvent event = new RemoveEvent( cacheName, key, listenerId );
+            queue.addLast( event );
+        }
         // Zombies have no inner life
         return;
     }
 
-    /*
+    /**
+     * Adds a removeAll event to the queue if the maxSize is greater than 0;
+     * <p>
      * (non-Javadoc)
-     * 
      * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#removeAll(java.lang.String,
      *      long)
      */
     public void removeAll( String cacheName, long listenerId )
     {
+        if ( maxQueueSize > 0 )
+        {
+            RemoveAllEvent event = new RemoveAllEvent( cacheName, listenerId );
+            queue.addLast( event );
+        }
         // Zombies have no inner life
         return;
     }
 
-    /*
+    /**
+     * Does nothing. Gets are synchronous and cannot be added to a queue.
+     * <p>
      * (non-Javadoc)
-     * 
      * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#get(java.lang.String,
      *      java.io.Serializable, long)
      */
@@ -85,14 +139,126 @@
         return null;
     }
 
-    /*
+    /**
+     * Does nothing.
+     * <p>
      * (non-Javadoc)
-     * 
      * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#getGroupKeys(java.lang.String,
      *      java.lang.String)
      */
     public Set getGroupKeys( String cacheName, String groupName )
     {
         return Collections.EMPTY_SET;
+    }
+
+    /**
+     * Walk the queue, calling the service for each queue operation.
+     * <p>
+     * @param service
+     */
+    protected void propagateEvents( IRemoteCacheService service )
+        throws Exception
+    {
+        int cnt = 0;
+        if ( log.isInfoEnabled() )
+        {
+            log.info( "Propagating events to the new RemoteService." );
+        }
+        ElapsedTimer timer = new ElapsedTimer();
+        while ( !queue.isEmpty() )
+        {
+            cnt++;
+            
+            // for each item, call the appropriate service method
+            ZombieEvent event = (ZombieEvent) queue.removeFirst();
+
+            if ( event instanceof PutEvent )
+            {
+                PutEvent putEvent = (PutEvent) event;
+                service.update( putEvent.element, event.requesterId );
+            }
+            else if ( event instanceof RemoveEvent )
+            {
+                RemoveEvent removeEvent = (RemoveEvent) event;
+                service.remove( event.cacheName, removeEvent.key, event.requesterId );
+            }
+            else if ( event instanceof RemoveAllEvent )
+            {
+                service.removeAll( event.cacheName, event.requesterId );
+            }
+        }
+        if ( log.isInfoEnabled() )
+        {
+            log.info( "Propagated " + cnt + " events to the new RemoteService in " + timer.getElapsedTimeString()
);
+        }
+    }
+
+    /**
+     * Base of the other events.
+     */
+    private abstract class ZombieEvent
+    {
+        String cacheName;
+
+        long requesterId;
+    }
+
+    /**
+     * A basic put event.
+     */
+    private class PutEvent
+        extends ZombieEvent
+    {
+        ICacheElement element;
+
+        /**
+         * Set the element
+         * @param element
+         * @param requesterId
+         */
+        public PutEvent( ICacheElement element, long requesterId )
+        {
+            this.requesterId = requesterId;
+            this.element = element;
+        }
+    }
+
+    /**
+     * A basic Remove event.
+     */
+    private class RemoveEvent
+        extends ZombieEvent
+    {
+        Serializable key;
+
+        /**
+         * Set the element
+         * @param cacheName
+         * @param key
+         * @param requesterId
+         */
+        public RemoveEvent( String cacheName, Serializable key, long requesterId )
+        {
+            this.cacheName = cacheName;
+            this.requesterId = requesterId;
+            this.key = key;
+        }
+    }
+
+    /**
+     * A basic RemoveAll event.
+     */
+    private class RemoveAllEvent
+        extends ZombieEvent
+    {
+        /**
+         * @param cacheName
+         * @param requesterId
+         */
+        public RemoveAllEvent( String cacheName, long requesterId )
+        {
+            this.cacheName = cacheName;
+            this.requesterId = requesterId;
+        }
     }
 }

Added: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerMockImpl.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerMockImpl.java?rev=433622&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerMockImpl.java
(added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerMockImpl.java
Tue Aug 22 06:15:18 2006
@@ -0,0 +1,86 @@
+package org.apache.jcs.auxiliary.remote;
+
+import java.io.IOException;
+import java.io.Serializable;
+
+import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheListener;
+import org.apache.jcs.engine.behavior.ICacheElement;
+
+/**
+ * For testing.
+ * <p>
+ * @author admin
+ */
+public class RemoteCacheListenerMockImpl
+    implements IRemoteCacheListener
+{
+    /** Setup the listener id that this will return. */
+    private long listenerId;
+
+    public void dispose()
+        throws IOException
+    {
+        // TODO Auto-generated method stub
+    }
+
+    /**
+     * returns the listener id, which can be setup.
+     */
+    public long getListenerId()
+        throws IOException
+    {
+        return listenerId;
+    }
+
+    public String getLocalHostAddress()
+        throws IOException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public int getRemoteType()
+        throws IOException
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    /**
+     * Allows you to setup the listener id.
+     */
+    public void setListenerId( long id )
+        throws IOException
+    {
+        listenerId = id;
+    }
+
+    public void handleDispose( String cacheName )
+        throws IOException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void handlePut( ICacheElement item )
+        throws IOException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void handleRemove( String cacheName, Serializable key )
+        throws IOException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void handleRemoveAll( String cacheName )
+        throws IOException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Added: 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?rev=433622&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheServiceMockImpl.java
(added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheServiceMockImpl.java
Tue Aug 22 06:15:18 2006
@@ -0,0 +1,151 @@
+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;
+    }
+
+}

Added: 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?rev=433622&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheUnitTest.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheUnitTest.java Tue
Aug 22 06:15:18 2006
@@ -0,0 +1,83 @@
+package org.apache.jcs.auxiliary.remote;
+
+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() );
+    }    
+}

Added: 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?rev=433622&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheServiceUnitTest.java
(added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheServiceUnitTest.java
Tue Aug 22 06:15:18 2006
@@ -0,0 +1,108 @@
+package org.apache.jcs.auxiliary.remote;
+
+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);
+    }    
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org


Mime
View raw message