Search in sources :

Example 1 with SearchState

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

Aggregations

HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 NetView (org.apache.geode.distributed.internal.membership.NetView)1 FindCoordinatorResponse (org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorResponse)1 SearchState (org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave.SearchState)1 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)1 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)1 Test (org.junit.Test)1