Search in sources :

Example 91 with NetView

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);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember) NetView(org.apache.geode.distributed.internal.membership.NetView) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 92 with NetView

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);
}
Also used : Answer(org.mockito.stubbing.Answer) HeartbeatMessage(org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NetView(org.apache.geode.distributed.internal.membership.NetView) HeartbeatRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatRequestMessage) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 93 with NetView

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);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) NetView(org.apache.geode.distributed.internal.membership.NetView) ArrayList(java.util.ArrayList) SuspectMembersMessage(org.apache.geode.distributed.internal.membership.gms.messages.SuspectMembersMessage) SuspectRequest(org.apache.geode.distributed.internal.membership.gms.messages.SuspectRequest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 94 with NetView

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);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) NetView(org.apache.geode.distributed.internal.membership.NetView) ArrayList(java.util.ArrayList) SuspectMembersMessage(org.apache.geode.distributed.internal.membership.gms.messages.SuspectMembersMessage) SuspectRequest(org.apache.geode.distributed.internal.membership.gms.messages.SuspectRequest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 95 with NetView

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());
}
Also used : Message(org.jgroups.Message) NetView(org.apache.geode.distributed.internal.membership.NetView) HashSet(java.util.HashSet) UnitTest(org.apache.geode.test.junit.categories.UnitTest) 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)101 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)65 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)59 Test (org.junit.Test)59 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)57 HashSet (java.util.HashSet)25 InstallViewMessage (org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage)18 Message (org.jgroups.Message)14 ArrayList (java.util.ArrayList)12 JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)10 UnitTest (org.apache.geode.test.junit.categories.UnitTest)10 LinkedList (java.util.LinkedList)9 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)9 IOException (java.io.IOException)8 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)8 Properties (java.util.Properties)7 FindCoordinatorResponse (org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorResponse)7 CancelException (org.apache.geode.CancelException)6 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)6 JoinRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)6