jakarta-jcs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asm...@apache.org
Subject svn commit: r434450 - in /jakarta/jcs/trunk/src: java/org/apache/jcs/auxiliary/remote/server/ java/org/apache/jcs/engine/ test-conf/ test/org/apache/jcs/auxiliary/remote/ test/org/apache/jcs/auxiliary/remote/server/
Date Thu, 24 Aug 2006 18:00:37 GMT
Author: asmuts
Date: Thu Aug 24 11:00:36 2006
New Revision: 434450

URL: http://svn.apache.org/viewvc?rev=434450&view=rev
Log:
Adding remote cache unit tests

Added:
    jakarta/jcs/trunk/src/test-conf/TestRemoteCacheServer.ccf
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerAttributesUnitTest.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerUnitTest.java
Modified:
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerAttributes.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheListeners.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerMockImpl.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerUnitTest.java

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java?rev=434450&r1=434449&r2=434450&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java
(original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java
Thu Aug 24 11:00:36 2006
@@ -152,13 +152,13 @@
     }
 
     /**
-     * Returns the cache lsitener for the specified cache. Creates the cache and
+     * Returns the cache listener for the specified cache. Creates the cache and
      * the cache descriptor if they do not already exist.
      * <p>
      * @param cacheName
      * @return The cacheListeners value
      */
