svn commit: r647264 [5/6] - in /jakarta/jcs/trunk: ./ src/java/org/apache/jcs/access/ src/java/org/apache/jcs/access/behavior/ src/java/org/apache/jcs/auxiliary/ src/java/org/apache/jcs/auxiliary/disk/ src/java/org/apache/jcs/auxiliary/lateral/ src/jav...

[email protected]
Newsgroups gmane.comp.jakarta.turbine.jcs.devel
Message-ID <[email protected]>
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheServiceMockImpl.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheServiceMockImpl.java?rev=647264&r1=647263&r2=647264&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheServiceMockImpl.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheServiceMockImpl.java Fri Apr 11 11:43:26 2008
@@ -1,170 +1,186 @@
-package org.apache.jcs.auxiliary.remote;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.rmi.RemoteException;
-import java.util.Set;
-
-import org.apache.jcs.access.exception.ObjectExistsException;
-import org.apache.jcs.access.exception.ObjectNotFoundException;
-import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService;
-import org.apache.jcs.engine.behavior.ICacheElement;
-
-/**
- * This is a mock impl of the remote cache service.
- * <p>
- * @author admin
- */
-public class RemoteCacheServiceMockImpl
-    implements IRemoteCacheService
-{
-    /** The object that was last passed to update. */
-    public Object lastUpdate;
-
-    /** The key that was last passed to remove. */
-    public Object lastRemoveKey;
-
-    /**
-     * The cache name that was last passed to removeAll.
-     */
-    public String lastRemoveAllCacheName;
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#get(java.lang.String,
-     *      java.io.Serializable, long)
-     */
-    public ICacheElement get( String cacheName, Serializable key, long requesterId )
-        throws IOException
-    {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#getGroupKeys(java.lang.String,
-     *      java.lang.String)
-     */
-    public Set getGroupKeys( String cacheName, String groupName )
-        throws RemoteException
-    {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#remove(java.lang.String,
-     *      java.io.Serializable, long)
-     */
-    public void remove( String cacheName, Serializable key, long requesterId )
-        throws IOException
-    {
-        lastRemoveKey = key;
-    }
-
-    /**
-     * Set the lastRemoveAllCacheName to the cacheName.
-     * <p>
-     * (non-Javadoc)
-     * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#removeAll(java.lang.String,
-     *      long)
-     */
-    public void removeAll( String cacheName, long requesterId )
-        throws IOException
-    {
-        lastRemoveAllCacheName = cacheName;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#update(org.apache.jcs.engine.behavior.ICacheElement,
-     *      long)
-     */
-    public void update( ICacheElement item, long requesterId )
-        throws ObjectExistsException, IOException
-    {
-        lastUpdate = item;
-    }
-
-    public void dispose( String cacheName )
-        throws IOException
-    {
-        // TODO Auto-generated method stub
-
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.jcs.engine.behavior.ICacheService#get(java.lang.String, java.io.Serializable)
-     */
-    public ICacheElement get( String cacheName, Serializable key )
-        throws ObjectNotFoundException, IOException
-    {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.jcs.engine.behavior.ICacheService#release()
-     */
-    public void release()
-        throws IOException
-    {
-        // TODO Auto-generated method stub
-
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.jcs.engine.behavior.ICacheService#remove(java.lang.String,
-     *      java.io.Serializable)
-     */
-    public void remove( String cacheName, Serializable key )
-        throws IOException
-    {
-        lastRemoveKey = key;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.jcs.engine.behavior.ICacheService#removeAll(java.lang.String)
-     */
-    public void removeAll( String cacheName )
-        throws IOException
-    {
-        lastRemoveAllCacheName = cacheName;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.jcs.engine.behavior.ICacheService#update(org.apache.jcs.engine.behavior.ICacheElement)
-     */
-    public void update( ICacheElement item )
-        throws ObjectExistsException, IOException
-    {
-        lastUpdate = item;
-    }
-
-}
+package org.apache.jcs.auxiliary.remote;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+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;
+
+    /**
+     * @param cacheName 
+     * @param key 
+     * @param requesterId 
+     * @return null
+     */
+    public ICacheElement get( String cacheName, Serializable key, long requesterId )
+    {
+        return null;
+    }
+
+    /**
+     * @param cacheName 
+     * @param groupName 
+     * @return empty set 
+     */
+    public Set getGroupKeys( String cacheName, String groupName )
+    {
+        return new HashSet();
+    }
+
+    /**
+     * Set the last remove key.
+     * <p>
+     * @param cacheName 
+     * @param key 
+     * @param requesterId 
+     */
+    public void remove( String cacheName, Serializable key, long requesterId )
+    {
+        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;
+    }
+
+    /**
+     * Set the last update item.
+     * <p>
+     * @param item 
+     * @param requesterId 
+     */
+    public void update( ICacheElement item, long requesterId )
+    {
+        lastUpdate = item;
+    }
+
+    /**
+     * Do nothing.
+     * <p>
+     * @param cacheName 
+     */
+    public void dispose( String cacheName )
+    {
+        return;
+    }
+
+    /**
+     * @param cacheName 
+     * @param key 
+     * @return null
+     */
+    public ICacheElement get( String cacheName, Serializable key )
+    {
+        return null;
+    }
+
+    /**
+     * Do nothing.
+     */
+    public void release()
+    {
+        return;
+    }
+
+    /**
+     * Set the last remove key.
+     * <p>
+     * @param cacheName 
+     * @param key 
+     */
+    public void remove( String cacheName, Serializable key )
+    {
+        lastRemoveKey = key;
+    }
+
+    /**
+     * Set the last remove all cache name.
+     * <p>
+     * @param cacheName 
+     */
+    public void removeAll( String cacheName )
+    {
+        lastRemoveAllCacheName = cacheName;
+    }
+
+    /**
+     * Set the last update item.
+     * <p>
+     * @param item 
+     */
+    public void update( ICacheElement item )
+    {
+        lastUpdate = item;
+    }
+
+    /**
+     * @param cacheName 
+     * @param keys 
+     * @param requesterId 
+     * @return empty map
+     */
+    public Map getMultiple( String cacheName, Set keys, long requesterId )
+    {
+        return new HashMap();
+    }
+
+    /**
+     * @param cacheName 
+     * @param keys 
+     * @return empty map
+     */
+    public Map getMultiple( String cacheName, Set keys )
+    {
+        return new HashMap();
+    }
+
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java?rev=647264&r1=647263&r2=647264&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java Fri Apr 11 11:43:26 2008
@@ -1,220 +1,221 @@
-package org.apache.jcs.auxiliary.remote.server;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.auxiliary.AuxiliaryCache;
-import org.apache.jcs.auxiliary.remote.RemoteCacheAttributes;
-import org.apache.jcs.auxiliary.remote.RemoteCacheListenerMockImpl;
-import org.apache.jcs.auxiliary.remote.RemoteCacheManager;
-import org.apache.jcs.engine.CacheElement;
-import org.apache.jcs.engine.behavior.ICacheElement;
-import org.apache.jcs.engine.control.CompositeCacheManagerMockImpl;
-import org.apache.jcs.utils.timing.SleepUtil;
-
-/**
- * These tests startup the remote server and make requests to it.
- * <p>
- * @author Aaron Smuts
- */
-public class BasicRemoteCacheClientServerUnitTest
-    extends TestCase
-{
-    RemoteCacheServer server = null;
-
-    /**
-     * Starts the server. This is not in a setup, since the server is slow to kill right now.
-     */
-    public BasicRemoteCacheClientServerUnitTest()
-    {
-        String configFile = "TestRemoteCacheClientServer.ccf";
-        server = RemoteCacheServerStartupUtil.startServerUsingProperties( configFile );
-    }
-
-    /**
-     * Verify that we can start the remote cache server. Send an item to the remote. Verify that the
-     * remote put count goes up. If we go through JCS, the manager will be shared and we will get
-     * into an endless loop. We will use a mock cache manager instead.
-     * <p>
-     * The remote server uses the real JCS. We can verify that items are added to JCS behind the
-     * server by calling get. We cannot access it directly via JCS since it is serialized.
-     * <p>
-     * This test uses a mock injected client to test a normal server.
-     * <p>
-     * @throws Exception
-     */
-    public void testSinglePut()
-        throws Exception
-    {
-        // SETUP
-        CompositeCacheManagerMockImpl compositeCacheManager = new CompositeCacheManagerMockImpl();
-
-        RemoteCacheAttributes attributes = new RemoteCacheAttributes();
-        attributes.setRemoteHost( "localhost" );
-        attributes.setLocalPort( 1202 );
-        attributes.setRemotePort( 1101 );
-
-        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes, compositeCacheManager );
-        String regionName = "testSinglePut";
-        AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
-
-        // DO WORK
-        int numPutsPrior = server.getPutCount();
-        ICacheElement element = new CacheElement( regionName, "key", "value" );
-        cache.update( element );
-        SleepUtil.sleepAtLeast( 50 );
-
-        // VERIFY
-        System.out.println( server.getStats() );
-        assertEquals( "Wrong number of puts", 1, server.getPutCount() - numPutsPrior );
-
-        // DO WORK
-        ICacheElement result = cache.get( "key" );
-
-        // VERIFY
-        assertEquals( "Wrong element.", element.getVal(), result.getVal() );
-    }
-
-    /**
-     * Verify that we can remove an item via the remote server.
-     * <p>
-     * @throws Exception
-     */
-    public void testPutRemove()
-        throws Exception
-    {
-        // SETUP
-        CompositeCacheManagerMockImpl compositeCacheManager = new CompositeCacheManagerMockImpl();
-
-        RemoteCacheAttributes attributes = new RemoteCacheAttributes();
-        attributes.setRemoteHost( "localhost" );
-        attributes.setLocalPort( 1202 );
-        attributes.setRemotePort( 1101 );
-
-        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes, compositeCacheManager );
-        String regionName = "testPutRemove";
-        AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
-
-        // DO WORK
-        int numPutsPrior = server.getPutCount();
-        ICacheElement element = new CacheElement( regionName, "key", "value" );
-        cache.update( element );
-        SleepUtil.sleepAtLeast( 50 );
-
-        // VERIFY
-        System.out.println( server.getStats() );
-        assertEquals( "Wrong number of puts", 1, server.getPutCount() - numPutsPrior );
-
-        // DO WORK
-        ICacheElement result = cache.get( "key" );
-
-        // VERIFY
-        assertEquals( "Wrong element.", element.getVal(), result.getVal() );
-
-        // DO WORK
-        cache.remove( "key" );
-        SleepUtil.sleepAtLeast( 50 );
-        ICacheElement resultAfterRemote = cache.get( "key" );
-
-        // VERIFY
-        assertNull( "Element resultAfterRemote should be null.", resultAfterRemote );
-    }
-
-    /**
-     * Register a listener with the server. Send an update. Verify that the listener received it.
-     * @throws Exception
-     */
-    public void testPutAndListen()
-        throws Exception
-    {
-        // SETUP
-        CompositeCacheManagerMockImpl compositeCacheManager = new CompositeCacheManagerMockImpl();
-
-        RemoteCacheAttributes attributes = new RemoteCacheAttributes();
-        attributes.setRemoteHost( "localhost" );
-        attributes.setLocalPort( 1202 );
-        attributes.setRemotePort( 1101 );
-
-        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes, compositeCacheManager );
-        String regionName = "testPutAndListen";
-        AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
-
-        RemoteCacheListenerMockImpl listener = new RemoteCacheListenerMockImpl();
-        server.addCacheListener( regionName, listener );
-
-        // DO WORK
-        int numPutsPrior = server.getPutCount();
-        ICacheElement element = new CacheElement( regionName, "key", "value" );
-        cache.update( element );
-        SleepUtil.sleepAtLeast( 50 );
-
-        // VERIFY
-        try
-        {
-            System.out.println( server.getStats() );
-            assertEquals( "Wrong number of puts", 1, server.getPutCount() - numPutsPrior );
-            assertEquals( "Wrong number of puts to listener.", 1, listener.putCount );
-        }
-        finally
-        {
-            // remove from all regions.
-            server.removeCacheListener( listener );
-        }
-    }
-
-    /**
-     * Register a listener with the server. Send an update. Verify that the listener received it.
-     * @throws Exception
-     */
-    public void testPutaMultipleAndListen()
-        throws Exception
-    {
-        // SETUP
-        CompositeCacheManagerMockImpl compositeCacheManager = new CompositeCacheManagerMockImpl();
-
-        RemoteCacheAttributes attributes = new RemoteCacheAttributes();
-        attributes.setRemoteHost( "localhost" );
-        attributes.setLocalPort( 1202 );
-        attributes.setRemotePort( 1101 );
-
-        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes, compositeCacheManager );
-        String regionName = "testPutAndListen";
-        AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
-
-        RemoteCacheListenerMockImpl listener = new RemoteCacheListenerMockImpl();
-        server.addCacheListener( regionName, listener );
-
-        // DO WORK
-        int numPutsPrior = server.getPutCount();
-        int numToPut = 100;
-        for ( int i = 0; i < numToPut; i++ )
-        {
-            ICacheElement element = new CacheElement( regionName, "key" + 1, "value" + i );
-            cache.update( element );
-        }
-        SleepUtil.sleepAtLeast( 500 );
-
-        // VERIFY
-        System.out.println( server.getStats() );
-        assertEquals( "Wrong number of puts", numToPut, server.getPutCount() - numPutsPrior );
-        assertEquals( "Wrong number of puts to listener.", numToPut, listener.putCount );
-    }
-}
+package org.apache.jcs.auxiliary.remote.server;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.auxiliary.AuxiliaryCache;
+import org.apache.jcs.auxiliary.remote.RemoteCacheAttributes;
+import org.apache.jcs.auxiliary.remote.RemoteCacheListenerMockImpl;
+import org.apache.jcs.auxiliary.remote.RemoteCacheManager;
+import org.apache.jcs.engine.CacheElement;
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.control.CompositeCacheManagerMockImpl;
+import org.apache.jcs.utils.timing.SleepUtil;
+
+/**
+ * These tests startup the remote server and make requests to it.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class BasicRemoteCacheClientServerUnitTest
+    extends TestCase
+{
+    /** Server instance to use in the tests. */
+    private RemoteCacheServer server = null;
+
+    /**
+     * Starts the server. This is not in a setup, since the server is slow to kill right now.
+     */
+    public BasicRemoteCacheClientServerUnitTest()
+    {
+        String configFile = "TestRemoteCacheClientServer.ccf";
+        server = RemoteCacheServerStartupUtil.startServerUsingProperties( configFile );
+    }
+
+    /**
+     * Verify that we can start the remote cache server. Send an item to the remote. Verify that the
+     * remote put count goes up. If we go through JCS, the manager will be shared and we will get
+     * into an endless loop. We will use a mock cache manager instead.
+     * <p>
+     * The remote server uses the real JCS. We can verify that items are added to JCS behind the
+     * server by calling get. We cannot access it directly via JCS since it is serialized.
+     * <p>
+     * This test uses a mock injected client to test a normal server.
+     * <p>
+     * @throws Exception
+     */
+    public void testSinglePut()
+        throws Exception
+    {
+        // SETUP
+        CompositeCacheManagerMockImpl compositeCacheManager = new CompositeCacheManagerMockImpl();
+
+        RemoteCacheAttributes attributes = new RemoteCacheAttributes();
+        attributes.setRemoteHost( "localhost" );
+        attributes.setLocalPort( 1202 );
+        attributes.setRemotePort( 1101 );
+
+        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes, compositeCacheManager );
+        String regionName = "testSinglePut";
+        AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
+
+        // DO WORK
+        int numPutsPrior = server.getPutCount();
+        ICacheElement element = new CacheElement( regionName, "key", "value" );
+        cache.update( element );
+        SleepUtil.sleepAtLeast( 50 );
+
+        // VERIFY
+        System.out.println( server.getStats() );
+        assertEquals( "Wrong number of puts", 1, server.getPutCount() - numPutsPrior );
+
+        // DO WORK
+        ICacheElement result = cache.get( "key" );
+
+        // VERIFY
+        assertEquals( "Wrong element.", element.getVal(), result.getVal() );
+    }
+
+    /**
+     * Verify that we can remove an item via the remote server.
+     * <p>
+     * @throws Exception
+     */
+    public void testPutRemove()
+        throws Exception
+    {
+        // SETUP
+        CompositeCacheManagerMockImpl compositeCacheManager = new CompositeCacheManagerMockImpl();
+
+        RemoteCacheAttributes attributes = new RemoteCacheAttributes();
+        attributes.setRemoteHost( "localhost" );
+        attributes.setLocalPort( 1202 );
+        attributes.setRemotePort( 1101 );
+
+        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes, compositeCacheManager );
+        String regionName = "testPutRemove";
+        AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
+
+        // DO WORK
+        int numPutsPrior = server.getPutCount();
+        ICacheElement element = new CacheElement( regionName, "key", "value" );
+        cache.update( element );
+        SleepUtil.sleepAtLeast( 50 );
+
+        // VERIFY
+        System.out.println( server.getStats() );
+        assertEquals( "Wrong number of puts", 1, server.getPutCount() - numPutsPrior );
+
+        // DO WORK
+        ICacheElement result = cache.get( "key" );
+
+        // VERIFY
+        assertEquals( "Wrong element.", element.getVal(), result.getVal() );
+
+        // DO WORK
+        cache.remove( "key" );
+        SleepUtil.sleepAtLeast( 50 );
+        ICacheElement resultAfterRemote = cache.get( "key" );
+
+        // VERIFY
+        assertNull( "Element resultAfterRemote should be null.", resultAfterRemote );
+    }
+
+    /**
+     * Register a listener with the server. Send an update. Verify that the listener received it.
+     * @throws Exception
+     */
+    public void testPutAndListen()
+        throws Exception
+    {
+        // SETUP
+        CompositeCacheManagerMockImpl compositeCacheManager = new CompositeCacheManagerMockImpl();
+
+        RemoteCacheAttributes attributes = new RemoteCacheAttributes();
+        attributes.setRemoteHost( "localhost" );
+        attributes.setLocalPort( 1202 );
+        attributes.setRemotePort( 1101 );
+
+        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes, compositeCacheManager );
+        String regionName = "testPutAndListen";
+        AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
+
+        RemoteCacheListenerMockImpl listener = new RemoteCacheListenerMockImpl();
+        server.addCacheListener( regionName, listener );
+
+        // DO WORK
+        int numPutsPrior = server.getPutCount();
+        ICacheElement element = new CacheElement( regionName, "key", "value" );
+        cache.update( element );
+        SleepUtil.sleepAtLeast( 50 );
+
+        // VERIFY
+        try
+        {
+            System.out.println( server.getStats() );
+            assertEquals( "Wrong number of puts", 1, server.getPutCount() - numPutsPrior );
+            assertEquals( "Wrong number of puts to listener.", 1, listener.putCount );
+        }
+        finally
+        {
+            // remove from all regions.
+            server.removeCacheListener( listener );
+        }
+    }
+
+    /**
+     * Register a listener with the server. Send an update. Verify that the listener received it.
+     * @throws Exception
+     */
+    public void testPutaMultipleAndListen()
+        throws Exception
+    {
+        // SETUP
+        CompositeCacheManagerMockImpl compositeCacheManager = new CompositeCacheManagerMockImpl();
+
+        RemoteCacheAttributes attributes = new RemoteCacheAttributes();
+        attributes.setRemoteHost( "localhost" );
+        attributes.setLocalPort( 1202 );
+        attributes.setRemotePort( 1101 );
+
+        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes, compositeCacheManager );
+        String regionName = "testPutAndListen";
+        AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
+
+        RemoteCacheListenerMockImpl listener = new RemoteCacheListenerMockImpl();
+        server.addCacheListener( regionName, listener );
+
+        // DO WORK
+        int numPutsPrior = server.getPutCount();
+        int numToPut = 100;
+        for ( int i = 0; i < numToPut; i++ )
+        {
+            ICacheElement element = new CacheElement( regionName, "key" + 1, "value" + i );
+            cache.update( element );
+        }
+        SleepUtil.sleepAtLeast( 500 );
+
+        // VERIFY
+        System.out.println( server.getStats() );
+        assertEquals( "Wrong number of puts", numToPut, server.getPutCount() - numPutsPrior );
+        assertEquals( "Wrong number of puts to listener.", numToPut, listener.putCount );
+    }
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java?rev=647264&r1=647263&r2=647264&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java Fri Apr 11 11:43:26 2008
@@ -1,448 +1,465 @@
-package org.apache.jcs.engine.control;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.Set;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-import org.apache.jcs.access.exception.CacheException;
-import org.apache.jcs.auxiliary.AuxiliaryCache;
-import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
-import org.apache.jcs.engine.CacheElement;
-import org.apache.jcs.engine.CompositeCacheAttributes;
-import org.apache.jcs.engine.ElementAttributes;
-import org.apache.jcs.engine.behavior.ICacheElement;
-import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
-import org.apache.jcs.engine.behavior.IElementAttributes;
-import org.apache.jcs.engine.stats.behavior.IStats;
-
-/**
- * Tests of the disk usage settings for the CompositeCache.
- * <p>
- * @author Aaron Smuts
- */
-public class CompositeCacheDiskUsageUnitTest
-    extends TestCase
-{
-    /**
-     * Test setup
-     */
-    public void setUp()
-    {
-        JCS.setConfigFilename( "/TestDiskCacheUsagePattern.ccf" );
-    }
-
-    /**
-     * Verify that the swap region is set to the correct pattern.
-     * <p>
-     * @throws CacheException
-     */
-    public void testSwapConfig() throws CacheException
-    {
-        JCS swap = JCS.getInstance( "Swap" );
-        assertEquals( ICompositeCacheAttributes.DISK_USAGE_PATTERN_SWAP, swap.getCacheAttributes().getDiskUsagePattern() );
-    }
-
-    /**
-     * Verify that the swap region is set to the correct pattern.
-     * <p>
-     * @throws CacheException
-     */
-    public void testUpdateConfig() throws CacheException
-    {
-        JCS swap = JCS.getInstance( "Update" );
-        assertEquals( ICompositeCacheAttributes.DISK_USAGE_PATTERN_UPDATE, swap.getCacheAttributes().getDiskUsagePattern() );
-    }
-
-    /**
-     * Setup a disk cache. Configure the disk usage pattern to swap. Call spool. Verify that the
-     * item is put to disk.
-     */
-    public void testSpoolAllowed()
-    {
-        // SETUP
-        ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
-        cattr.setDiskUsagePattern( ICompositeCacheAttributes.DISK_USAGE_PATTERN_SWAP );
-
-        IElementAttributes attr = new ElementAttributes();
-
-        CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr, attr );
-
-        MockAuxCache mock = new MockAuxCache();
-        mock.cacheType = AuxiliaryCache.DISK_CACHE;
-
-        cache.setAuxCaches( new AuxiliaryCache[] { mock } );
-
-        ICacheElement inputElement = new CacheElement( "testSpoolAllowed", "key", "value" );
-
-        // DO WORK
-        cache.spoolToDisk( inputElement );
-
-        // VERIFY
-        assertEquals( "Wrong number of calls to the disk cache update.", 1, mock.updateCount );
-        assertEquals( "Wrong element updated.", inputElement, mock.lastUpdatedItem );
-    }
-
-    /**
-     * Setup a disk cache. Configure the disk usage pattern to not swap. Call spool. Verify that the
-     * item is not put to disk.
-     */
-    public void testSpoolNotAllowed()
-    {
-        // SETUP
-        ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
-        cattr.setDiskUsagePattern( ICompositeCacheAttributes.DISK_USAGE_PATTERN_UPDATE );
-
-        IElementAttributes attr = new ElementAttributes();
-
-        CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr, attr );
-
-        MockAuxCache mock = new MockAuxCache();
-        mock.cacheType = AuxiliaryCache.DISK_CACHE;
-
-        cache.setAuxCaches( new AuxiliaryCache[] { mock } );
-
-        ICacheElement inputElement = new CacheElement( "testSpoolAllowed", "key", "value" );
-
-        // DO WORK
-        cache.spoolToDisk( inputElement );
-
-        // VERIFY
-        assertEquals( "Wrong number of calls to the disk cache update.", 0, mock.updateCount );
-    }
-
-    /**
-     * Setup a disk cache. Configure the disk usage pattern to UPDATE. Call updateAuxiliaries.
-     * Verify that the item is put to disk.
-     * <p>
-     * This tests that the items are put to disk on a normal put when the usage pattern is set
-     * appropriately.
-     * @throws IOException
-     */
-    public void testUpdateAllowed()
-        throws IOException
-    {
-        // SETUP
-        ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
-        cattr.setDiskUsagePattern( ICompositeCacheAttributes.DISK_USAGE_PATTERN_UPDATE );
-
-        IElementAttributes attr = new ElementAttributes();
-
-        CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr, attr );
-
-        MockAuxCache mock = new MockAuxCache();
-        mock.cacheType = AuxiliaryCache.DISK_CACHE;
-
-        cache.setAuxCaches( new AuxiliaryCache[] { mock } );
-
-        ICacheElement inputElement = new CacheElement( "testSpoolAllowed", "key", "value" );
-
-        // DO WORK
-        cache.updateAuxiliaries( inputElement, true );
-
-        // VERIFY
-        assertEquals( "Wrong number of calls to the disk cache update.", 1, mock.updateCount );
-        assertEquals( "Wrong element updated.", inputElement, mock.lastUpdatedItem );
-    }
-
-    /**
-     * Setup a disk cache. Configure the disk usage pattern to UPDATE. Call updateAuxiliaries with
-     * local only set to false. Verify that the item is put to disk.
-     * <p>
-     * This tests that the items are put to disk on a normal put when the usage pattern is set
-     * appropriately. The local setting should have no impact on whether the item goes to disk.
-     * <p>
-     * @throws IOException
-     */
-    public void testUpdateAllowed_localFalse()
-        throws IOException
-    {
-        // SETUP
-        ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
-        cattr.setDiskUsagePattern( ICompositeCacheAttributes.DISK_USAGE_PATTERN_UPDATE );
-
-        IElementAttributes attr = new ElementAttributes();
-
-        CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr, attr );
-
-        MockAuxCache mock = new MockAuxCache();
-        mock.cacheType = AuxiliaryCache.DISK_CACHE;
-
-        cache.setAuxCaches( new AuxiliaryCache[] { mock } );
-
-        ICacheElement inputElement = new CacheElement( "testSpoolAllowed", "key", "value" );
-
-        // DO WORK
-        cache.updateAuxiliaries( inputElement, false );
-
-        // VERIFY
-        assertEquals( "Wrong number of calls to the disk cache update.", 1, mock.updateCount );
-        assertEquals( "Wrong element updated.", inputElement, mock.lastUpdatedItem );
-    }
-
-    /**
-     * Setup a disk cache. Configure the disk usage pattern to SWAP. Call updateAuxiliaries. Verify
-     * that the item is not put to disk.
-     * <p>
-     * This tests that the items are not put to disk on a normal put when the usage pattern is set
-     * to SWAP.
-     * <p>
-     * @throws IOException
-     */
-    public void testUpdateNotAllowed()
-        throws IOException
-    {
-        // SETUP
-        ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
-        cattr.setDiskUsagePattern( ICompositeCacheAttributes.DISK_USAGE_PATTERN_SWAP );
-
-        IElementAttributes attr = new ElementAttributes();
-
-        CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr, attr );
-
-        MockAuxCache mock = new MockAuxCache();
-        mock.cacheType = AuxiliaryCache.DISK_CACHE;
-
-        cache.setAuxCaches( new AuxiliaryCache[] { mock } );
-
-        ICacheElement inputElement = new CacheElement( "testSpoolAllowed", "key", "value" );
-
-        // DO WORK
-        cache.updateAuxiliaries( inputElement, true );
-
-        // VERIFY
-        assertEquals( "Wrong number of calls to the disk cache update.", 0, mock.updateCount );
-    }
-
-    /**
-     * Setup a disk cache. Configure the disk usage pattern to UPDATE. Call updateAuxiliaries.
-     * Verify that the item is put to disk.
-     * <p>
-     * This tests that the items are put to disk on a normal put when the usage pattern is set
-     * appropriately.
-     * @throws IOException
-     */
-    public void testUpdateAllowed_withOtherCaches()
-        throws IOException
-    {
-        // SETUP
-        ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
-        cattr.setDiskUsagePattern( ICompositeCacheAttributes.DISK_USAGE_PATTERN_UPDATE );
-
-        IElementAttributes attr = new ElementAttributes();
-
-        CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr, attr );
-
-        MockAuxCache mock = new MockAuxCache();
-        mock.cacheType = AuxiliaryCache.DISK_CACHE;
-
-        MockAuxCache mockLateral = new MockAuxCache();
-        mockLateral.cacheType = AuxiliaryCache.LATERAL_CACHE;
-
-        cache.setAuxCaches( new AuxiliaryCache[] { mock, mockLateral } );
-
-        ICacheElement inputElement = new CacheElement( "testSpoolAllowed", "key", "value" );
-
-        // DO WORK
-        cache.updateAuxiliaries( inputElement, false );
-
-        // VERIFY
-        assertEquals( "Wrong number of calls to the disk cache update.", 1, mock.updateCount );
-        assertEquals( "Wrong element updated.", inputElement, mock.lastUpdatedItem );
-
-        assertEquals( "Wrong number of calls to the lateral cache update.", 1, mockLateral.updateCount );
-        assertEquals( "Wrong element updated with lateral.", inputElement, mockLateral.lastUpdatedItem );
-    }
-
-    /**
-     * Used to test the disk cache functionality.
-     * <p>
-     * @author Aaron Smuts
-     */
-    public class MockAuxCache
-        implements AuxiliaryCache
-    {
-        private static final long serialVersionUID = 1L;
-
-        /**
-         * The last item passed to update.
-         */
-        public ICacheElement lastUpdatedItem;
-
-        /**
-         * The number of times update was called.
-         */
-        public int updateCount = 0;
-
-        /**
-         * The type that should be returned from getCacheType.
-         */
-        public int cacheType = AuxiliaryCache.DISK_CACHE;
-
-        /**
-         * Resets counters and catchers.
-         */
-        public void reset()
-        {
-            updateCount = 0;
-            lastUpdatedItem = null;
-        }
-
-        /*
-         * (non-Javadoc)
-         * @see org.apache.jcs.auxiliary.AuxiliaryCache#update(org.apache.jcs.engine.behavior.ICacheElement)
-         */
-        public void update( ICacheElement ce )
-            throws IOException
-        {
-            lastUpdatedItem = ce;
-            updateCount++;
-        }
-
-        /*
-         * (non-Javadoc)
-         * @see org.apache.jcs.auxiliary.AuxiliaryCache#get(java.io.Serializable)
-         */
-        public ICacheElement get( Serializable key )
-            throws IOException
-        {
-            // TODO Auto-generated method stub
-            return null;
-        }
-
-        /*
-         * (non-Javadoc)
-         * @see org.apache.jcs.auxiliary.AuxiliaryCache#remove(java.io.Serializable)
-         */
-        public boolean remove( Serializable key )
-            throws IOException
-        {
-            // TODO Auto-generated method stub
-            return false;
-        }
-
-        /*
-         * (non-Javadoc)
-         * @see org.apache.jcs.auxiliary.AuxiliaryCache#removeAll()
-         */
-        public void removeAll()
-            throws IOException
-        {
-            // TODO Auto-generated method stub
-
-        }
-
-        /*
-         * (non-Javadoc)
-         * @see org.apache.jcs.auxiliary.AuxiliaryCache#dispose()
-         */
-        public void dispose()
-            throws IOException
-        {
-            // TODO Auto-generated method stub
-
-        }
-
-        /*
-         * (non-Javadoc)
-         * @see org.apache.jcs.auxiliary.AuxiliaryCache#getSize()
-         */
-        public int getSize()
-        {
-            // TODO Auto-generated method stub
-            return 0;
-        }
-
-        /*
-         * (non-Javadoc)
-         * @see org.apache.jcs.auxiliary.AuxiliaryCache#getStatus()
-         */
-        public int getStatus()
-        {
-            // TODO Auto-generated method stub
-            return 0;
-        }
-
-        /*
-         * (non-Javadoc)
-         * @see org.apache.jcs.auxiliary.AuxiliaryCache#getCacheName()
-         */
-        public String getCacheName()
-        {
-            // TODO Auto-generated method stub
-            return null;
-        }
-
-        /*
-         * (non-Javadoc)
-         * @see org.apache.jcs.auxiliary.AuxiliaryCache#getGroupKeys(java.lang.String)
-         */
-        public Set getGroupKeys( String group )
-            throws IOException
-        {
-            // TODO Auto-generated method stub
-            return null;
-        }
-
-        /*
-         * (non-Javadoc)
-         * @see org.apache.jcs.auxiliary.AuxiliaryCache#getStatistics()
-         */
-        public IStats getStatistics()
-        {
-            // TODO Auto-generated method stub
-            return null;
-        }
-
-        /*
-         * (non-Javadoc)
-         * @see org.apache.jcs.engine.behavior.ICache#getStats()
-         */
-        public String getStats()
-        {
-            // TODO Auto-generated method stub
-            return null;
-        }
-
-        /**
-         * Returns the setup cache type. This allows you to use this mock as multiple cache types.
-         * <p>
-         * (non-Javadoc)
-         * @see org.apache.jcs.engine.behavior.ICacheType#getCacheType()
-         */
-        public int getCacheType()
-        {
-            return cacheType;
-        }
-
-        /**
-         * @return Returns the AuxiliaryCacheAttributes.
-         */
-        public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
-        {
-            return null;
-        }
-    }
-
-}
+package org.apache.jcs.engine.control;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+import org.apache.jcs.access.exception.CacheException;
+import org.apache.jcs.auxiliary.AuxiliaryCache;
+import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
+import org.apache.jcs.engine.CacheElement;
+import org.apache.jcs.engine.CompositeCacheAttributes;
+import org.apache.jcs.engine.ElementAttributes;
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
+import org.apache.jcs.engine.behavior.IElementAttributes;
+import org.apache.jcs.engine.stats.behavior.IStats;
+
+/**
+ * Tests of the disk usage settings for the CompositeCache.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class CompositeCacheDiskUsageUnitTest
+    extends TestCase
+{
+    /**
+     * Test setup
+     */
+    public void setUp()
+    {
+        JCS.setConfigFilename( "/TestDiskCacheUsagePattern.ccf" );
+    }
+
+    /**
+     * Verify that the swap region is set to the correct pattern.
+     * <p>
+     * @throws CacheException
+     */
+    public void testSwapConfig()
+        throws CacheException
+    {
+        JCS swap = JCS.getInstance( "Swap" );
+        assertEquals( ICompositeCacheAttributes.DISK_USAGE_PATTERN_SWAP, swap.getCacheAttributes()
+            .getDiskUsagePattern() );
+    }
+
+    /**
+     * Verify that the swap region is set to the correct pattern.
+     * <p>
+     * @throws CacheException
+     */
+    public void testUpdateConfig()
+        throws CacheException
+    {
+        JCS swap = JCS.getInstance( "Update" );
+        assertEquals( ICompositeCacheAttributes.DISK_USAGE_PATTERN_UPDATE, swap.getCacheAttributes()
+            .getDiskUsagePattern() );
+    }
+
+    /**
+     * Setup a disk cache. Configure the disk usage pattern to swap. Call spool. Verify that the
+     * item is put to disk.
+     */
+    public void testSpoolAllowed()
+    {
+        // SETUP
+        ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+        cattr.setDiskUsagePattern( ICompositeCacheAttributes.DISK_USAGE_PATTERN_SWAP );
+
+        IElementAttributes attr = new ElementAttributes();
+
+        CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr, attr );
+
+        MockAuxCache mock = new MockAuxCache();
+        mock.cacheType = AuxiliaryCache.DISK_CACHE;
+
+        cache.setAuxCaches( new AuxiliaryCache[] { mock } );
+
+        ICacheElement inputElement = new CacheElement( "testSpoolAllowed", "key", "value" );
+
+        // DO WORK
+        cache.spoolToDisk( inputElement );
+
+        // VERIFY
+        assertEquals( "Wrong number of calls to the disk cache update.", 1, mock.updateCount );
+        assertEquals( "Wrong element updated.", inputElement, mock.lastUpdatedItem );
+    }
+
+    /**
+     * Setup a disk cache. Configure the disk usage pattern to not swap. Call spool. Verify that the
+     * item is not put to disk.
+     */
+    public void testSpoolNotAllowed()
+    {
+        // SETUP
+        ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+        cattr.setDiskUsagePattern( ICompositeCacheAttributes.DISK_USAGE_PATTERN_UPDATE );
+
+        IElementAttributes attr = new ElementAttributes();
+
+        CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr, attr );
+
+        MockAuxCache mock = new MockAuxCache();
+        mock.cacheType = AuxiliaryCache.DISK_CACHE;
+
+        cache.setAuxCaches( new AuxiliaryCache[] { mock } );
+
+        ICacheElement inputElement = new CacheElement( "testSpoolAllowed", "key", "value" );
+
+        // DO WORK
+        cache.spoolToDisk( inputElement );
+
+        // VERIFY
+        assertEquals( "Wrong number of calls to the disk cache update.", 0, mock.updateCount );
+    }
+
+    /**
+     * Setup a disk cache. Configure the disk usage pattern to UPDATE. Call updateAuxiliaries.
+     * Verify that the item is put to disk.
+     * <p>
+     * This tests that the items are put to disk on a normal put when the usage pattern is set
+     * appropriately.
+     * @throws IOException
+     */
+    public void testUpdateAllowed()
+        throws IOException
+    {
+        // SETUP
+        ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+        cattr.setDiskUsagePattern( ICompositeCacheAttributes.DISK_USAGE_PATTERN_UPDATE );
+
+        IElementAttributes attr = new ElementAttributes();
+
+        CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr, attr );
+
+        MockAuxCache mock = new MockAuxCache();
+        mock.cacheType = AuxiliaryCache.DISK_CACHE;
+
+        cache.setAuxCaches( new AuxiliaryCache[] { mock } );
+
+        ICacheElement inputElement = new CacheElement( "testSpoolAllowed", "key", "value" );
+
+        // DO WORK
+        cache.updateAuxiliaries( inputElement, true );
+
+        // VERIFY
+        assertEquals( "Wrong number of calls to the disk cache update.", 1, mock.updateCount );
+        assertEquals( "Wrong element updated.", inputElement, mock.lastUpdatedItem );
+    }
+
+    /**
+     * Setup a disk cache. Configure the disk usage pattern to UPDATE. Call updateAuxiliaries with
+     * local only set to false. Verify that the item is put to disk.
+     * <p>
+     * This tests that the items are put to disk on a normal put when the usage pattern is set
+     * appropriately. The local setting should have no impact on whether the item goes to disk.
+     * <p>
+     * @throws IOException
+     */
+    public void testUpdateAllowed_localFalse()
+        throws IOException
+    {
+        // SETUP
+        ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+        cattr.setDiskUsagePattern( ICompositeCacheAttributes.DISK_USAGE_PATTERN_UPDATE );
+
+        IElementAttributes attr = new ElementAttributes();
+
+        CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr, attr );
+
+        MockAuxCache mock = new MockAuxCache();
+        mock.cacheType = AuxiliaryCache.DISK_CACHE;
+
+        cache.setAuxCaches( new AuxiliaryCache[] { mock } );
+
+        ICacheElement inputElement = new CacheElement( "testSpoolAllowed", "key", "value" );
+
+        // DO WORK
+        cache.updateAuxiliaries( inputElement, false );
+
+        // VERIFY
+        assertEquals( "Wrong number of calls to the disk cache update.", 1, mock.updateCount );
+        assertEquals( "Wrong element updated.", inputElement, mock.lastUpdatedItem );
+    }
+
+    /**
+     * Setup a disk cache. Configure the disk usage pattern to SWAP. Call updateAuxiliaries. Verify
+     * that the item is not put to disk.
+     * <p>
+     * This tests that the items are not put to disk on a normal put when the usage pattern is set
+     * to SWAP.
+     * <p>
+     * @throws IOException
+     */
+    public void testUpdateNotAllowed()
+        throws IOException
+    {
+        // SETUP
+        ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+        cattr.setDiskUsagePattern( ICompositeCacheAttributes.DISK_USAGE_PATTERN_SWAP );
+
+        IElementAttributes attr = new ElementAttributes();
+
+        CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr, attr );
+
+        MockAuxCache mock = new MockAuxCache();
+        mock.cacheType = AuxiliaryCache.DISK_CACHE;
+
+        cache.setAuxCaches( new AuxiliaryCache[] { mock } );
+
+        ICacheElement inputElement = new CacheElement( "testSpoolAllowed", "key", "value" );
+
+        // DO WORK
+        cache.updateAuxiliaries( inputElement, true );
+
+        // VERIFY
+        assertEquals( "Wrong number of calls to the disk cache update.", 0, mock.updateCount );
+    }
+
+    /**
+     * Setup a disk cache. Configure the disk usage pattern to UPDATE. Call updateAuxiliaries.
+     * Verify that the item is put to disk.
+     * <p>
+     * This tests that the items are put to disk on a normal put when the usage pattern is set
+     * appropriately.
+     * @throws IOException
+     */
+    public void testUpdateAllowed_withOtherCaches()
+        throws IOException
+    {
+        // SETUP
+        ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+        cattr.setDiskUsagePattern( ICompositeCacheAttributes.DISK_USAGE_PATTERN_UPDATE );
+
+        IElementAttributes attr = new ElementAttributes();
+
+        CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr, attr );
+
+        MockAuxCache mock = new MockAuxCache();
+        mock.cacheType = AuxiliaryCache.DISK_CACHE;
+
+        MockAuxCache mockLateral = new MockAuxCache();
+        mockLateral.cacheType = AuxiliaryCache.LATERAL_CACHE;
+
+        cache.setAuxCaches( new AuxiliaryCache[] { mock, mockLateral } );
+
+        ICacheElement inputElement = new CacheElement( "testSpoolAllowed", "key", "value" );
+
+        // DO WORK
+        cache.updateAuxiliaries( inputElement, false );
+
+        // VERIFY
+        assertEquals( "Wrong number of calls to the disk cache update.", 1, mock.updateCount );
+        assertEquals( "Wrong element updated.", inputElement, mock.lastUpdatedItem );
+
+        assertEquals( "Wrong number of calls to the lateral cache update.", 1, mockLateral.updateCount );
+        assertEquals( "Wrong element updated with lateral.", inputElement, mockLateral.lastUpdatedItem );
+    }
+
+    /**
+     * Used to test the disk cache functionality.
+     * <p>
+     * @author Aaron Smuts
+     */
+    public class MockAuxCache
+        implements AuxiliaryCache
+    {
+        private static final long serialVersionUID = 1L;
+
+        /**
+         * The last item passed to update.
+         */
+        public ICacheElement lastUpdatedItem;
+
+        /**
+         * The number of times update was called.
+         */
+        public int updateCount = 0;
+
+        /**
+         * The type that should be returned from getCacheType.
+         */
+        public int cacheType = AuxiliaryCache.DISK_CACHE;
+
+        /**
+         * Resets counters and catchers.
+         */
+        public void reset()
+        {
+            updateCount = 0;
+            lastUpdatedItem = null;
+        }
+
+        /*
+         * (non-Javadoc)
+         * @see org.apache.jcs.auxiliary.AuxiliaryCache#update(org.apache.jcs.engine.behavior.ICacheElement)
+         */
+        public void update( ICacheElement ce )
+            throws IOException
+        {
+            lastUpdatedItem = ce;
+            updateCount++;
+        }
+
+        /*
+         * (non-Javadoc)
+         * @see org.apache.jcs.auxiliary.AuxiliaryCache#get(java.io.Serializable)
+         */
+        public ICacheElement get( Serializable key )
+            throws IOException
+        {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        /**
+         * Gets multiple items from the cache based on the given set of keys.
+         * <p>
+         * @param keys
+         * @return a map of Serializable key to ICacheElement element, or an empty map if there is no data in cache for any of these keys
+         */
+        public Map getMultiple( Set keys )
+        {
+            return new HashMap();
+        }
+
+        /*
+         * (non-Javadoc)
+         * @see org.apache.jcs.auxiliary.AuxiliaryCache#remove(java.io.Serializable)
+         */
+        public boolean remove( Serializable key )
+            throws IOException
+        {
+            // TODO Auto-generated method stub
+            return false;
+        }
+
+        /*
+         * (non-Javadoc)
+         * @see org.apache.jcs.auxiliary.AuxiliaryCache#removeAll()
+         */
+        public void removeAll()
+            throws IOException
+        {
+            // TODO Auto-generated method stub
+
+        }
+
+        /*
+         * (non-Javadoc)
+         * @see org.apache.jcs.auxiliary.AuxiliaryCache#dispose()
+         */
+        public void dispose()
+            throws IOException
+        {
+            // TODO Auto-generated method stub
+
+        }
+
+        /*
+         * (non-Javadoc)
+         * @see org.apache.jcs.auxiliary.AuxiliaryCache#getSize()
+         */
+        public int getSize()
+        {
+            // TODO Auto-generated method stub
+            return 0;
+        }
+
+        /*
+         * (non-Javadoc)
+         * @see org.apache.jcs.auxiliary.AuxiliaryCache#getStatus()
+         */
+        public int getStatus()
+        {
+            // TODO Auto-generated method stub
+            return 0;
+        }
+
+        /*
+         * (non-Javadoc)
+         * @see org.apache.jcs.auxiliary.AuxiliaryCache#getCacheName()
+         */
+        public String getCacheName()
+        {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        /*
+         * (non-Javadoc)
+         * @see org.apache.jcs.auxiliary.AuxiliaryCache#getGroupKeys(java.lang.String)
+         */
+        public Set getGroupKeys( String group )
+            throws IOException
+        {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        /*
+         * (non-Javadoc)
+         * @see org.apache.jcs.auxiliary.AuxiliaryCache#getStatistics()
+         */
+        public IStats getStatistics()
+        {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        /*
+         * (non-Javadoc)
+         * @see org.apache.jcs.engine.behavior.ICache#getStats()
+         */
+        public String getStats()
+        {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        /**
+         * Returns the setup cache type. This allows you to use this mock as multiple cache types.
+         * <p>
+         * (non-Javadoc)
+         * @see org.apache.jcs.engine.behavior.ICacheType#getCacheType()
+         */
+        public int getCacheType()
+        {
+            return cacheType;
+        }
+
+        /**
+         * @return Returns the AuxiliaryCacheAttributes.
+         */
+        public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
+        {
+            return null;
+        }
+    }
+
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MemoryCacheMockImpl.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MemoryCacheMockImpl.java?rev=647264&r1=647263&r2=647264&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MemoryCacheMockImpl.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MemoryCacheMockImpl.java Fri Apr 11 11:43:26 2008
@@ -1,170 +1,196 @@
-package org.apache.jcs.engine.memory;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.apache.jcs.engine.behavior.ICacheElement;
-import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
-import org.apache.jcs.engine.control.CompositeCache;
-import org.apache.jcs.engine.stats.behavior.IStats;
-
-/**
- * Mock implementation of a memory cache for testing things like the memory
- * shrinker.
- * <p>
- * @author Aaron Smuts
- */
-public class MemoryCacheMockImpl
-    implements MemoryCache
-{
-    private ICompositeCacheAttributes cacheAttr;
-
-    private HashMap map = new HashMap();
-
-    /**
-     * The number of times waterfall was called.
-     */
-    public int waterfallCallCount = 0;
-
-    /**
-     * The number passed to the last call of free elements.
-     */
-    public int lastNumberOfFreedElements = 0;
-
-    public void initialize( CompositeCache cache )
-    {
-        // TODO Auto-generated method stub
-    }
-
-    public void dispose()
-        throws IOException
-    {
-        // TODO Auto-generated method stub
-
-    }
-
-    public int getSize()
-    {
-        return map.size();
-    }
-
-    public IStats getStatistics()
-    {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    public Iterator getIterator()
-    {
-        // return
-        return null;
-    }
-
-    public Object[] getKeyArray()
-    {
-        return map.keySet().toArray();
-    }
-
-    public boolean remove( Serializable key )
-        throws IOException
-    {
-        return map.remove( key ) != null;
-    }
-
-    public void removeAll()
-        throws IOException
-    {
-        map.clear();
-    }
-
-    public ICacheElement get( Serializable key )
-        throws IOException
-    {
-        return (ICacheElement) map.get( key );
-    }
-
-    public ICacheElement getQuiet( Serializable key )
-        throws IOException
-    {
-        return (ICacheElement) map.get( key );
-    }
-
-    public void waterfal( ICacheElement ce )
-        throws IOException
-    {
-        waterfallCallCount++;
-    }
-
-    public void update( ICacheElement ce )
-        throws IOException
-    {
-        if ( ce != null )
-        {
-            map.put( ce.getKey(), ce );
-        }
-    }
-
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.apache.jcs.engine.memory.MemoryCache#getCacheAttributes()
-     */
-    public ICompositeCacheAttributes getCacheAttributes()
-    {
-        return cacheAttr;
-    }
-
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.apache.jcs.engine.memory.MemoryCache#setCacheAttributes(org.apache.jcs.engine.behavior.ICompositeCacheAttributes)
-     */
-    public void setCacheAttributes( ICompositeCacheAttributes cattr )
-    {
-        this.cacheAttr = cattr;
-    }
-
-    public CompositeCache getCompositeCache()
-    {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    public Set getGroupKeys( String group )
-    {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.jcs.engine.memory.MemoryCache#freeElements(int)
-     */
-    public int freeElements( int numberToFree )
-        throws IOException
-    {
-        lastNumberOfFreedElements = numberToFree;
-        return 0;
-    }
-}
+package org.apache.jcs.engine.memory;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
+import org.apache.jcs.engine.control.CompositeCache;
+import org.apache.jcs.engine.stats.behavior.IStats;
+
+/**
+ * Mock implementation of a memory cache for testing things like the memory
+ * shrinker.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class MemoryCacheMockImpl
+    implements MemoryCache
+{
+    private ICompositeCacheAttributes cacheAttr;
+
+    private HashMap map = new HashMap();
+
+    /**
+     * The number of times waterfall was called.
+     */
+    public int waterfallCallCount = 0;
+
+    /**
+     * The number passed to the last call of free elements.
+     */
+    public int lastNumberOfFreedElements = 0;
+
+    public void initialize( CompositeCache cache )
+    {
+        // TODO Auto-generated method stub
+    }
+
+    public void dispose()
+        throws IOException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public int getSize()
+    {
+        return map.size();
+    }
+
+    public IStats getStatistics()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Iterator getIterator()
+    {
+        // return
+        return null;
+    }
+
+    public Object[] getKeyArray()
+    {
+        return map.keySet().toArray();
+    }
+
+    public boolean remove( Serializable key )
+        throws IOException
+    {
+        return map.remove( key ) != null;
+    }
+
+    public void removeAll()
+        throws IOException
+    {
+        map.clear();
+    }
+
+    public ICacheElement get( Serializable key )
+        throws IOException
+    {
+        return (ICacheElement) map.get( key );
+    }
+
+    public Map getMultiple( Set keys )
+        throws IOException
+    {
+        Map elements = new HashMap();
+
+        if ( keys != null && !keys.isEmpty() )
+        {
+            Iterator iterator = keys.iterator();
+
+            while ( iterator.hasNext() )
+            {
+                Serializable key = (Serializable) iterator.next();
+
+                ICacheElement element = get( key );
+
+                if ( element != null )
+                {
+                    elements.put( key, element );
+                }
+            }
+        }
+
+        return elements;
+    }
+
+    public ICacheElement getQuiet( Serializable key )
+        throws IOException
+    {
+        return (ICacheElement) map.get( key );
+    }
+
+    public void waterfal( ICacheElement ce )
+        throws IOException
+    {
+        waterfallCallCount++;
+    }
+
+    public void update( ICacheElement ce )
+        throws IOException
+    {
+        if ( ce != null )
+        {
+            map.put( ce.getKey(), ce );
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.apache.jcs.engine.memory.MemoryCache#getCacheAttributes()
+     */
+    public ICompositeCacheAttributes getCacheAttributes()
+    {
+        return cacheAttr;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.apache.jcs.engine.memory.MemoryCache#setCacheAttributes(org.apache.jcs.engine.behavior.ICompositeCacheAttributes)
+     */
+    public void setCacheAttributes( ICompositeCacheAttributes cattr )
+    {
+        this.cacheAttr = cattr;
+    }
+
+    public CompositeCache getCompositeCache()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Set getGroupKeys( String group )
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jcs.engine.memory.MemoryCache#freeElements(int)
+     */
+    public int freeElements( int numberToFree )
+        throws IOException
+    {
+        lastNumberOfFreedElements = numberToFree;
+        return 0;
+    }
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/lru/LRUMemoryCacheConcurrentUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/lru/LRUMemoryCacheConcurrentUnitTest.java?rev=647264&r1=647263&r2=647264&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/lru/LRUMemoryCacheConcurrentUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/lru/LRUMemoryCacheConcurrentUnitTest.java Fri Apr 11 11:43:26 2008
@@ -19,6 +19,10 @@
  * under the License.
  */
 
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
 import junit.extensions.ActiveTestSuite;
 import junit.framework.Test;
 import junit.framework.TestCase;
@@ -132,18 +136,35 @@
         }
 
         // Test that initial items have been purged
-
         for ( int i = 0; i < 102; i++ )
         {
             assertNull( lru.get( i + ":key" ) );
         }
 
         // Test that last items are in cache
-
         for ( int i = 102; i < items; i++ )
         {
             String value = (String) lru.get( i + ":key" ).getVal();
             assertEquals( region + " data " + i, value );
+        }
+
+        // Test that getMultiple returns all the items remaining in cache and none of the missing ones
+        Set keys = new HashSet();
+        for ( int i = 0; i < items; i++ )
+        {
+            keys.add( i + ":key" );
+        }
+
+        Map elements = lru.getMultiple( keys );
+        for ( int i = 0; i < 102; i++ )
+        {
+            assertNull( elements.get( i + ":key" ) );
+        }
+        for ( int i = 102; i < items; i++ )
+        {
+            ICacheElement element = (ICacheElement) elements.get( i + ":key" );
+            assertNotNull( "element " + i + ":key is missing", element );
+            assertEquals( "value " + i + ":key", region + " data " + i, element.getVal() );
         }
 
         // Remove all the items
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.