Search in sources :

Example 26 with NetView

use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.

the class GMSJoinLeaveJUnitTest method testFindCoordinatorInView.

@Test
public void testFindCoordinatorInView() throws Exception {
    initMocks();
    int viewId = 1;
    List<InternalDistributedMember> mbrs = new LinkedList<>();
    mbrs.add(mockMembers[0]);
    mbrs.add(mockMembers[1]);
    mbrs.add(mockMembers[2]);
    when(services.getMessenger()).thenReturn(messenger);
    // prepare the view
    NetView netView = new NetView(mockMembers[0], viewId, mbrs);
    SearchState state = gmsJoinLeave.searchState;
    state.view = netView;
    state.viewId = netView.getViewId();
    InternalDistributedMember coordinator = mockMembers[2];
    coordinator.setVmViewId(viewId);
    // already tried joining using members 0 and 1
    Set<InternalDistributedMember> set = new HashSet<>();
    mockMembers[0].setVmViewId(viewId - 1);
    set.add(mockMembers[0]);
    mockMembers[1].setVmViewId(viewId - 1);
    set.add(mockMembers[1]);
    state.alreadyTried = set;
    state.hasContactedAJoinedLocator = true;
    // simulate a response being received
    InternalDistributedMember sender = mockMembers[2];
    FindCoordinatorResponse resp = new FindCoordinatorResponse(coordinator, sender, null, 0);
    gmsJoinLeave.processMessage(resp);
    // tell GMSJoinLeave that a unit test is running so it won't clear the
    // responses collection
    gmsJoinLeave.unitTesting.add("findCoordinatorFromView");
    // now for the test
    boolean result = gmsJoinLeave.findCoordinatorFromView();
    assertTrue("should have found coordinator " + mockMembers[2], result);
    assertTrue("should have found " + coordinator + " but found " + state.possibleCoordinator, state.possibleCoordinator == coordinator);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) FindCoordinatorResponse(org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorResponse) SearchState(org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave.SearchState) NetView(org.apache.geode.distributed.internal.membership.NetView) 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 27 with NetView

use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.

the class GMSJoinLeaveJUnitTest method testCoordinatorFindRequestFailure.

@Test
public void testCoordinatorFindRequestFailure() throws Exception {
    try {
        initMocks(false);
        HashSet<InternalDistributedMember> registrants = new HashSet<>();
        registrants.add(mockMembers[0]);
        FindCoordinatorResponse fcr = new FindCoordinatorResponse(mockMembers[0], mockMembers[0], false, null, registrants, false, true, null);
        NetView view = createView();
        JoinResponseMessage jrm = new JoinResponseMessage(mockMembers[0], view, 0);
        gmsJoinLeave.setJoinResponseMessage(jrm);
        TcpClientWrapper tcpClientWrapper = mock(TcpClientWrapper.class);
        gmsJoinLeave.setTcpClientWrapper(tcpClientWrapper);
        FindCoordinatorRequest fcreq = new FindCoordinatorRequest(gmsJoinLeaveMemberId, new HashSet<>(), -1, null, 0, "");
        int connectTimeout = (int) services.getConfig().getMemberTimeout() * 2;
        // passing wrong port here, so ot will fail
        when(tcpClientWrapper.sendCoordinatorFindRequest(new InetSocketAddress("localhost", 12346), fcreq, connectTimeout)).thenReturn(fcr);
        assertFalse("Should not be able to join ", gmsJoinLeave.join());
    } finally {
    }
}
Also used : TcpClientWrapper(org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave.TcpClientWrapper) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) FindCoordinatorResponse(org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorResponse) FindCoordinatorRequest(org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorRequest) InetSocketAddress(java.net.InetSocketAddress) NetView(org.apache.geode.distributed.internal.membership.NetView) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) 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 28 with NetView

use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.

the class GMSJoinLeaveJUnitTest method testCoordinatorShutsdownAndWeBecomeCoordinatorAndSendOutCorrectView.

/**
   * This tests a member shutdown using the memberShutdown call (simulating the call from
   * DistributionManager) The gmsJoinLeaveMemberId is not the coordinator but should now become the
   * coordinator.
   */
@Test
public void testCoordinatorShutsdownAndWeBecomeCoordinatorAndSendOutCorrectView() throws Exception {
    initMocks(false);
    prepareAndInstallView(mockMembers[0], createMemberList(mockMembers[0], gmsJoinLeaveMemberId, mockMembers[1], mockMembers[2], mockMembers[3]));
    Assert.assertFalse(gmsJoinLeave.isCoordinator());
    // The coordinator shuts down
    gmsJoinLeave.memberShutdown(mockMembers[0], "Shutdown");
    NetView nextView = gmsJoinLeave.getViewCreator().initialView;
    assertTrue(gmsJoinLeave.isCoordinator());
    assertTrue(nextView.getCoordinator().equals(gmsJoinLeaveMemberId));
    assertTrue(nextView.getMembers().contains(mockMembers[1]));
    assertTrue(nextView.getMembers().contains(mockMembers[2]));
    assertTrue(nextView.getMembers().contains(mockMembers[3]));
}
Also used : NetView(org.apache.geode.distributed.internal.membership.NetView) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 29 with NetView

use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.

the class GMSHealthMonitorJUnitTest method testHMServiceStarted.

@Test
public void testHMServiceStarted() throws IOException {
    InternalDistributedMember mbr = new InternalDistributedMember(SocketCreator.getLocalHost(), 12345);
    mbr.setVmViewId(1);
    when(messenger.getMemberID()).thenReturn(mbr);
    gmsHealthMonitor.started();
    NetView v = new NetView(mbr, 1, mockMembers);
    gmsHealthMonitor.processMessage(new HeartbeatRequestMessage(mbr, 1));
    verify(messenger, atLeastOnce()).send(any(HeartbeatMessage.class));
    Assert.assertEquals(1, gmsHealthMonitor.getStats().getHeartbeatRequestsReceived());
    Assert.assertEquals(1, gmsHealthMonitor.getStats().getHeartbeatsSent());
}
Also used : HeartbeatMessage(org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) 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 30 with NetView

use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.

the class GMSJoinLeaveJUnitTest method testQuorumLossNotificationWithNetworkPartitionDetectionDisabled.

@Test
public void testQuorumLossNotificationWithNetworkPartitionDetectionDisabled() throws IOException {
    initMocks(false);
    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<>();
    Set<InternalDistributedMember> shutdowns = new HashSet<>();
    Set<InternalDistributedMember> crashes = new HashSet<>();
    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, shutdowns, crashes);
    InstallViewMessage installViewMessage = getInstallViewMessage(newView, credentials, false);
    gmsJoinLeave.processMessage(installViewMessage);
    crashes = new HashSet<>(crashes);
    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, shutdowns, crashes);
    installViewMessage = getInstallViewMessage(partitionView, credentials, false);
    gmsJoinLeave.processMessage(installViewMessage);
    verify(manager, never()).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)

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