001: /**
002: * Copyright 2003-2007 Luck Consulting Pty Ltd
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */package net.sf.ehcache.distribution;
016:
017: import net.sf.ehcache.AbstractCacheTest;
018: import net.sf.ehcache.CacheManager;
019: import net.sf.ehcache.Ehcache;
020:
021: import java.util.List;
022:
023: /**
024: * @author <a href="mailto:gluck@thoughtworks.com">Greg Luck</a>
025: * @version $Id: ManualRMIPeerProviderTest.java 552 2007-08-26 04:20:49Z gregluck $
026: */
027: public class ManualRMIPeerProviderTest extends
028: MulticastRMIPeerProviderTest {
029:
030: /**
031: * {@inheritDoc}
032: */
033: protected void setUp() throws Exception {
034: if (JVMUtil.isSingleRMIRegistryPerVM()) {
035: return;
036: }
037:
038: manager1 = new CacheManager(AbstractCacheTest.TEST_CONFIG_DIR
039: + "distribution/ehcache-manual-distributed1.xml");
040: manager2 = new CacheManager(AbstractCacheTest.TEST_CONFIG_DIR
041: + "distribution/ehcache-manual-distributed2.xml");
042: manager3 = new CacheManager(AbstractCacheTest.TEST_CONFIG_DIR
043: + "distribution/ehcache-manual-distributed3.xml");
044:
045: /* manager3 has an empty manual configuration, which is topped up by adding manual entries.
046: * The sampleCache1 from manager3 is added to the rmiUrls list for manager1 and manager2
047: */
048: CacheManagerPeerProvider peerProvider = manager3
049: .getCacheManagerPeerProvider();
050: peerProvider.registerPeer("//localhost:40001/sampleCache1");
051: peerProvider.registerPeer("//localhost:40002/sampleCache1");
052:
053: //Allow cluster setup
054: Thread.sleep(2000);
055: }
056:
057: /**
058: * test remote cache peers
059: */
060: public void testProviderFromCacheManager()
061: throws InterruptedException {
062:
063: if (JVMUtil.isSingleRMIRegistryPerVM()) {
064: return;
065: }
066:
067: Ehcache m1sampleCache1 = manager1.getCache("sampleCache1");
068: Thread.sleep(2000);
069:
070: List peerUrls = manager1.getCachePeerProvider()
071: .listRemoteCachePeers(m1sampleCache1);
072: assertEquals(expectedPeers(), peerUrls.size());
073:
074: Ehcache m2sampleCache1 = manager2.getCache("sampleCache1");
075: assertFalse(m1sampleCache1.getGuid().equals(
076: m2sampleCache1.getGuid()));
077:
078: List peerUrls2 = manager2.getCachePeerProvider()
079: .listRemoteCachePeers(m2sampleCache1);
080: assertEquals(expectedPeers(), peerUrls2.size());
081:
082: Ehcache m3sampleCache1 = manager3.getCache("sampleCache1");
083: assertFalse(m1sampleCache1.getGuid().equals(
084: m3sampleCache1.getGuid()));
085:
086: List peerUrls3 = manager3.getCachePeerProvider()
087: .listRemoteCachePeers(m3sampleCache1);
088: assertEquals(expectedPeers(), peerUrls3.size());
089:
090: //Now remove a node, wait for the cluster to self-heal and then test
091: manager1.shutdown();
092: Thread.sleep(1000);
093: peerUrls3 = manager3.getCachePeerProvider()
094: .listRemoteCachePeers(m3sampleCache1);
095: //The manual provider removes the cache peer that was not reachable
096: assertEquals(1, peerUrls3.size());
097:
098: }
099:
100: }
|