You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by as...@apache.org on 2009/07/23 20:27:42 UTC
svn commit: r797178 [2/2] - in /jakarta/jcs/trunk/src: conf/
java/org/apache/jcs/auxiliary/lateral/
java/org/apache/jcs/auxiliary/lateral/behavior/
java/org/apache/jcs/auxiliary/lateral/socket/tcp/
java/org/apache/jcs/auxiliary/lateral/socket/tcp/behav...
Added: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListenerUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListenerUnitTest.java?rev=797178&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListenerUnitTest.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListenerUnitTest.java Thu Jul 23 18:27:41 2009
@@ -0,0 +1,255 @@
+package org.apache.jcs.auxiliary.lateral.socket.tcp;
+
+import java.util.ArrayList;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.auxiliary.lateral.LateralCache;
+import org.apache.jcs.auxiliary.lateral.LateralCacheAttributes;
+import org.apache.jcs.auxiliary.lateral.LateralCacheNoWait;
+import org.apache.jcs.auxiliary.lateral.LateralCacheNoWaitFacade;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
+import org.apache.jcs.auxiliary.lateral.socket.tcp.behavior.ITCPLateralCacheAttributes;
+import org.apache.jcs.engine.behavior.ICompositeCacheManager;
+import org.apache.jcs.engine.behavior.IElementSerializer;
+import org.apache.jcs.engine.control.CompositeCacheManager;
+import org.apache.jcs.engine.logging.MockCacheEventLogger;
+import org.apache.jcs.utils.discovery.DiscoveredService;
+import org.apache.jcs.utils.serialization.StandardSerializer;
+
+/** Test for the listener that observers UDP discovery events. */
+public class LateralTCPDiscoveryListenerUnitTest
+ extends TestCase
+{
+ /** the listener */
+ private LateralTCPDiscoveryListener listener;
+
+ /** The cache manager. */
+ private ICompositeCacheManager cacheMgr;
+
+ /** The event logger. */
+ protected MockCacheEventLogger cacheEventLogger;
+
+ /** The serializer. */
+ protected IElementSerializer elementSerializer;
+
+ /** Create the listener for testing */
+ protected void setUp()
+ {
+ cacheMgr = CompositeCacheManager.getInstance();
+ cacheEventLogger = new MockCacheEventLogger();
+ elementSerializer = new StandardSerializer();
+
+ listener = new LateralTCPDiscoveryListener( cacheMgr, cacheEventLogger, elementSerializer );
+ }
+
+ /**
+ * Add a no wait facade.
+ */
+ public void testAddNoWaitFacade_NotInList()
+ {
+ // SETUP
+ String cacheName = "testAddNoWaitFacade_NotInList";
+ LateralCacheNoWait[] noWaits = new LateralCacheNoWait[0];
+ ILateralCacheAttributes cattr = new LateralCacheAttributes();
+ cattr.setCacheName( cacheName );
+
+ LateralCacheNoWaitFacade facade = new LateralCacheNoWaitFacade( noWaits, cattr );
+
+ // DO WORK
+ listener.addNoWaitFacade( cacheName, facade );
+
+ // VERIFY
+ assertTrue( "Should have the facade.", listener.containsNoWaitFacade( cacheName ) );
+ }
+
+ /**
+ * Add a no wait to a known facade.
+ */
+ public void testAddNoWait_FacadeInList()
+ {
+ // SETUP
+ String cacheName = "testAddNoWaitFacade_FacadeInList";
+ LateralCacheNoWait[] noWaits = new LateralCacheNoWait[0];
+ ILateralCacheAttributes cattr = new LateralCacheAttributes();
+ cattr.setCacheName( cacheName );
+
+ LateralCacheNoWaitFacade facade = new LateralCacheNoWaitFacade( noWaits, cattr );
+ listener.addNoWaitFacade( cacheName, facade );
+
+ LateralCache cache = new LateralCache( cattr );
+ LateralCacheNoWait noWait = new LateralCacheNoWait( cache );
+
+ // DO WORK
+ boolean result = listener.addNoWait( noWait );
+
+ // VERIFY
+ assertTrue( "Should have added the no wait.", result );
+ }
+
+ /**
+ * Add a no wait from an unknown facade.
+ */
+ public void testAddNoWait_FacadeNotInList()
+ {
+ // SETUP
+ String cacheName = "testAddNoWaitFacade_FacadeInList";
+ ILateralCacheAttributes cattr = new LateralCacheAttributes();
+ cattr.setCacheName( cacheName );
+
+ LateralCache cache = new LateralCache( cattr );
+ LateralCacheNoWait noWait = new LateralCacheNoWait( cache );
+
+ // DO WORK
+ boolean result = listener.addNoWait( noWait );
+
+ // VERIFY
+ assertFalse( "Should not have added the no wait.", result );
+ }
+
+ /**
+ * Remove a no wait from an unknown facade.
+ */
+ public void testRemoveNoWait_FacadeNotInList()
+ {
+ // SETUP
+ String cacheName = "testRemoveNoWaitFacade_FacadeNotInList";
+ ILateralCacheAttributes cattr = new LateralCacheAttributes();
+ cattr.setCacheName( cacheName );
+
+ LateralCache cache = new LateralCache( cattr );
+ LateralCacheNoWait noWait = new LateralCacheNoWait( cache );
+
+ // DO WORK
+ boolean result = listener.removeNoWait( noWait );
+
+ // VERIFY
+ assertFalse( "Should not have removed the no wait.", result );
+ }
+
+ /**
+ * Remove a no wait from a known facade.
+ */
+ public void testRemoveNoWait_FacadeInList_NoWaitNot()
+ {
+ // SETUP
+ String cacheName = "testAddNoWaitFacade_FacadeInList";
+ LateralCacheNoWait[] noWaits = new LateralCacheNoWait[0];
+ ILateralCacheAttributes cattr = new LateralCacheAttributes();
+ cattr.setCacheName( cacheName );
+
+ LateralCacheNoWaitFacade facade = new LateralCacheNoWaitFacade( noWaits, cattr );
+ listener.addNoWaitFacade( cacheName, facade );
+
+ LateralCache cache = new LateralCache( cattr );
+ LateralCacheNoWait noWait = new LateralCacheNoWait( cache );
+
+ // DO WORK
+ boolean result = listener.removeNoWait( noWait );
+
+ // VERIFY
+ assertFalse( "Should not have removed the no wait.", result );
+ }
+
+ /**
+ * Remove a no wait from a known facade.
+ */
+ public void testRemoveNoWait_FacadeInList_NoWaitIs()
+ {
+ // SETUP
+ String cacheName = "testRemoveNoWaitFacade_FacadeInListNoWaitIs";
+ LateralCacheNoWait[] noWaits = new LateralCacheNoWait[0];
+ ILateralCacheAttributes cattr = new LateralCacheAttributes();
+ cattr.setCacheName( cacheName );
+
+ LateralCacheNoWaitFacade facade = new LateralCacheNoWaitFacade( noWaits, cattr );
+ listener.addNoWaitFacade( cacheName, facade );
+
+ LateralCache cache = new LateralCache( cattr );
+ LateralCacheNoWait noWait = new LateralCacheNoWait( cache );
+ listener.addNoWait( noWait );
+
+ // DO WORK
+ boolean result = listener.removeNoWait( noWait );
+
+ // VERIFY
+ assertTrue( "Should have removed the no wait.", result );
+ }
+
+ /**
+ * Add a no wait to a known facade.
+ */
+ public void testAddDiscoveredService_FacadeInList_NoWaitNot()
+ {
+ // SETUP
+ String cacheName = "testAddDiscoveredService_FacadeInList_NoWaitNot";
+
+ ArrayList cacheNames = new ArrayList();
+ cacheNames.add( cacheName );
+
+ DiscoveredService service = new DiscoveredService();
+ service.setCacheNames( cacheNames );
+ service.setServiceAddress( "localhost" );
+ service.setServicePort( 9999 );
+
+ // since the no waits are compared by object equality, I have to do this
+ // TODO add an equals method to the noWait. the problem if is figuring out what to compare.
+ ITCPLateralCacheAttributes lca = new TCPLateralCacheAttributes();
+ lca.setTransmissionType( LateralCacheAttributes.TCP );
+ lca.setTcpServer( service.getServiceAddress() + ":" + service.getServicePort() );
+ LateralTCPCacheManager lcm = LateralTCPCacheManager.getInstance( lca, cacheMgr, cacheEventLogger,
+ elementSerializer );
+ LateralCacheNoWait noWait = (LateralCacheNoWait) lcm.getCache( cacheName );
+
+ LateralCacheNoWait[] noWaits = new LateralCacheNoWait[0];
+ ILateralCacheAttributes cattr = new LateralCacheAttributes();
+ cattr.setCacheName( cacheName );
+ LateralCacheNoWaitFacade facade = new LateralCacheNoWaitFacade( noWaits, cattr );
+ listener.addNoWaitFacade( cacheName, facade );
+
+ // DO WORK
+ listener.addDiscoveredService( service );
+
+ // VERIFY
+ assertTrue( "Should have no wait.", listener.containsNoWait( cacheName, noWait ) );
+ }
+
+ /**
+ * Remove a no wait from a known facade.
+ */
+ public void testRemoveDiscoveredService_FacadeInList_NoWaitIs()
+ {
+ // SETUP
+ String cacheName = "testRemoveDiscoveredService_FacadeInList_NoWaitIs";
+
+ ArrayList cacheNames = new ArrayList();
+ cacheNames.add( cacheName );
+
+ DiscoveredService service = new DiscoveredService();
+ service.setCacheNames( cacheNames );
+ service.setServiceAddress( "localhost" );
+ service.setServicePort( 9999 );
+
+ // since the no waits are compared by object equality, I have to do this
+ // TODO add an equals method to the noWait. the problem if is figuring out what to compare.
+ ITCPLateralCacheAttributes lca = new TCPLateralCacheAttributes();
+ lca.setTransmissionType( LateralCacheAttributes.TCP );
+ lca.setTcpServer( service.getServiceAddress() + ":" + service.getServicePort() );
+ LateralTCPCacheManager lcm = LateralTCPCacheManager.getInstance( lca, cacheMgr, cacheEventLogger,
+ elementSerializer );
+ LateralCacheNoWait noWait = (LateralCacheNoWait) lcm.getCache( cacheName );
+
+ LateralCacheNoWait[] noWaits = new LateralCacheNoWait[0];
+ ILateralCacheAttributes cattr = new LateralCacheAttributes();
+ cattr.setCacheName( cacheName );
+ LateralCacheNoWaitFacade facade = new LateralCacheNoWaitFacade( noWaits, cattr );
+ listener.addNoWaitFacade( cacheName, facade );
+ listener.addDiscoveredService( service );
+
+ // DO WORK
+ listener.removeDiscoveredService( service );
+
+ // VERIFY
+ assertFalse( "Should not have no wait.", listener.containsNoWait( cacheName, noWait ) );
+ }
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java?rev=797178&r1=797177&r2=797178&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java Thu Jul 23 18:27:41 2009
@@ -38,7 +38,7 @@
//private static boolean isSysOut = false;
/** The port the server will listen to. */
- private int serverPort = 1118;
+ private int serverPort = 2001;
/**
* Constructor for the TestDiskCache object.
@@ -56,7 +56,6 @@
public void setUp()
{
System.setProperty( "jcs.auxiliary.LTCP.attributes.TcpServers", "localhost:" + serverPort );
-
JCS.setConfigFilename( "/TestTCPLateralRemoveFilter.ccf" );
}
@@ -85,9 +84,6 @@
public void runTestForRegion( String region, int numOps, int testNum )
throws Exception
{
-
- //boolean show = true;//false;
-
JCS cache = JCS.getInstance( region );
Thread.sleep( 100 );
@@ -95,7 +91,7 @@
TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
lattr2.setTcpListenerPort( 1102 );
lattr2.setTransmissionTypeName( "TCP" );
- lattr2.setTcpServer( "localhost:1118" );
+ lattr2.setTcpServer( "localhost:" + serverPort );
lattr2.setIssueRemoveOnPut( true );
// should still try to remove
lattr2.setAllowPut( false );
Added: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/MockCacheServiceNonLocal.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/MockCacheServiceNonLocal.java?rev=797178&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/MockCacheServiceNonLocal.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/MockCacheServiceNonLocal.java Thu Jul 23 18:27:41 2009
@@ -0,0 +1,232 @@
+package org.apache.jcs.engine;
+
+/*
+ * 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.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.behavior.ICacheServiceNonLocal;
+
+/**
+ * This is a mock impl of the non local cache service.
+ */
+public class MockCacheServiceNonLocal
+ implements ICacheServiceNonLocal
+{
+ /** The key last passed to get */
+ public Serializable lastGetKey;
+
+ /** The pattern last passed to get */
+ public String lastGetMatchingPattern;
+
+ /** The keya last passed to getMatching */
+ public Set lastGetMultipleKeys;
+
+ /** The object that was last passed to update. */
+ public Object lastUpdate;
+
+ /** List of updates. */
+ public List updateRequestList = new ArrayList();
+
+ /** List of request ids. */
+ public List updateRequestIdList = new ArrayList();
+
+ /** 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 - identity of requester
+ * @return null
+ */
+ public ICacheElement get( String cacheName, Serializable key, long requesterId )
+ {
+ lastGetKey = key;
+ 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 - identity of requester
+ */
+ public void remove( String cacheName, Serializable key, long requesterId )
+ {
+ lastRemoveKey = key;
+ }
+
+ /**
+ * Set the lastRemoveAllCacheName to the cacheName.
+ * <p>
+ * @param cacheName - region name
+ * @param requesterId - identity of requester
+ * @throws IOException
+ */
+ public void removeAll( String cacheName, long requesterId )
+ throws IOException
+ {
+ lastRemoveAllCacheName = cacheName;
+ }
+
+ /**
+ * Set the last update item.
+ * <p>
+ * @param item
+ * @param requesterId - identity of requester
+ */
+ public void update( ICacheElement item, long requesterId )
+ {
+ lastUpdate = item;
+ updateRequestList.add( item );
+ updateRequestIdList.add( new Long( requesterId ) );
+ }
+
+ /**
+ * 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 get( cacheName, key, 0 );
+ }
+
+ /**
+ * 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 - identity of requester
+ * @return empty map
+ */
+ public Map getMultiple( String cacheName, Set keys, long requesterId )
+ {
+ lastGetMultipleKeys = keys;
+ return new HashMap();
+ }
+
+ /**
+ * @param cacheName
+ * @param keys
+ * @return empty map
+ */
+ public Map getMultiple( String cacheName, Set keys )
+ {
+ return getMultiple( cacheName, keys, 0 );
+ }
+
+ /**
+ * Returns an empty map. Zombies have no internal data.
+ * <p>
+ * @param cacheName
+ * @param pattern
+ * @return an empty map
+ * @throws IOException
+ */
+ public Map getMatching( String cacheName, String pattern )
+ throws IOException
+ {
+ return getMatching( cacheName, pattern, 0 );
+ }
+
+ /**
+ * @param cacheName
+ * @param pattern
+ * @param requesterId
+ * @return Map
+ * @throws IOException
+ */
+ public Map getMatching( String cacheName, String pattern, long requesterId )
+ throws IOException
+ {
+ lastGetMatchingPattern = pattern;
+ return new HashMap();
+ }
+}
Added: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/ZombieCacheServiceNonLocalUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/ZombieCacheServiceNonLocalUnitTest.java?rev=797178&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/ZombieCacheServiceNonLocalUnitTest.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/ZombieCacheServiceNonLocalUnitTest.java Thu Jul 23 18:27:41 2009
@@ -0,0 +1,126 @@
+package org.apache.jcs.engine;
+
+/*
+ * 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.engine.behavior.ICacheElement;
+
+/**
+ * Tests for the zombie remote cache service.
+ */
+public class ZombieCacheServiceNonLocalUnitTest
+ extends TestCase
+{
+ /**
+ * Verify that an update event gets added and then is sent to the service passed to propagate.
+ * <p>
+ * @throws Exception
+ */
+ public void testUpdateThenWalk()
+ throws Exception
+ {
+ // SETUP
+ MockCacheServiceNonLocal service = new MockCacheServiceNonLocal();
+
+ ZombieCacheServiceNonLocal zombie = new ZombieCacheServiceNonLocal( 10 );
+
+ String cacheName = "testUpdate";
+
+ // DO WORK
+ ICacheElement element = new CacheElement( cacheName, "key", "value" );
+ zombie.update( element, 123l );
+ zombie.propagateEvents( service );
+
+ // VERIFY
+ assertEquals( "Updated element is not as expected.", element, service.lastUpdate );
+ }
+
+ /**
+ * Verify that nothing is added if the max is set to 0.
+ * <p>
+ * @throws Exception
+ */
+ public void testUpdateThenWalk_zeroSize()
+ throws Exception
+ {
+ // SETUP
+ MockCacheServiceNonLocal service = new MockCacheServiceNonLocal();
+
+ ZombieCacheServiceNonLocal zombie = new ZombieCacheServiceNonLocal( 0 );
+
+ String cacheName = "testUpdate";
+
+ // DO WORK
+ ICacheElement element = new CacheElement( cacheName, "key", "value" );
+ zombie.update( element, 123l );
+ zombie.propagateEvents( service );
+
+ // VERIFY
+ assertNull( "Nothing should have been put to the service.", service.lastUpdate );
+ }
+
+ /**
+ * Verify that a remove event gets added and then is sent to the service passed to propagate.
+ * <p>
+ * @throws Exception
+ */
+ public void testRemoveThenWalk()
+ throws Exception
+ {
+ // SETUP
+ MockCacheServiceNonLocal service = new MockCacheServiceNonLocal();
+
+ ZombieCacheServiceNonLocal zombie = new ZombieCacheServiceNonLocal( 10 );
+
+ String cacheName = "testRemoveThenWalk";
+ String key = "myKey";
+
+ // DO WORK
+ zombie.remove( cacheName, key, 123l );
+ zombie.propagateEvents( service );
+
+ // VERIFY
+ assertEquals( "Updated element is not as expected.", key, service.lastRemoveKey );
+ }
+
+ /**
+ * Verify that a removeAll event gets added and then is sent to the service passed to propagate.
+ * <p>
+ * @throws Exception
+ */
+ public void testRemoveAllThenWalk()
+ throws Exception
+ {
+ // SETUP
+ MockCacheServiceNonLocal service = new MockCacheServiceNonLocal();
+
+ ZombieCacheServiceNonLocal zombie = new ZombieCacheServiceNonLocal( 10 );
+
+ String cacheName = "testRemoveThenWalk";
+
+ // DO WORK
+ zombie.removeAll( cacheName, 123l );
+ zombie.propagateEvents( service );
+
+ // VERIFY
+ assertEquals( "Updated element is not as expected.", cacheName, service.lastRemoveAllCacheName );
+ }
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/utils/discovery/UDPDiscoveryServiceUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/utils/discovery/UDPDiscoveryServiceUnitTest.java?rev=797178&r1=797177&r2=797178&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/utils/discovery/UDPDiscoveryServiceUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/utils/discovery/UDPDiscoveryServiceUnitTest.java Thu Jul 23 18:27:41 2009
@@ -65,7 +65,71 @@
}
/** Verify that the list is updated. */
- public void testAddOrUpdateService_InList()
+ public void testAddOrUpdateService_InList_NamesDoNotChange()
+ {
+ // SETUP
+ String host = "228.5.6.7";
+ int port = 6789;
+ UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes();
+ attributes.setUdpDiscoveryAddr( host );
+ attributes.setUdpDiscoveryPort( port );
+ attributes.setServicePort( 1000 );
+
+ // create the service
+ UDPDiscoveryService service = new UDPDiscoveryService( attributes, new MockCacheEventLogger() );
+ service.addParticipatingCacheName( "testCache1" );
+
+ MockDiscoveryListener discoveryListener = new MockDiscoveryListener();
+ service.addDiscoveryListener( discoveryListener );
+
+ ArrayList sametCacheNames = new ArrayList();
+ sametCacheNames.add( "name1" );
+
+ DiscoveredService discoveredService = new DiscoveredService();
+ discoveredService.setServiceAddress( host );
+ discoveredService.setCacheNames( sametCacheNames );
+ discoveredService.setServicePort( 1000 );
+ discoveredService.setLastHearFromTime( 100 );
+
+
+ DiscoveredService discoveredService2 = new DiscoveredService();
+ discoveredService2.setServiceAddress( host );
+ discoveredService2.setCacheNames( sametCacheNames );
+ discoveredService2.setServicePort( 1000 );
+ discoveredService2.setLastHearFromTime( 500 );
+
+ // DO WORK
+ service.addOrUpdateService( discoveredService );
+ // again
+ service.addOrUpdateService( discoveredService2 );
+
+ // VERIFY
+ assertEquals( "Should only be one in the set.", 1, service.getDiscoveredServices().size() );
+ assertTrue( "Service should be in the service list.", service.getDiscoveredServices()
+ .contains( discoveredService ) );
+ assertTrue( "Service should be in the listener list.", discoveryListener.discoveredServices
+ .contains( discoveredService ) );
+
+ Iterator it = service.getDiscoveredServices().iterator();
+ // need to update the time this sucks. add has no effect convert to a map
+ while ( it.hasNext() )
+ {
+ DiscoveredService service1 = (DiscoveredService) it.next();
+ if ( discoveredService.equals( service1 ) )
+ {
+ assertEquals( "The match should have the new last heard from time.", service1.getLastHearFromTime(),
+ discoveredService2.getLastHearFromTime() );
+ }
+ }
+ // the mock has a list from all add calls.
+ // it should have been called when the list changed.
+ //assertEquals( "Mock should have been called once.", 1, discoveryListener.discoveredServices.size() );
+ // logic changed. it's called every time.
+ assertEquals( "Mock should have been called twice.", 2, discoveryListener.discoveredServices.size() );
+ }
+
+ /** Verify that the list is updated. */
+ public void testAddOrUpdateService_InList_NamesChange()
{
// SETUP
String host = "228.5.6.7";
@@ -88,9 +152,11 @@
discoveredService.setServicePort( 1000 );
discoveredService.setLastHearFromTime( 100 );
+ ArrayList differentCacheNames = new ArrayList();
+ differentCacheNames.add( "name1" );
DiscoveredService discoveredService2 = new DiscoveredService();
discoveredService2.setServiceAddress( host );
- discoveredService2.setCacheNames( new ArrayList() );
+ discoveredService2.setCacheNames( differentCacheNames );
discoveredService2.setServicePort( 1000 );
discoveredService2.setLastHearFromTime( 500 );
@@ -105,7 +171,7 @@
.contains( discoveredService ) );
assertTrue( "Service should be in the listener list.", discoveryListener.discoveredServices
.contains( discoveredService ) );
-
+
Iterator it = service.getDiscoveredServices().iterator();
// need to update the time this sucks. add has no effect convert to a map
while ( it.hasNext() )
@@ -115,8 +181,14 @@
{
assertEquals( "The match should have the new last heard from time.", service1.getLastHearFromTime(),
discoveredService2.getLastHearFromTime() );
+ assertEquals( "The names should be updated.", service1.getCacheNames() + "", differentCacheNames + "" );
}
- }
+ }
+ // the mock has a list from all add calls.
+ // it should have been called when the list changed.
+ assertEquals( "Mock should have been called twice.", 2, discoveryListener.discoveredServices.size() );
+ assertEquals( "The second mock listener add should be discoveredService2", discoveredService2,
+ discoveryListener.discoveredServices.get( 1 ) );
}
/** Verify that the list is updated. */
@@ -153,5 +225,5 @@
.contains( discoveredService ) );
assertFalse( "Service should not be in the listener list.", discoveryListener.discoveredServices
.contains( discoveredService ) );
- }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org