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;
}
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();
}
}
}
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());
}
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();
}
}
}
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());
}
Aggregations