~ubuntu-branches/ubuntu/trusty/ehcache/trusty

« back to all changes in this revision

Viewing changes to src/test/java/net/sf/ehcache/distribution/ManualRMIPeerProviderTest.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2013-05-06 14:53:07 UTC
  • mfrom: (1.1.7) (2.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130506145307-v5bhw5yu70re00l3
Tags: 2.6.7-1
* Team upload.
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 *  Copyright 2003-2010 Terracotta, Inc.
 
2
 *  Copyright Terracotta, Inc.
3
3
 *
4
4
 *  Licensed under the Apache License, Version 2.0 (the "License");
5
5
 *  you may not use this file except in compliance with the License.
16
16
 
17
17
package net.sf.ehcache.distribution;
18
18
 
19
 
import static org.junit.Assert.assertEquals;
20
 
import static org.junit.Assert.assertFalse;
21
 
 
 
19
import java.util.ArrayList;
22
20
import java.util.Collections;
23
21
import java.util.List;
24
22
import java.util.concurrent.TimeUnit;
25
23
 
26
24
import net.sf.ehcache.AbstractCacheTest;
27
25
import net.sf.ehcache.CacheManager;
28
 
import net.sf.ehcache.Ehcache;
 
26
import net.sf.ehcache.config.Configuration;
29
27
 
30
28
import org.junit.Before;
31
 
import org.junit.Test;
32
29
 
33
30
/**
34
31
 * @author <a href="mailto:gluck@thoughtworks.com">Greg Luck</a>
35
 
 * @version $Id: ManualRMIPeerProviderTest.java 4741 2011-09-25 10:05:01Z asingh $
 
32
 * @version $Id: ManualRMIPeerProviderTest.java 6496 2012-10-31 14:34:15Z cdennis $
36
33
 */
37
34
public class ManualRMIPeerProviderTest extends MulticastRMIPeerProviderTest {
38
35
 
39
 
 
40
36
    /**
41
37
     * {@inheritDoc}
42
38
     */
43
39
    @Override
44
40
    @Before
45
41
    public void setUp() throws Exception {
46
 
        manager1 = new CacheManager(getConfiguration(AbstractCacheTest.TEST_CONFIG_DIR + "distribution/ehcache-manual-distributed1.xml").name("cm1"));
47
 
        manager2 = new CacheManager(getConfiguration(AbstractCacheTest.TEST_CONFIG_DIR + "distribution/ehcache-manual-distributed2.xml").name("cm2"));
48
 
        manager3 = new CacheManager(getConfiguration(AbstractCacheTest.TEST_CONFIG_DIR + "distribution/ehcache-manual-distributed3.xml").name("cm3"));
 
42
        List<Configuration> configurations = new ArrayList<Configuration>();
 
43
        configurations.add(getConfiguration(AbstractCacheTest.TEST_CONFIG_DIR + "distribution/ehcache-manual-distributed1.xml").name("cm1"));
 
44
        configurations.add(getConfiguration(AbstractCacheTest.TEST_CONFIG_DIR + "distribution/ehcache-manual-distributed2.xml").name("cm2"));
 
45
        configurations.add(getConfiguration(AbstractCacheTest.TEST_CONFIG_DIR + "distribution/ehcache-manual-distributed3.xml").name("cm3"));
 
46
 
 
47
        List<CacheManager> managers = startupManagers(configurations);
 
48
        manager1 = managers.get(0);
 
49
        manager2 = managers.get(1);
 
50
        manager3 = managers.get(2);
49
51
 
50
52
        /* manager3 has an empty manual configuration, which is topped up by adding manual entries.
51
53
         * The sampleCache1 from manager3 is added to the rmiUrls list for manager1 and manager2
52
54
         */
53
55
        CacheManagerPeerProvider peerProvider = manager3.getCacheManagerPeerProvider("RMI");
54
 
        peerProvider.registerPeer("//localhost:40001/sampleCache1");
55
 
        peerProvider.registerPeer("//localhost:40002/sampleCache1");
 
56
        peerProvider.registerPeer("//localhost:5011/sampleCache1");
 
57
        peerProvider.registerPeer("//localhost:5012/sampleCache1");
56
58
 
57
59
        //Allow cluster setup
58
60
        waitForClusterMembership(10, TimeUnit.SECONDS, Collections.singleton("sampleCache1"), manager1, manager2, manager3);
59
61
    }
60
 
 
61
 
 
62
 
    /**
63
 
     * test remote cache peers
64
 
     */
65
 
    @Override
66
 
    @Test
67
 
    public void testProviderFromCacheManager() throws InterruptedException {
68
 
        Ehcache m1sampleCache1 = manager1.getCache("sampleCache1");
69
 
        Thread.sleep(2000);
70
 
 
71
 
        List peerUrls = manager1.getCacheManagerPeerProvider("RMI").listRemoteCachePeers(m1sampleCache1);
72
 
        assertEquals(expectedPeers(), peerUrls.size());
73
 
 
74
 
        Ehcache m2sampleCache1 = manager2.getCache("sampleCache1");
75
 
        assertFalse(m1sampleCache1.getGuid().equals(m2sampleCache1.getGuid()));
76
 
 
77
 
        List peerUrls2 = manager2.getCacheManagerPeerProvider("RMI").listRemoteCachePeers(m2sampleCache1);
78
 
        assertEquals(expectedPeers(), peerUrls2.size());
79
 
 
80
 
        Ehcache m3sampleCache1 = manager3.getCache("sampleCache1");
81
 
        assertFalse(m1sampleCache1.getGuid().equals(m3sampleCache1.getGuid()));
82
 
 
83
 
        List peerUrls3 = manager3.getCacheManagerPeerProvider("RMI").listRemoteCachePeers(m3sampleCache1);
84
 
        assertEquals(expectedPeers(), peerUrls3.size());
85
 
 
86
 
        //Now remove a node, wait for the cluster to self-heal and then test
87
 
        manager1.shutdown();
88
 
        Thread.sleep(1000);
89
 
        peerUrls3 = manager3.getCacheManagerPeerProvider("RMI").listRemoteCachePeers(m3sampleCache1);
90
 
        //The manual provider removes the cache peer that was not reachable
91
 
        assertEquals(1, peerUrls3.size());
92
 
 
93
 
    }
94
 
 
95
 
 
96
62
}