use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSJoinLeaveJUnitTest method testRemoveAndLeaveIsNotACrash.
@Test
public void testRemoveAndLeaveIsNotACrash() throws Exception {
// simultaneous leave & remove requests for a member
// should not result in it's being seen as a crashed member
initMocks();
final int viewInstallationTime = 15000;
when(healthMonitor.checkIfAvailable(isA(InternalDistributedMember.class), isA(String.class), isA(Boolean.class))).thenReturn(true);
// ensures multiple requests are queued for a view
gmsJoinLeave.delayViewCreationForTest(5000);
// change
GMSJoinLeaveTestHelper.becomeCoordinatorForTest(gmsJoinLeave);
Awaitility.await().atMost(viewInstallationTime, MILLISECONDS).until(() -> gmsJoinLeave.getView() != null);
NetView oldView = gmsJoinLeave.getView();
NetView newView = new NetView(oldView, oldView.getViewId() + 1);
newView.add(mockMembers[1]);
newView.add(mockMembers[2]);
gmsJoinLeave.installView(newView);
gmsJoinLeave.memberShutdown(mockMembers[1], "shutting down for test");
gmsJoinLeave.remove(mockMembers[1], "removing for test");
Awaitility.await().atMost(viewInstallationTime, MILLISECONDS).until(() -> gmsJoinLeave.getView().getViewId() > newView.getViewId());
assertFalse(gmsJoinLeave.getView().getCrashedMembers().contains(mockMembers[1]));
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSJoinLeaveJUnitTest method testBecomeCoordinator.
@Test
public void testBecomeCoordinator() throws Exception {
String reason = "testing";
initMocks();
prepareAndInstallView(mockMembers[0], createMemberList(mockMembers[0], gmsJoinLeaveMemberId));
NetView view = gmsJoinLeave.getView();
view.add(gmsJoinLeaveMemberId);
InternalDistributedMember creator = view.getCreator();
LeaveRequestMessage msg = new LeaveRequestMessage(creator, creator, reason);
msg.setSender(creator);
gmsJoinLeave.processMessage(msg);
assertTrue("Expected becomeCoordinator to be invoked", gmsJoinLeave.isCoordinator());
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSJoinLeaveJUnitTest method testRejectOlderView.
@Test
public void testRejectOlderView() throws IOException {
initMocks();
prepareAndInstallView(mockMembers[0], createMemberList(mockMembers[0], gmsJoinLeaveMemberId));
List<InternalDistributedMember> mbrs = new LinkedList<>();
mbrs.add(mockMembers[0]);
mbrs.add(mockMembers[1]);
// try to install an older view where viewId < currentView.viewId
NetView olderNetView = new NetView(mockMembers[0], 0, mbrs);
InstallViewMessage installViewMessage = getInstallViewMessage(olderNetView, credentials, false);
gmsJoinLeave.processMessage(installViewMessage);
Assert.assertNotEquals(gmsJoinLeave.getView(), olderNetView);
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSJoinLeaveJUnitTest method prepareAndInstallView.
/**
* prepares and install a view
*
* @throws IOException
*/
private void prepareAndInstallView(InternalDistributedMember coordinator, List<InternalDistributedMember> members) throws IOException {
int viewId = 1;
when(services.getMessenger()).thenReturn(messenger);
// prepare the view
NetView netView = new NetView(coordinator, viewId, members);
InstallViewMessage installViewMessage = getInstallViewMessage(netView, credentials, true);
gmsJoinLeave.processMessage(installViewMessage);
verify(messenger).send(isA(ViewAckMessage.class));
// install the view
installViewMessage = getInstallViewMessage(netView, credentials, false);
gmsJoinLeave.processMessage(installViewMessage);
Assert.assertEquals(netView, gmsJoinLeave.getView());
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSJoinLeaveJUnitTest method testDuplicateLeaveRequestDoesNotCauseNewView.
@Test
public void testDuplicateLeaveRequestDoesNotCauseNewView() throws Exception {
String reason = "testing";
initMocks();
gmsJoinLeave.unitTesting.add("noRandomViewChange");
prepareAndInstallView(gmsJoinLeaveMemberId, createMemberList(gmsJoinLeaveMemberId, mockMembers[0]));
GMSJoinLeaveTestHelper.becomeCoordinatorForTest(gmsJoinLeave);
LeaveRequestMessage msg = new LeaveRequestMessage(gmsJoinLeave.getMemberID(), mockMembers[0], reason);
msg.setSender(mockMembers[0]);
gmsJoinLeave.processMessage(msg);
msg = new LeaveRequestMessage(gmsJoinLeave.getMemberID(), mockMembers[0], reason);
msg.setSender(mockMembers[0]);
gmsJoinLeave.processMessage(msg);
waitForViewAndNoRequestsInProgress(7);
NetView view = gmsJoinLeave.getView();
assertTrue("expected member to be removed: " + mockMembers[0] + "; view: " + view, !view.contains(mockMembers[0]));
assertTrue("expected member to be in shutdownMembers collection: " + mockMembers[0] + "; view: " + view, view.getShutdownMembers().contains(mockMembers[0]));
}
Aggregations