-    private CacheListeners getCacheListeners( String cacheName )
+    protected CacheListeners getCacheListeners( String cacheName )
     {
         CacheListeners cacheListeners = (CacheListeners) cacheListenersMap.get( cacheName
);
         synchronized ( cacheListenersMap )
@@ -184,7 +184,7 @@
      * @param cacheName
      * @return The clusterListeners value
      */
-    private CacheListeners getClusterListeners( String cacheName )
+    protected CacheListeners getClusterListeners( String cacheName )
     {
         CacheListeners cacheListeners = (CacheListeners) clusterListenersMap.get( cacheName
);
         synchronized ( clusterListenersMap )
@@ -282,7 +282,7 @@
 
         if ( log.isDebugEnabled() )
         {
-            log.debug( "In update, put " + item.getKey() + " in " + item.getCacheName() );
+            log.debug( "In update, put [" + item.getKey() + "] in [" + item.getCacheName()
+ "]" );
         }
 
         try
@@ -484,7 +484,7 @@
 
         if ( log.isDebugEnabled() )
         {
-            log.debug( "get " + key + " from cache " + cacheName + " requesterId = [" + requesterId
+ "] remoteType = "
+            log.debug( "get [" + key + "] from cache [" + cacheName + "] requesterId = ["
+ requesterId + "] remoteType = "
                 + remoteTypeL );
         }
 
@@ -610,7 +610,7 @@
     {
         if ( log.isDebugEnabled() )
         {
-            log.debug( "remove " + key + " from cache " + cacheName );
+            log.debug( "remove [" + key + "] from cache [" + cacheName + "]" );
         }
         CacheListeners cacheDesc = (CacheListeners) cacheListenersMap.get( cacheName );
 
@@ -627,7 +627,6 @@
             // notification.
             synchronized ( cacheDesc )
             {
-
                 boolean removeSuccess = false;
 
                 // No need to notify if it was not cached.
@@ -652,7 +651,7 @@
 
                 if ( log.isDebugEnabled() )
                 {
-                    log.debug( "remove " + key + " from cache " + cacheName + " success (was
it found) = "
+                    log.debug( "remove [" + key + "] from cache [" + cacheName + "] success
(was it found) = "
                         + removeSuccess );
                 }
 
@@ -685,7 +684,7 @@
     }
 
     /**
-     * Remove all keys from the sepcified remote cache.
+     * Remove all keys from the specified remote cache.
      * <p>
      * @param cacheName
      * @param requesterId
@@ -732,7 +731,6 @@
                 // update registered listeners
                 if ( !fromCluster || ( fromCluster && rcsa.getLocalClusterConsistency()
) )
                 {
-
                     ICacheEventQueue[] qlist = getEventQList( cacheDesc, requesterId );
 
                     for ( int i = 0; i < qlist.length; i++ )
@@ -966,7 +964,7 @@
     }
 
     /**
-     * Unsibscribe this listener from this region. If the listener is
+     * Unsubscribe this listener from this region. If the listener is
      * registered, it will be removed from the event queue map list.
      * <p>
      * @param cacheName
@@ -979,7 +977,7 @@
     }
 
     /**
-     * Unsibscribe this listener from this region. If the listener is
+     * Unsubscribe this listener from this region. If the listener is
      * registered, it will be removed from the event queue map list.
      * <p>
      * @param cacheName
@@ -992,7 +990,23 @@
             log.info( "Removing listener for cache region = [" + cacheName + "] and listenerId
[" + listenerId + "]" );
         }
 
-        CacheListeners cacheDesc = getCacheListeners( cacheName );
+        Integer remoteTypeL = (Integer) idTypeMap.get( new Long( listenerId ) );
+        boolean isClusterListener = false;
+        if ( remoteTypeL != null && remoteTypeL.intValue() == IRemoteCacheAttributes.CLUSTER
)
+        {
+            isClusterListener = true;
+        }
+        
+        CacheListeners cacheDesc = null;
+        
+        if ( isClusterListener )
+        {
+            cacheDesc = getClusterListeners( cacheName );            
+        }
+        else
+        {
+            cacheDesc = getCacheListeners( cacheName );
+        }
         Map eventQMap = cacheDesc.eventQMap;
         cleanupEventQMap( eventQMap );
         ICacheEventQueue q = (ICacheEventQueue) eventQMap.remove( new Long( listenerId )
);

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerAttributes.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerAttributes.java?rev=434450&r1=434449&r2=434450&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerAttributes.java
(original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerAttributes.java
Thu Aug 24 11:00:36 2006
@@ -336,13 +336,14 @@
     public String toString()
     {
         StringBuffer buf = new StringBuffer();
-        buf.append( "\n remoteHost = " + this.remoteHost );
-        buf.append( "\n remotePort = " + this.remotePort );
-        buf.append( "\n cacheName = " + this.cacheName );
-        buf.append( "\n removeUponRemotePut = " + this.removeUponRemotePut );
-        buf.append( "\n getOnly = " + getOnly );
-        buf.append( "\n allowClusterGet = " + allowClusterGet );
-        buf.append( "\n localClusterConsistency = " + localClusterConsistency );
+        buf.append( "\n remoteHost = " + this.getRemoteHost() );
+        buf.append( "\n remotePort = " + this.getRemotePort() );
+        buf.append( "\n cacheName = " + this.getCacheName() );
+        buf.append( "\n removeUponRemotePut = " + this.getRemoveUponRemotePut() );
+        buf.append( "\n getOnly = " + this.getGetOnly() );
+        buf.append( "\n allowClusterGet = " + this.getAllowClusterGet() );
+        buf.append( "\n localClusterConsistency = " + this.getLocalClusterConsistency() );
+        buf.append( "\n getConfigFileName = " + this.getConfigFileName() );
         return buf.toString();
     }
 }

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheListeners.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheListeners.java?rev=434450&r1=434449&r2=434450&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheListeners.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheListeners.java Thu Aug 24 11:00:36
2006
@@ -25,10 +25,7 @@
     /** Description of the Field */
     public final ICache cache;
 
-    /*
-     * Map ICacheListener to ICacheEventQueue.
-     */
-    /** Description of the Field */
+    /** Map ICacheListener to ICacheEventQueue */
     public final Map eventQMap = new Hashtable();
 
     /**

Added: jakarta/jcs/trunk/src/test-conf/TestRemoteCacheServer.ccf
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test-conf/TestRemoteCacheServer.ccf?rev=434450&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test-conf/TestRemoteCacheServer.ccf (added)
+++ jakarta/jcs/trunk/src/test-conf/TestRemoteCacheServer.ccf Thu Aug 24 11:00:36 2006
@@ -0,0 +1,4 @@
+jcs.default=
+jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
+jcs.default.cacheattributes.MaxObjects=1000
+jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache

Modified: 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=434450&r1=434449&r2=434450&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerMockImpl.java
(original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerMockImpl.java
Thu Aug 24 11:00:36 2006
@@ -13,14 +13,17 @@
 
 import java.io.IOException;
 import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
 
+import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
 import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheListener;
 import org.apache.jcs.engine.behavior.ICacheElement;
 
 /**
  * For testing.
  * <p>
- * @author admin
+ * @author Aaron Smuts
  */
 public class RemoteCacheListenerMockImpl
     implements IRemoteCacheListener
@@ -28,6 +31,21 @@
     /** Setup the listener id that this will return. */
     private long listenerId;
 
+    /** Number of times handlePut was called. */
+    public int putCount;
+    
+    /** List of ICacheElements passed to handlePut. */
+    public List putItems = new LinkedList();
+
+    /** List of Serializable objects passed to handleRemove. */
+    public List removedKeys = new LinkedList();
+
+    /** Number of times handleRemote was called. */
+    public int removeCount;
+    
+    /** The type of remote listener */
+    public int remoteType = IRemoteCacheAttributes.LOCAL;
+    
     public void dispose()
         throws IOException
     {
@@ -50,11 +68,13 @@
         return null;
     }
 
+    /**
+     * Return the setup remoteType.
+     */
     public int getRemoteType()
         throws IOException
     {
-        // TODO Auto-generated method stub
-        return 0;
+        return remoteType;
     }
 
     /**
@@ -73,18 +93,24 @@
 
     }
 
+    /**
+     * This increments the put count and adds the item to the putItem list.
+     */
     public void handlePut( ICacheElement item )
         throws IOException
     {
-        // TODO Auto-generated method stub
-
+        putCount++;
+        this.putItems.add( item );
     }
 
+    /**
+     * Increments the remove count and adds the key to the removedKeys list.
+     */
     public void handleRemove( String cacheName, Serializable key )
         throws IOException
     {
-        // TODO Auto-generated method stub
-
+        removeCount++;
+        removedKeys.add( key );
     }
 
     public void handleRemoveAll( String cacheName )

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerUnitTest.java?rev=434450&r1=434449&r2=434450&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerUnitTest.java
(original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerUnitTest.java
Thu Aug 24 11:00:36 2006
@@ -15,14 +15,13 @@
 
 /**
  * Tests for the remote cache listener.
- * 
+ * <p>
  * @author Aaron Smuts
  * 
  */
 public class RemoteCacheListenerUnitTest
     extends TestCase
 {
-
     /**
      * Create a RemoteCacheListener with a mock cache manager.  Set remove on put to false.
      * Create a serialized element.  Call put on the listener.

Added: 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?rev=434450&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerAttributesUnitTest.java
(added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerAttributesUnitTest.java
Thu Aug 24 11:00:36 2006
@@ -0,0 +1,46 @@
+package org.apache.jcs.auxiliary.remote.server;
+
+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() );
+    }
+}

Added: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerUnitTest.java?rev=434450&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerUnitTest.java
(added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerUnitTest.java
Thu Aug 24 11:00:36 2006
@@ -0,0 +1,282 @@
+package org.apache.jcs.auxiliary.remote.server;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.auxiliary.remote.RemoteCacheListenerMockImpl;
+import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
+import org.apache.jcs.auxiliary.remote.server.behavior.IRemoteCacheServerAttributes;
+import org.apache.jcs.engine.CacheElement;
+import org.apache.jcs.engine.behavior.ICacheElement;
+
+/**
+ * Since the server does not know that it is a server, it is easy to unit test. The factory
does all
+ * the rmi work.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class RemoteCacheServerUnitTest
+    extends TestCase
+{
+
+    /**
+     * Add a listner. Pass the id of 0, verify that the server sets a new listener id. Do
another
+     * and verify that the second gets an id of 2.
+     * <p>
+     * @throws Exception
+     */
+    public void testAddListenerToCache()
+        throws Exception
+    {
+        // SETUP
+        IRemoteCacheServerAttributes rcsa = new RemoteCacheServerAttributes();
+        rcsa.setConfigFileName( "/TestRemoteCacheServer.ccf" );
+        RemoteCacheServer server = new RemoteCacheServer( rcsa );
+
+        RemoteCacheListenerMockImpl mockListener1 = new RemoteCacheListenerMockImpl();
+        RemoteCacheListenerMockImpl mockListener2 = new RemoteCacheListenerMockImpl();
+
+        String cacheName = "testAddListener";
+
+        // DO WORK
+        server.addCacheListener( cacheName, mockListener1 );
+        server.addCacheListener( cacheName, mockListener2 );
+
+        // VERIFY
+        assertEquals( "Wrong listener id.", 1, mockListener1.getListenerId() );
+        assertEquals( "Wrong listener id.", 2, mockListener2.getListenerId() );
+    }
+
+    /**
+     * Add a listner. Pass the id of 0, verify that the server sets a new listener id. Do
another
+     * and verify that the second gets an id of 2.
+     * <p>
+     * @throws Exception
+     */
+    public void testAddListenerToAll()
+        throws Exception
+    {
+        // SETUP
+        IRemoteCacheServerAttributes rcsa = new RemoteCacheServerAttributes();
+        rcsa.setConfigFileName( "/TestRemoteCacheServer.ccf" );
+        RemoteCacheServer server = new RemoteCacheServer( rcsa );
+
+        RemoteCacheListenerMockImpl mockListener1 = new RemoteCacheListenerMockImpl();
+        RemoteCacheListenerMockImpl mockListener2 = new RemoteCacheListenerMockImpl();
+
+        // DO WORK
+        // don't specify the cache name
+        server.addCacheListener( mockListener1 );
+        server.addCacheListener( mockListener2 );
+
+        // VERIFY
+        assertEquals( "Wrong listener id.", 1, mockListener1.getListenerId() );
+        assertEquals( "Wrong listener id.", 2, mockListener2.getListenerId() );
+    }
+
+    /**
+     * Add a listner. Pass the id of 0, verify that the server sets a new listener id. Do
another
+     * and verify that the second gets an id of 2. Call remove Listener and verify that it
is
+     * removed.
+     * <p>
+     * @throws Exception
+     */
+    public void testAddListenerToAllThenRemove()
+        throws Exception
+    {
+        // SETUP
+        IRemoteCacheServerAttributes rcsa = new RemoteCacheServerAttributes();
+        rcsa.setConfigFileName( "/TestRemoteCacheServer.ccf" );
+        RemoteCacheServer server = new RemoteCacheServer( rcsa );
+
+        RemoteCacheListenerMockImpl mockListener1 = new RemoteCacheListenerMockImpl();
+        RemoteCacheListenerMockImpl mockListener2 = new RemoteCacheListenerMockImpl();
+
+        String cacheName = "testAddListenerToAllThenRemove";
+
+        // DO WORK
+        server.addCacheListener( cacheName, mockListener1 );
+        server.addCacheListener( cacheName, mockListener2 );
+
+        // VERIFY
+        assertEquals( "Wrong number of listeners.", 2, server.getCacheListeners( cacheName
).eventQMap.size() );
+        assertEquals( "Wrong listener id.", 1, mockListener1.getListenerId() );
+        assertEquals( "Wrong listener id.", 2, mockListener2.getListenerId() );
+
+        // DO WORK
+        server.removeCacheListener( cacheName, mockListener1.getListenerId() );
+        assertEquals( "Wrong number of listeners.", 1, server.getCacheListeners( cacheName
).eventQMap.size() );
+    }
+
+    /**
+     * Add a listner. Pass the id of 0, verify that the server sets a new listener id. Do
another
+     * and verify that the second gets an id of 2. Call remove Listener and verify that it
is
+     * removed.
+     * <p>
+     * @throws Exception
+     */
+    public void testAddListenerToAllThenRemove_clusterType()
+        throws Exception
+    {
+        // SETUP
+        IRemoteCacheServerAttributes rcsa = new RemoteCacheServerAttributes();
+        rcsa.setConfigFileName( "/TestRemoteCacheServer.ccf" );
+        RemoteCacheServer server = new RemoteCacheServer( rcsa );
+
+        RemoteCacheListenerMockImpl mockListener1 = new RemoteCacheListenerMockImpl();
+        mockListener1.remoteType = IRemoteCacheServerAttributes.CLUSTER;
+        RemoteCacheListenerMockImpl mockListener2 = new RemoteCacheListenerMockImpl();
+        mockListener2.remoteType = IRemoteCacheServerAttributes.CLUSTER;
+
+        String cacheName = "testAddListenerToAllThenRemove";
+
+        // DO WORK
+        server.addCacheListener( cacheName, mockListener1 );
+        server.addCacheListener( cacheName, mockListener2 );
+
+        // VERIFY
+        assertEquals( "Wrong number of listeners.", 0, server.getCacheListeners( cacheName
).eventQMap.size() );
+        assertEquals( "Wrong number of listeners.", 2, server.getClusterListeners( cacheName
).eventQMap.size() );
+        assertEquals( "Wrong listener id.", 1, mockListener1.getListenerId() );
+        assertEquals( "Wrong listener id.", 2, mockListener2.getListenerId() );
+
+        // DO WORK
+        server.removeCacheListener( cacheName, mockListener1.getListenerId() );
+        assertEquals( "Wrong number of listeners.", 1, server.getClusterListeners( cacheName
).eventQMap.size() );
+    }    
+    
+    /**
+     * Register a listener and then verify that it is called when we put using a different
listener
+     * id.
+     * @throws Exception
+     */
+    public void testSimpleRegisterListenerAndPut()
+        throws Exception
+    {
+        // SETUP
+        IRemoteCacheServerAttributes rcsa = new RemoteCacheServerAttributes();
+        rcsa.setConfigFileName( "/TestRemoteCacheServer.ccf" );
+
+        RemoteCacheListenerMockImpl mockListener = new RemoteCacheListenerMockImpl();
+        RemoteCacheServer server = new RemoteCacheServer( rcsa );
+
+        String cacheName = "testSimpleRegisterListenerAndPut";
+        server.addCacheListener( cacheName, mockListener );
+
+        // DO WORK
+        List inputItems = new LinkedList();
+        int numToPut = 10;
+
+        for ( int i = 0; i < numToPut; i++ )
+        {
+            ICacheElement element = new CacheElement( cacheName, String.valueOf( i ), new
Long( i ) );
+            inputItems.add( element );
+            server.update( element, 9999 );
+        }
+
+        Thread.sleep( 100 );
+        Thread.yield();
+        Thread.sleep( 100 );
+
+        // VERIFY
+        assertEquals( "Wrong number of items put to listener.", numToPut, mockListener.putItems.size()
);
+        for ( int i = 0; i < numToPut; i++ )
+        {
+            assertEquals( "Wrong item.", inputItems.get( i ), mockListener.putItems.get(
i ) );
+        }
+    }
+
+    /**
+     * Register a listener and then verify that it is called when we put using a different
listener
+     * id. The updates should come from a cluster listener and local cluster consistency
should be
+     * true.
+     * <p>
+     * @throws Exception
+     */
+    public void testSimpleRegisterListenerAndPut_FromClusterWithLCC()
+        throws Exception
+    {
+        // SETUP
+        IRemoteCacheServerAttributes rcsa = new RemoteCacheServerAttributes();
+        rcsa.setLocalClusterConsistency( true );
+        rcsa.setConfigFileName( "/TestRemoteCacheServer.ccf" );
+        RemoteCacheServer server = new RemoteCacheServer( rcsa );
+
+        // this is to get the listenr id for inserts.
+        RemoteCacheListenerMockImpl clusterListener = new RemoteCacheListenerMockImpl();
+        clusterListener.remoteType = IRemoteCacheAttributes.CLUSTER;
+
+        // this should get the updates
+        RemoteCacheListenerMockImpl localListener = new RemoteCacheListenerMockImpl();
+        localListener.remoteType = IRemoteCacheAttributes.LOCAL;
+
+        String cacheName = "testSimpleRegisterListenerAndPut_FromClusterWithLCC";
+        server.addCacheListener( cacheName, clusterListener );
+        server.addCacheListener( cacheName, localListener );
+
+        // DO WORK
+        List inputItems = new LinkedList();
+        int numToPut = 10;
+
+        for ( int i = 0; i < numToPut; i++ )
+        {
+            ICacheElement element = new CacheElement( cacheName, String.valueOf( i ), new
Long( i ) );
+            inputItems.add( element );
+            // update using the cluster listener id
+            server.update( element, clusterListener.getListenerId() );
+        }
+
+        Thread.sleep( 100 );
+        Thread.yield();
+        Thread.sleep( 100 );
+
+        // VERIFY
+        assertEquals( "Wrong number of items put to listener.", numToPut, localListener.putItems.size()
);
+        for ( int i = 0; i < numToPut; i++ )
+        {
+            assertEquals( "Wrong item.", inputItems.get( i ), localListener.putItems.get(
i ) );
+        }
+    }
+
+    /**
+     * Register a listener and then verify that it is called when we put using a different
listener
+     * id.
+     * @throws Exception
+     */
+    public void testSimpleRegisterListenerAndRemove()
+        throws Exception
+    {
+        // SETUP
+        IRemoteCacheServerAttributes rcsa = new RemoteCacheServerAttributes();
+        rcsa.setConfigFileName( "/TestRemoteCacheServer.ccf" );
+
+        RemoteCacheListenerMockImpl mockListener = new RemoteCacheListenerMockImpl();
+        RemoteCacheServer server = new RemoteCacheServer( rcsa );
+
+        String cacheName = "testSimpleRegisterListenerAndPut";
+        server.addCacheListener( cacheName, mockListener );
+
+        // DO WORK
+        int numToPut = 10;
+
+        for ( int i = 0; i < numToPut; i++ )
+        {
+            // use a junk listener id
+            server.remove( cacheName, String.valueOf( i ), 9999 );
+        }
+
+        Thread.sleep( 100 );
+        Thread.yield();
+        Thread.sleep( 100 );
+
+        // VERIFY
+        assertEquals( "Wrong number of items removed from listener.", numToPut, mockListener.removedKeys.size()
);
+        for ( int i = 0; i < numToPut; i++ )
+        {
+            assertEquals( "Wrong key.", String.valueOf( i ), mockListener.removedKeys.get(
i ) );
+        }
+    }
+
+}



---------------------------------------------------------------------
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