use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSJoinLeaveJUnitTest method testNetworkPartitionDetected.
@Test
public void testNetworkPartitionDetected() throws IOException {
initMocks(true);
prepareAndInstallView(mockMembers[0], createMemberList(mockMembers[0], gmsJoinLeaveMemberId));
// set up a view with sufficient members, then create a new view
// where enough weight is lost to cause a network partition
List<InternalDistributedMember> mbrs = new LinkedList<>();
mbrs.add(mockMembers[0]);
mbrs.add(mockMembers[1]);
mbrs.add(mockMembers[2]);
mbrs.add(gmsJoinLeaveMemberId);
((GMSMember) mockMembers[1].getNetMember()).setMemberWeight((byte) 20);
NetView newView = new NetView(mockMembers[0], gmsJoinLeave.getView().getViewId() + 1, mbrs);
InstallViewMessage installViewMessage = getInstallViewMessage(newView, credentials, false);
gmsJoinLeave.processMessage(installViewMessage);
Set<InternalDistributedMember> crashes = new HashSet<>();
crashes.add(mockMembers[1]);
crashes.add(mockMembers[2]);
mbrs = new LinkedList<>(mbrs);
mbrs.remove(mockMembers[1]);
mbrs.remove(mockMembers[2]);
NetView partitionView = new NetView(mockMembers[0], newView.getViewId() + 1, mbrs, Collections.emptySet(), crashes);
installViewMessage = getInstallViewMessage(partitionView, credentials, false);
gmsJoinLeave.processMessage(installViewMessage);
verify(manager).forceDisconnect(isA(String.class));
verify(manager).quorumLost(crashes, newView);
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSHealthMonitorJUnitTest method testCheckIfAvailableWithSimulatedHeartBeat.
@Test
public void testCheckIfAvailableWithSimulatedHeartBeat() {
NetView v = installAView();
InternalDistributedMember memberToCheck = mockMembers.get(1);
HeartbeatMessage fakeHeartbeat = new HeartbeatMessage();
fakeHeartbeat.setSender(memberToCheck);
when(messenger.send(any(HeartbeatRequestMessage.class))).then(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
gmsHealthMonitor.processMessage(fakeHeartbeat);
return null;
}
});
boolean retVal = gmsHealthMonitor.checkIfAvailable(memberToCheck, "Not responding", true);
assertTrue("CheckIfAvailable should have return true", retVal);
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSHealthMonitorJUnitTest method testRemoveMemberCalled.
/***
* Send remove member message after doing final check, ping Timeout
*/
@Test
public void testRemoveMemberCalled() throws Exception {
System.out.println("testRemoveMemberCalled starting");
NetView v = new NetView(mockMembers.get(0), 2, mockMembers);
// 3rd is current member
// coordinator and local member
when(messenger.getMemberID()).thenReturn(mockMembers.get(0));
gmsHealthMonitor.started();
gmsHealthMonitor.installView(v);
Thread.sleep(memberTimeout / GMSHealthMonitor.LOGICAL_INTERVAL);
ArrayList<InternalDistributedMember> recipient = new ArrayList<InternalDistributedMember>();
recipient.add(mockMembers.get(0));
ArrayList<SuspectRequest> as = new ArrayList<SuspectRequest>();
// removing member
SuspectRequest sr = new SuspectRequest(mockMembers.get(1), "Not Responding");
// 1
as.add(sr);
SuspectMembersMessage sm = new SuspectMembersMessage(recipient, as);
sm.setSender(mockMembers.get(0));
gmsHealthMonitor.processMessage(sm);
Awaitility.await("waiting for remove(member) to be invoked").atMost(3 * memberTimeout, TimeUnit.SECONDS).until(() -> {
verify(joinLeave, atLeastOnce()).remove(any(InternalDistributedMember.class), any(String.class));
});
Assert.assertTrue(gmsHealthMonitor.getStats().getSuspectsReceived() > 0);
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSHealthMonitorJUnitTest method testRemoveMemberNotCalledBeforeTimeout.
/***
* Shouldn't send remove member message before doing final check, or before ping Timeout
*/
@Test
public void testRemoveMemberNotCalledBeforeTimeout() {
System.out.println("testRemoveMemberNotCalledBeforeTimeout starting");
NetView v = new NetView(mockMembers.get(0), 2, mockMembers);
// 3rd is current member
// coordinator and local member
when(messenger.getMemberID()).thenReturn(mockMembers.get(0));
// coordinator and local member
when(joinLeave.getMemberID()).thenReturn(mockMembers.get(0));
gmsHealthMonitor.started();
gmsHealthMonitor.installView(v);
ArrayList<InternalDistributedMember> recipient = new ArrayList<InternalDistributedMember>();
recipient.add(mockMembers.get(0));
ArrayList<SuspectRequest> as = new ArrayList<SuspectRequest>();
// removing member
SuspectRequest sr = new SuspectRequest(mockMembers.get(1), "Not Responding");
// 1
as.add(sr);
SuspectMembersMessage sm = new SuspectMembersMessage(recipient, as);
sm.setSender(mockMembers.get(0));
gmsHealthMonitor.processMessage(sm);
try {
// this happens after final check, ping timeout
Thread.sleep(memberTimeout - 100);
} catch (InterruptedException e) {
}
System.out.println("testRemoveMemberNotCalledBeforeTimeout ending");
verify(joinLeave, never()).remove(any(InternalDistributedMember.class), any(String.class));
Assert.assertTrue(gmsHealthMonitor.getStats().getSuspectsReceived() > 0);
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSQuorumCheckerJUnitTest method testQuorumChecker10Servers2Locators4ServersLost.
@Test
public void testQuorumChecker10Servers2Locators4ServersLost() throws Exception {
NetView view = prepareView();
mockMembers[0].setVmKind(DistributionManager.LOCATOR_DM_TYPE);
mockMembers[1].setVmKind(DistributionManager.LOCATOR_DM_TYPE);
Set<Integer> pongResponders = new HashSet<Integer>();
for (int i = 0; i < mockMembers.length; i++) {
pongResponders.add(mockMembers[i].getPort());
}
// remove 4 servers
pongResponders.remove(mockMembers[8].getPort());
pongResponders.remove(mockMembers[9].getPort());
pongResponders.remove(mockMembers[10].getPort());
pongResponders.remove(mockMembers[11].getPort());
PingMessageAnswer answerer = new PingMessageAnswer(channel, pongResponders);
Mockito.doAnswer(answerer).when(channel).send(any(Message.class));
GMSQuorumChecker qc = new GMSQuorumChecker(view, 51, channel);
qc.initialize();
boolean quorum = qc.checkForQuorum(500);
assertTrue(quorum);
assertSame(view.getMembers().size(), answerer.getPingCount());
}
Aggregations