Search in sources :

Example 1 with InstallViewMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage 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)

Example 2 with InstallViewMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage in project geode by apache.

the class GMSJoinLeaveJUnitTest method testBecomeCoordinatorThroughViewChange.

@Test
public void testBecomeCoordinatorThroughViewChange() throws Exception {
    initMocks();
    prepareAndInstallView(mockMembers[0], createMemberList(mockMembers[0], gmsJoinLeaveMemberId));
    NetView oldView = gmsJoinLeave.getView();
    oldView.add(gmsJoinLeaveMemberId);
    NetView view = new NetView(oldView, oldView.getViewId() + 1);
    InternalDistributedMember creator = view.getCreator();
    view.remove(creator);
    InstallViewMessage msg = getInstallViewMessage(view, creator, false);
    msg.setSender(creator);
    gmsJoinLeave.processMessage(msg);
    assertTrue("Expected it to become coordinator", gmsJoinLeave.isCoordinator());
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) 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)

Example 3 with InstallViewMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage in project geode by apache.

the class GMSJoinLeaveJUnitTest method getInstallViewMessage.

private InstallViewMessage getInstallViewMessage(NetView view, Object credentials, boolean preparing) {
    InstallViewMessage installViewMessage = new InstallViewMessage(view, credentials, preparing);
    installViewMessage.setSender(gmsJoinLeaveMemberId);
    return installViewMessage;
}
Also used : InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage)

Example 4 with InstallViewMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage in project geode by apache.

the class GMSJoinLeaveJUnitTest method testConflictingPrepare.

@Test
public void testConflictingPrepare() throws Exception {
    initMocks(true);
    prepareAndInstallView(mockMembers[0], createMemberList(mockMembers[0], gmsJoinLeaveMemberId));
    NetView gmsView = gmsJoinLeave.getView();
    NetView newView = new NetView(gmsView, gmsView.getViewId() + 6);
    InstallViewMessage msg = getInstallViewMessage(newView, null, true);
    gmsJoinLeave.processMessage(msg);
    NetView alternateView = new NetView(gmsView, gmsView.getViewId() + 1);
    msg = getInstallViewMessage(alternateView, null, true);
    gmsJoinLeave.processMessage(msg);
    assertTrue(gmsJoinLeave.getPreparedView().equals(newView));
}
Also used : 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)

Example 5 with InstallViewMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage in project geode by apache.

the class GMSJoinLeaveJUnitTest method testForceDisconnectedFromNewView.

@Test
public void testForceDisconnectedFromNewView() throws IOException {
    // enabledNetworkPartition;
    initMocks(true);
    Manager mockManager = mock(Manager.class);
    when(services.getManager()).thenReturn(mockManager);
    prepareAndInstallView(mockMembers[0], createMemberList(mockMembers[0], gmsJoinLeaveMemberId));
    int viewId = 2;
    List<InternalDistributedMember> mbrs = new LinkedList<>();
    mbrs.add(mockMembers[1]);
    mbrs.add(mockMembers[2]);
    mbrs.add(mockMembers[3]);
    // install the view
    NetView netView = new NetView(mockMembers[0], viewId, mbrs);
    InstallViewMessage installViewMessage = getInstallViewMessage(netView, credentials, false);
    gmsJoinLeave.processMessage(installViewMessage);
    Assert.assertNotEquals(netView, gmsJoinLeave.getView());
    verify(mockManager).forceDisconnect(isA(String.class));
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) NetView(org.apache.geode.distributed.internal.membership.NetView) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) Manager(org.apache.geode.distributed.internal.membership.gms.interfaces.Manager) LinkedList(java.util.LinkedList) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

InstallViewMessage (org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage)16 NetView (org.apache.geode.distributed.internal.membership.NetView)15 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)12 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)12 Test (org.junit.Test)12 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)10 LinkedList (java.util.LinkedList)4 HashSet (java.util.HashSet)3 GMSMember (org.apache.geode.distributed.internal.membership.gms.GMSMember)2 ViewAckMessage (org.apache.geode.distributed.internal.membership.gms.messages.ViewAckMessage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 Properties (java.util.Properties)1 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)1 Manager (org.apache.geode.distributed.internal.membership.gms.interfaces.Manager)1 ViewCreator (org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave.ViewCreator)1 JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)1 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)1