Search in sources :

Example 1 with ViewCreator

use of org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave.ViewCreator in project geode by apache.

the class GMSJoinLeaveJUnitTest method testPreparedViewFoundDuringBecomeCoordinator.

@Test
public void testPreparedViewFoundDuringBecomeCoordinator() throws Exception {
    initMocks(false);
    prepareAndInstallView(gmsJoinLeaveMemberId, createMemberList(gmsJoinLeaveMemberId, mockMembers[0]));
    // a new member is joining
    NetView preparedView = new NetView(gmsJoinLeave.getView(), gmsJoinLeave.getView().getViewId() + 5);
    mockMembers[1].setVmViewId(preparedView.getViewId());
    preparedView.add(mockMembers[1]);
    InstallViewMessage msg = getInstallViewMessage(preparedView, null, true);
    gmsJoinLeave.processMessage(msg);
    GMSJoinLeaveTestHelper.becomeCoordinatorForTest(gmsJoinLeave);
    Thread.sleep(2000);
    ViewCreator vc = gmsJoinLeave.getViewCreator();
    int viewId = 0;
    if (gmsJoinLeave.getPreparedView() == null) {
        viewId = gmsJoinLeave.getView().getViewId();
    } else {
        viewId = gmsJoinLeave.getPreparedView().getViewId();
    }
    ViewAckMessage vack = new ViewAckMessage(gmsJoinLeaveMemberId, viewId, true);
    vack.setSender(mockMembers[0]);
    gmsJoinLeave.processMessage(vack);
    vack = new ViewAckMessage(gmsJoinLeaveMemberId, viewId, true);
    vack.setSender(mockMembers[1]);
    gmsJoinLeave.processMessage(vack);
    vack = new ViewAckMessage(gmsJoinLeaveMemberId, viewId, true);
    vack.setSender(gmsJoinLeaveMemberId);
    gmsJoinLeave.processMessage(vack);
    Awaitility.await("view creator finishes").atMost(30, SECONDS).until(() -> vc.waiting);
    NetView newView = gmsJoinLeave.getView();
    System.out.println("new view is " + newView);
    assertTrue(newView.contains(mockMembers[1]));
    assertTrue(newView.getViewId() > preparedView.getViewId());
}
Also used : ViewCreator(org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave.ViewCreator) ViewAckMessage(org.apache.geode.distributed.internal.membership.gms.messages.ViewAckMessage) NetView(org.apache.geode.distributed.internal.membership.NetView) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

NetView (org.apache.geode.distributed.internal.membership.NetView)1 ViewCreator (org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave.ViewCreator)1 InstallViewMessage (org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage)1 ViewAckMessage (org.apache.geode.distributed.internal.membership.gms.messages.ViewAckMessage)1 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)1 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)1 Test (org.junit.Test)1