use of org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager in project geode by apache.
the class ReconnectDUnitTest method testReconnectWithQuorum.
@Test
public void testReconnectWithQuorum() throws Exception {
// quorum check fails, then succeeds
IgnoredException.addIgnoredException("killing member's ds");
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM locatorVm = host.getVM(locatorVMNumber);
final int locPort = locatorPort;
final String xmlFileLoc = (new File(".")).getAbsolutePath();
// disable disconnects in the locator so we have some stability
host.getVM(locatorVMNumber).invoke(new SerializableRunnable("disable force-disconnect") {
public void run() {
GMSMembershipManager mgr = (GMSMembershipManager) MembershipManagerHelper.getMembershipManager(InternalDistributedSystem.getConnectedInstance());
mgr.disableDisconnectOnQuorumLossForTesting();
}
});
SerializableCallable create = new SerializableCallable("Create Cache and Regions from cache.xml") {
public Object call() throws CacheException {
// DebuggerSupport.waitForJavaDebugger(getLogWriter(), " about to create region");
locatorPort = locPort;
Properties props = getDistributedSystemProperties();
props.put(CACHE_XML_FILE, xmlFileLoc + fileSeparator + "MyDisconnect-cache.xml");
props.put(MAX_NUM_RECONNECT_TRIES, "2");
// props.put("log-file", "autoReconnectVM"+VM.getCurrentVMNum()+"_"+getPID()+".log");
Cache cache = new CacheFactory(props).create();
IgnoredException.addIgnoredException("org.apache.geode.ForcedDisconnectException||Possible loss of quorum");
Region myRegion = cache.getRegion("root/myRegion");
ReconnectDUnitTest.savedSystem = cache.getDistributedSystem();
myRegion.put("MyKey1", "MyValue1");
// myRegion.put("Mykey2", "MyValue2");
return savedSystem.getDistributedMember();
}
};
System.out.println("creating caches in vm0 and vm1");
vm0.invoke(create);
vm1.invoke(create);
// view is [locator(3), vm0(15), vm1(10), vm2(10)]
/*
* now we want to kick out the locator and observe that it reconnects using its rebooted
* location service
*/
System.out.println("disconnecting locator");
forceDisconnect(locatorVm);
waitForReconnect(locatorVm);
// if the locator reconnected it did so with its own location
// service since it doesn't know about any other locators
ensureLocationServiceRunning(locatorVm);
}
use of org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager in project geode by apache.
the class ReconnectedCacheServerDUnitTest method testCacheServerConfigRetained.
@Test
public void testCacheServerConfigRetained() {
// make sure the environment isn't polluted
assertFalse(Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "autoReconnect-useCacheXMLFile"));
InternalCache gc = (InternalCache) this.cache;
// fool the system into thinking cluster-config is being used
GMSMembershipManager mgr = (GMSMembershipManager) MembershipManagerHelper.getMembershipManager(gc.getDistributedSystem());
mgr.saveCacheXmlForReconnect(true);
// the cache server config should now be stored in the cache's config
assertFalse(gc.getCacheServers().isEmpty());
assertNotNull(gc.getCacheConfig().getCacheServerCreation());
}
use of org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager in project geode by apache.
the class MembershipJUnitTest method testLocatorAndTwoServersJoinUsingDiffeHellman.
/**
* This test ensures that secure communications are enabled.
*
* This test creates a locator with a colocated membership manager and then creates a second
* manager that joins the system of the first.
*
* It then makes assertions about the state of the membership view, closes one of the managers and
* makes more assertions.
*/
@Test
public void testLocatorAndTwoServersJoinUsingDiffeHellman() throws Exception {
MembershipManager m1 = null, m2 = null;
Locator l = null;
int mcastPort = AvailablePortHelper.getRandomAvailableUDPPort();
try {
// boot up a locator
int port = AvailablePortHelper.getRandomAvailableTCPPort();
InetAddress localHost = SocketCreator.getLocalHost();
Properties p = new Properties();
p.setProperty(ConfigurationProperties.SECURITY_UDP_DHALGO, "AES:128");
// this locator will hook itself up with the first MembershipManager
// to be created
l = InternalLocator.startLocator(port, new File(""), null, null, null, localHost, false, p, null);
// create configuration objects
Properties nonDefault = new Properties();
nonDefault.put(DistributionConfig.DISABLE_TCP_NAME, "true");
nonDefault.put(DistributionConfig.MCAST_PORT_NAME, String.valueOf(mcastPort));
nonDefault.put(DistributionConfig.LOG_FILE_NAME, "");
nonDefault.put(DistributionConfig.LOG_LEVEL_NAME, "fine");
nonDefault.put(DistributionConfig.GROUPS_NAME, "red, blue");
nonDefault.put(DistributionConfig.MEMBER_TIMEOUT_NAME, "2000");
nonDefault.put(DistributionConfig.LOCATORS_NAME, localHost.getHostName() + '[' + port + ']');
nonDefault.put(ConfigurationProperties.SECURITY_UDP_DHALGO, "AES:128");
DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
RemoteTransportConfig transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
// start the first membership manager
try {
System.setProperty(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY, "true");
DistributedMembershipListener listener1 = mock(DistributedMembershipListener.class);
DMStats stats1 = mock(DMStats.class);
System.out.println("creating 1st membership manager");
m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1);
m1.startEventProcessing();
} finally {
System.getProperties().remove(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY);
}
// start the second membership manager
DistributedMembershipListener listener2 = mock(DistributedMembershipListener.class);
DMStats stats2 = mock(DMStats.class);
System.out.println("creating 2nd membership manager");
m2 = MemberFactory.newMembershipManager(listener2, config, transport, stats2);
m2.startEventProcessing();
// we have to check the views with JoinLeave because the membership
// manager queues new views for processing through the DM listener,
// which is a mock object in this test
System.out.println("waiting for views to stabilize");
JoinLeave jl1 = ((GMSMembershipManager) m1).getServices().getJoinLeave();
JoinLeave jl2 = ((GMSMembershipManager) m2).getServices().getJoinLeave();
long giveUp = System.currentTimeMillis() + 15000;
for (; ; ) {
try {
assertTrue("view = " + jl2.getView(), jl2.getView().size() == 2);
assertTrue("view = " + jl1.getView(), jl1.getView().size() == 2);
assertTrue(jl1.getView().getCreator().equals(jl2.getView().getCreator()));
assertTrue(jl1.getView().getViewId() == jl2.getView().getViewId());
break;
} catch (AssertionError e) {
if (System.currentTimeMillis() > giveUp) {
throw e;
}
}
}
System.out.println("testing multicast availability");
assertTrue(m1.testMulticast());
System.out.println("multicasting SerialAckedMessage from m1 to m2");
SerialAckedMessage msg = new SerialAckedMessage();
msg.setRecipient(m2.getLocalMember());
msg.setMulticast(true);
m1.send(new InternalDistributedMember[] { m2.getLocalMember() }, msg, null);
giveUp = System.currentTimeMillis() + 5000;
boolean verified = false;
Throwable problem = null;
while (giveUp > System.currentTimeMillis()) {
try {
verify(listener2).messageReceived(isA(SerialAckedMessage.class));
verified = true;
break;
} catch (Error e) {
problem = e;
Thread.sleep(500);
}
}
if (!verified) {
if (problem != null) {
problem.printStackTrace();
}
fail("Expected a multicast message to be received");
}
// let the managers idle for a while and get used to each other
Thread.sleep(4000l);
m2.shutdown();
assertTrue(!m2.isConnected());
assertTrue(m1.getView().size() == 1);
} finally {
if (m2 != null) {
m2.shutdown();
}
if (m1 != null) {
m1.shutdown();
}
if (l != null) {
l.stop();
}
}
}
use of org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager in project geode by apache.
the class MembershipManagerHelper method crashDistributedSystem.
public static void crashDistributedSystem(final DistributedSystem msys) {
msys.getLogWriter().info("crashing distributed system: " + msys);
MembershipManagerHelper.inhibitForcedDisconnectLogging(true);
MembershipManagerHelper.beSickMember(msys);
MembershipManagerHelper.playDead(msys);
GMSMembershipManager mgr = ((GMSMembershipManager) getMembershipManager(msys));
mgr.forceDisconnect("for testing");
while (msys.isConnected()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
MembershipManagerHelper.inhibitForcedDisconnectLogging(false);
}
use of org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager 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();
}
}
}
Aggregations