Search in sources :

Example 11 with MembershipManager

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

the class MembershipManagerHelper method getMembershipManager.

/** returns the JGroupMembershipManager for the given distributed system */
public static MembershipManager getMembershipManager(DistributedSystem sys) {
    InternalDistributedSystem isys = (InternalDistributedSystem) sys;
    DistributionManager dm = (DistributionManager) isys.getDM();
    MembershipManager mgr = dm.getMembershipManager();
    return mgr;
}
Also used : GMSMembershipManager(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager) MembershipManager(org.apache.geode.distributed.internal.membership.MembershipManager) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributionManager(org.apache.geode.distributed.internal.DistributionManager)

Example 12 with MembershipManager

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

the class DistributionManagerDUnitTest method testSurpriseMemberHandling.

/**
   * Test the handling of "surprise members" in the membership manager. Create a DistributedSystem
   * in this VM and then add a fake member to its surpriseMember set. Then ensure that it stays in
   * the set when a new membership view arrives that doesn't contain it. Then wait until the member
   * should be gone and force more view processing to have it scrubbed from the set.
   **/
@Test
public void testSurpriseMemberHandling() throws Exception {
    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "surprise-member-timeout", "3000");
    InternalDistributedSystem sys = getSystem();
    MembershipManager mgr = MembershipManagerHelper.getMembershipManager(sys);
    assertTrue(((GMSMembershipManager) mgr).isCleanupTimerStarted());
    try {
        InternalDistributedMember mbr = new InternalDistributedMember(NetworkUtils.getIPLiteral(), 12345);
        // first make sure we can't add this as a surprise member (bug #44566)
        // if the view number isn't being recorded correctly the test will pass but the
        // functionality is broken
        Assert.assertTrue("expected view ID to be greater than zero", mgr.getView().getViewId() > 0);
        int oldViewId = mbr.getVmViewId();
        mbr.setVmViewId((int) mgr.getView().getViewId() - 1);
        org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("current membership view is " + mgr.getView());
        org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("created ID " + mbr + " with view ID " + mbr.getVmViewId());
        IgnoredException.addIgnoredException("attempt to add old member");
        IgnoredException.addIgnoredException("Removing shunned GemFire node");
        boolean accepted = mgr.addSurpriseMember(mbr);
        Assert.assertTrue("member with old ID was not rejected (bug #44566)", !accepted);
        mbr.setVmViewId(oldViewId);
        // now forcibly add it as a surprise member and show that it is reaped
        long gracePeriod = 5000;
        long startTime = System.currentTimeMillis();
        long timeout = ((GMSMembershipManager) mgr).getSurpriseMemberTimeout();
        long birthTime = startTime - timeout + gracePeriod;
        MembershipManagerHelper.addSurpriseMember(sys, mbr, birthTime);
        assertTrue("Member was not a surprise member", mgr.isSurpriseMember(mbr));
        // if (birthTime < (System.currentTimeMillis() - timeout)) {
        // return; // machine is too busy and we didn't get enough CPU to perform more assertions
        // }
        Awaitility.await("waiting for member to be removed").atMost((timeout / 3) + gracePeriod, TimeUnit.MILLISECONDS).until(() -> !mgr.isSurpriseMember(mbr));
    } finally {
        if (sys != null && sys.isConnected()) {
            sys.disconnect();
        }
    }
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) GMSMembershipManager(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager) GMSMembershipManager(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager) MembershipManager(org.apache.geode.distributed.internal.membership.MembershipManager) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 13 with MembershipManager

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

the class DistributionManagerDUnitTest method testConnectAfterBeingShunned.

/**
   * Demonstrate that a new UDP port is used when an attempt is made to reconnect using a shunned
   * port
   */
@Test
public void testConnectAfterBeingShunned() {
    InternalDistributedSystem sys = getSystem();
    MembershipManager mgr = MembershipManagerHelper.getMembershipManager(sys);
    InternalDistributedMember idm = mgr.getLocalMember();
    // TODO GMS needs to have a system property allowing the bind-port to be set
    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "jg-bind-port", "" + idm.getPort());
    sys.disconnect();
    sys = getSystem();
    mgr = MembershipManagerHelper.getMembershipManager(sys);
    sys.disconnect();
    InternalDistributedMember idm2 = mgr.getLocalMember();
    org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("original ID=" + idm + " and after connecting=" + idm2);
    assertTrue("should not have used a different udp port", idm.getPort() == idm2.getPort());
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) GMSMembershipManager(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager) MembershipManager(org.apache.geode.distributed.internal.membership.MembershipManager) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 14 with MembershipManager

use of org.apache.geode.distributed.internal.membership.MembershipManager 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)

Example 15 with MembershipManager

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

the class P2PAuthenticationDUnitTest method verifyMembers.

private static void verifyMembers(final int numExpectedMembers) {
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    MembershipManager mgr = MembershipManagerHelper.getMembershipManager(ds);
    assertEquals(numExpectedMembers, mgr.getView().size());
}
Also used : MembershipManager(org.apache.geode.distributed.internal.membership.MembershipManager) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Aggregations

MembershipManager (org.apache.geode.distributed.internal.membership.MembershipManager)16 GMSMembershipManager (org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager)6 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)6 Test (org.junit.Test)6 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)5 Properties (java.util.Properties)4 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)4 IOException (java.io.IOException)3 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)3 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)3 File (java.io.File)2 ForcedDisconnectException (org.apache.geode.ForcedDisconnectException)2 GemFireConfigException (org.apache.geode.GemFireConfigException)2 SystemConnectException (org.apache.geode.SystemConnectException)2 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)2 NetView (org.apache.geode.distributed.internal.membership.NetView)2 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)2 Host (org.apache.geode.test.dunit.Host)2 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)2 VM (org.apache.geode.test.dunit.VM)2