Search in sources :

Example 1 with DistributedMembershipListener

use of org.apache.geode.distributed.internal.membership.DistributedMembershipListener in project geode by apache.

the class GMSLocatorRecoveryJUnitTest method testRecoverFromOther.

@Test
public void testRecoverFromOther() throws Exception {
    MembershipManager m1 = null, m2 = null;
    Locator l = null;
    try {
        // boot up a locator
        int port = AvailablePortHelper.getRandomAvailableTCPPort();
        InetAddress localHost = SocketCreator.getLocalHost();
        // this locator will hook itself up with the first MembershipManager
        // to be created
        // l = Locator.startLocator(port, new File(""), localHost);
        l = InternalLocator.startLocator(port, new File(""), null, null, null, localHost, false, new Properties(), null);
        // create configuration objects
        Properties nonDefault = new Properties();
        nonDefault.put(DISABLE_TCP, "true");
        nonDefault.put(MCAST_PORT, "0");
        nonDefault.put(LOG_FILE, "");
        nonDefault.put(LOG_LEVEL, "fine");
        nonDefault.put(LOCATORS, localHost.getHostAddress() + '[' + port + ']');
        nonDefault.put(BIND_ADDRESS, localHost.getHostAddress());
        DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
        RemoteTransportConfig transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
        // start the first membership manager
        DistributedMembershipListener listener1 = mock(DistributedMembershipListener.class);
        DMStats stats1 = mock(DMStats.class);
        m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1);
        // hook up the locator to the membership manager
        ((InternalLocator) l).getLocatorHandler().setMembershipManager(m1);
        GMSLocator l2 = new GMSLocator(SocketCreator.getLocalHost(), new File("l2.dat"), m1.getLocalMember().getHost() + "[" + port + "]", true, true, new LocatorStats(), "");
        l2.init(null);
        assertTrue("expected view to contain " + m1.getLocalMember() + ": " + l2.getMembers(), l2.getMembers().contains(m1.getLocalMember()));
    } finally {
        if (m1 != null) {
            m1.shutdown();
        }
        if (l != null) {
            l.stop();
        }
    }
}
Also used : Locator(org.apache.geode.distributed.Locator) MembershipManager(org.apache.geode.distributed.internal.membership.MembershipManager) RemoteTransportConfig(org.apache.geode.internal.admin.remote.RemoteTransportConfig) DistributedMembershipListener(org.apache.geode.distributed.internal.membership.DistributedMembershipListener) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) InetAddress(java.net.InetAddress) File(java.io.File) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

File (java.io.File)1 InetAddress (java.net.InetAddress)1 Properties (java.util.Properties)1 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)1 Locator (org.apache.geode.distributed.Locator)1 DistributedMembershipListener (org.apache.geode.distributed.internal.membership.DistributedMembershipListener)1 MembershipManager (org.apache.geode.distributed.internal.membership.MembershipManager)1 RemoteTransportConfig (org.apache.geode.internal.admin.remote.RemoteTransportConfig)1 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)1 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)1 Test (org.junit.Test)1