Author: tv Date: Wed Jun 21 12:42:00 2017 New Revision: 1799432 URL: http://svn.apache.org/viewvc?rev=1799432&view=rev Log: JCS-178: Clients using RemoteCache are not working. Add a test. Add new constructors with better parametrization, deprecate the old ones
Added: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWaitFacadeUnitTest.java (with props) Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCache.java commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFactory.java commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java commons/proper/jcs/trunk/src/changes/changes.xml Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java?rev=1799432&r1=1799431&r2=1799432&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java Wed Jun 21 12:42:00 2017 @@ -60,10 +60,38 @@ public abstract class AbstractRemoteCach * <p> * @param noWaits * @param rca + * @param cacheEventLogger + * @param elementSerializer + */ + public AbstractRemoteCacheNoWaitFacade( List<RemoteCacheNoWait<K,V>> noWaits, IRemoteCacheAttributes rca, + ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer ) + { + if ( log.isDebugEnabled() ) + { + log.debug( "CONSTRUCTING NO WAIT FACADE" ); + } + this.remoteCacheAttributes = rca; + setCacheEventLogger( cacheEventLogger ); + setElementSerializer( elementSerializer ); + this.noWaits = new ArrayList<RemoteCacheNoWait<K,V>>(noWaits); + for (RemoteCacheNoWait<K,V> nw : this.noWaits) + { + // FIXME: This cast is very brave. Remove this. + ((RemoteCache<K, V>)nw.getRemoteCache()).setFacade(this); + } + } + + /** + * Constructs with the given remote cache, and fires events to any listeners. + * <p> + * @param noWaits + * @param rca * @param cacheMgr * @param cacheEventLogger * @param elementSerializer + * @deprecated Unused parameter cacheMgr scheduled for removal */ + @Deprecated public AbstractRemoteCacheNoWaitFacade( List<ICache<K, V>> noWaits, RemoteCacheAttributes rca, ICompositeCacheManager cacheMgr, ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer ) @@ -72,15 +100,16 @@ public abstract class AbstractRemoteCach { log.debug( "CONSTRUCTING NO WAIT FACADE" ); } + this.remoteCacheAttributes = rca; + setCacheEventLogger( cacheEventLogger ); + setElementSerializer( elementSerializer ); this.noWaits = new ArrayList<RemoteCacheNoWait<K,V>>(); for (ICache<K, V> nw : noWaits) { - RemoteCacheNoWait<K,V> rcnw = (RemoteCacheNoWait<K,V>) nw; + RemoteCacheNoWait<K,V> rcnw = (RemoteCacheNoWait<K,V>)nw; + ((RemoteCache<K, V>)rcnw.getRemoteCache()).setFacade(this); this.noWaits.add(rcnw); } - this.remoteCacheAttributes = rca; - setCacheEventLogger( cacheEventLogger ); - setElementSerializer( elementSerializer ); } /** Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCache.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCache.java?rev=1799432&r1=1799431&r2=1799432&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCache.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCache.java Wed Jun 21 12:42:00 2017 @@ -113,6 +113,16 @@ public class RemoteCache<K, V> } /** + * Get facade + * + * @return the facade + */ + protected AbstractRemoteCacheNoWaitFacade<K, V> getFacade() + { + return facade; + } + + /** * Handles exception by disabling the remote cache service before re-throwing the exception in * the form of an IOException. * <p> Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFactory.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFactory.java?rev=1799432&r1=1799431&r2=1799432&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFactory.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFactory.java Wed Jun 21 12:42:00 2017 @@ -32,7 +32,6 @@ import org.apache.commons.jcs.auxiliary. import org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes; import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes; import org.apache.commons.jcs.auxiliary.remote.server.behavior.RemoteType; -import org.apache.commons.jcs.engine.behavior.ICache; import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager; import org.apache.commons.jcs.engine.behavior.IElementSerializer; import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger; @@ -75,7 +74,7 @@ public class RemoteCacheFactory { RemoteCacheAttributes rca = (RemoteCacheAttributes) iaca; - ArrayList<ICache<K, V>> noWaits = new ArrayList<ICache<K, V>>(); + ArrayList<RemoteCacheNoWait<K,V>> noWaits = new ArrayList<RemoteCacheNoWait<K,V>>(); switch (rca.getRemoteType()) { @@ -93,7 +92,7 @@ public class RemoteCacheFactory failovers.add( rca.getRemoteLocation() ); RemoteCacheManager rcm = getManager( rca, cacheMgr, cacheEventLogger, elementSerializer ); - ICache<K, V> ic = rcm.getCache( rca ); + RemoteCacheNoWait<K,V> ic = rcm.getCache( rca ); noWaits.add( ic ); } @@ -120,7 +119,7 @@ public class RemoteCacheFactory // number it is at if ( ( !primaryDefined && fCnt == 1 ) || noWaits.size() <= 0 ) { - ICache<K, V> ic = rcm.getCache( rca ); + RemoteCacheNoWait<K,V> ic = rcm.getCache( rca ); noWaits.add( ic ); } } @@ -145,7 +144,7 @@ public class RemoteCacheFactory rca.setRemoteLocation(location); RemoteCacheManager rcm = getManager( rca, cacheMgr, cacheEventLogger, elementSerializer ); rca.setRemoteType( RemoteType.CLUSTER ); - ICache<K, V> ic = rcm.getCache( rca ); + RemoteCacheNoWait<K,V> ic = rcm.getCache( rca ); noWaits.add( ic ); } } @@ -153,7 +152,7 @@ public class RemoteCacheFactory } RemoteCacheNoWaitFacade<K, V> rcnwf = - new RemoteCacheNoWaitFacade<K, V>(noWaits, rca, cacheMgr, cacheEventLogger, elementSerializer, this ); + new RemoteCacheNoWaitFacade<K, V>(noWaits, rca, cacheEventLogger, elementSerializer, this ); return rcnwf; } Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java?rev=1799432&r1=1799431&r2=1799432&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java Wed Jun 21 12:42:00 2017 @@ -21,6 +21,7 @@ package org.apache.commons.jcs.auxiliary import java.util.List; +import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes; import org.apache.commons.jcs.auxiliary.remote.server.behavior.RemoteType; import org.apache.commons.jcs.engine.CacheStatus; import org.apache.commons.jcs.engine.behavior.ICache; @@ -52,11 +53,32 @@ public class RemoteCacheNoWaitFacade<K, * <p> * @param noWaits * @param rca + * @param cacheEventLogger + * @param elementSerializer + * @param cacheFactory + */ + public RemoteCacheNoWaitFacade( List<RemoteCacheNoWait<K,V>> noWaits, + IRemoteCacheAttributes rca, + ICacheEventLogger cacheEventLogger, + IElementSerializer elementSerializer, + RemoteCacheFactory cacheFactory) + { + super( noWaits, rca, cacheEventLogger, elementSerializer ); + this.cacheFactory = cacheFactory; + } + + /** + * Constructs with the given remote cache, and fires events to any listeners. + * <p> + * @param noWaits + * @param rca * @param cacheMgr * @param cacheEventLogger * @param elementSerializer * @param cacheFactory + * @deprecated Unused parameter cacheMgr scheduled for removal */ + @Deprecated public RemoteCacheNoWaitFacade( List<ICache<K, V>> noWaits, RemoteCacheAttributes rca, ICompositeCacheManager cacheMgr, @@ -66,11 +88,6 @@ public class RemoteCacheNoWaitFacade<K, { super( noWaits, rca, cacheMgr, cacheEventLogger, elementSerializer ); this.cacheFactory = cacheFactory; - - for (RemoteCacheNoWait<K,V> rcnw : this.noWaits) - { - ((RemoteCache<K, V>)rcnw.getRemoteCache()).setFacade(this); - } } /** Added: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWaitFacadeUnitTest.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWaitFacadeUnitTest.java?rev=1799432&view=auto ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWaitFacadeUnitTest.java (added) +++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWaitFacadeUnitTest.java Wed Jun 21 12:42:00 2017 @@ -0,0 +1,56 @@ +package org.apache.commons.jcs.auxiliary.remote; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes; + +/* + * 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; + +/** + * Tests for RemoteCacheNoWaitFacade. + */ +public class RemoteCacheNoWaitFacadeUnitTest + extends TestCase +{ + /** + * Verify that we can add an item. + */ + public void testAddNoWait_InList() + { + // SETUP + List<RemoteCacheNoWait<String, String>> noWaits = new ArrayList<RemoteCacheNoWait<String,String>>(); + IRemoteCacheAttributes cattr = new RemoteCacheAttributes(); + cattr.setCacheName( "testCache1" ); + + RemoteCache<String, String> client = new RemoteCache<String, String>(cattr, null, null, null); + RemoteCacheNoWait<String, String> noWait = new RemoteCacheNoWait<String, String>( client ); + noWaits.add( noWait ); + + RemoteCacheNoWaitFacade<String, String> facade = new RemoteCacheNoWaitFacade<String, String>(noWaits, cattr, null, null, null ); + + // VERIFY + assertEquals( "Should have one entry.", 1, facade.noWaits.size() ); + assertTrue( "Should be in the list.", facade.noWaits.contains( noWait ) ); + assertSame( "Should have same facade.", facade, ((RemoteCache<String, String>)facade.noWaits.get(0).getRemoteCache()).getFacade() ); + } +} Propchange: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWaitFacadeUnitTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: commons/proper/jcs/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/changes/changes.xml?rev=1799432&r1=1799431&r2=1799432&view=diff ============================================================================== --- commons/proper/jcs/trunk/src/changes/changes.xml (original) +++ commons/proper/jcs/trunk/src/changes/changes.xml Wed Jun 21 12:42:00 2017 @@ -20,6 +20,9 @@ </properties> <body> <release version="2.2" date="unreleased"> + <action issue="JCS-178" dev="tv" type="fix"> + Clients using RemoteCache are not working. Add a test. + </action> <action dev="tv" type="add"> Add a shutdown() method to JCS </action>