Search in sources :

Example 1 with CPMember

use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.

the class CPLiteMemberTest method liteMembers_shouldNotSelectedAsCPMembers_duringInitialDiscovery.

@Test
public void liteMembers_shouldNotSelectedAsCPMembers_duringInitialDiscovery() throws Exception {
    Config config = createConfig(3, 3);
    Config liteConfig = createConfig(3, 3).setLiteMember(true);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    HazelcastInstance hz2_lite = factory.newHazelcastInstance(liteConfig);
    HazelcastInstance hz3 = factory.newHazelcastInstance(config);
    HazelcastInstance hz4_lite = factory.newHazelcastInstance(liteConfig);
    // Discovery cannot be completed,
    // since there are not enough data members.
    assertFalse(awaitUntilDiscoveryCompleted(hz1, 1));
    assertFalse(awaitUntilDiscoveryCompleted(hz2_lite, 1));
    assertFalse(awaitUntilDiscoveryCompleted(hz3, 1));
    assertFalse(awaitUntilDiscoveryCompleted(hz4_lite, 1));
    // Start 3rd data member
    HazelcastInstance hz5 = factory.newHazelcastInstance(config);
    // Discovery can be completed now...
    assertTrue(awaitUntilDiscoveryCompleted(hz1, 60));
    assertTrue(awaitUntilDiscoveryCompleted(hz2_lite, 60));
    assertTrue(awaitUntilDiscoveryCompleted(hz3, 60));
    assertTrue(awaitUntilDiscoveryCompleted(hz4_lite, 60));
    assertTrue(awaitUntilDiscoveryCompleted(hz5, 60));
    Collection<CPMember> cpMembers = hz5.getCPSubsystem().getCPSubsystemManagementService().getCPMembers().toCompletableFuture().get();
    // Lite members are not part of CP member list
    assertNotCpMember(hz2_lite, cpMembers);
    assertNotCpMember(hz4_lite, cpMembers);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with CPMember

use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.

the class CPLiteMemberTest method liteMembers_canBePromotedToCPMember_afterPromotedToDataMember.

@Test
public void liteMembers_canBePromotedToCPMember_afterPromotedToDataMember() throws Exception {
    Config config = createConfig(3, 3);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    HazelcastInstance hz2 = factory.newHazelcastInstance(config);
    HazelcastInstance hz3 = factory.newHazelcastInstance(config);
    HazelcastInstance hz_lite = factory.newHazelcastInstance(createConfig(3, 3).setLiteMember(true));
    assertTrue(awaitUntilDiscoveryCompleted(hz1, 60));
    assertTrue(awaitUntilDiscoveryCompleted(hz_lite, 60));
    hz_lite.getCluster().promoteLocalLiteMember();
    hz_lite.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    Collection<CPMember> cpMembers = hz1.getCPSubsystem().getCPSubsystemManagementService().getCPMembers().toCompletableFuture().get();
    assertEquals(4, cpMembers.size());
    Set<Address> cpAddresses = cpMembers.stream().map(CPMember::getAddress).collect(Collectors.toSet());
    assertThat(cpAddresses, hasItem(getAddress(hz_lite)));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) Accessors.getAddress(com.hazelcast.test.Accessors.getAddress) Config(com.hazelcast.config.Config) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with CPMember

use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.

the class CPMemberAutoRemoveTest method when_missingCPNodeJoins_then_itIsNotAutomaticallyRemoved.

@Test
public void when_missingCPNodeJoins_then_itIsNotAutomaticallyRemoved() {
    missingRaftMemberRemovalSeconds = 300;
    HazelcastInstance[] instances = newInstances(3, 3, 0);
    CPMember cpMember0 = instances[0].getCPSubsystem().getLocalCPMember();
    CPMember cpMember1 = instances[1].getCPSubsystem().getLocalCPMember();
    CPMember cpMember2 = instances[2].getCPSubsystem().getLocalCPMember();
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            assertEquals(3, getRaftService(instance).getMetadataGroupManager().getActiveMembers().size());
        }
    });
    blockCommunicationBetween(instances[1], instances[2]);
    blockCommunicationBetween(instances[0], instances[2]);
    closeConnectionBetween(instances[1], instances[2]);
    closeConnectionBetween(instances[0], instances[2]);
    assertClusterSizeEventually(2, instances[0], instances[1]);
    assertClusterSizeEventually(1, instances[2]);
    assertTrueEventually(() -> {
        assertThat(getRaftService(instances[0]).getMissingMembers(), hasItem((CPMemberInfo) cpMember2));
        assertThat(getRaftService(instances[1]).getMissingMembers(), hasItem((CPMemberInfo) cpMember2));
        assertThat(getRaftService(instances[2]).getMissingMembers(), hasItem((CPMemberInfo) cpMember0));
        assertThat(getRaftService(instances[2]).getMissingMembers(), hasItem((CPMemberInfo) cpMember1));
    });
    unblockCommunicationBetween(instances[1], instances[2]);
    unblockCommunicationBetween(instances[0], instances[2]);
    assertClusterSizeEventually(3, instances);
    assertTrueEventually(() -> {
        assertThat(getRaftService(instances[0]).getMissingMembers(), Matchers.empty());
        assertThat(getRaftService(instances[1]).getMissingMembers(), Matchers.empty());
        assertThat(getRaftService(instances[2]).getMissingMembers(), Matchers.empty());
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with CPMember

use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.

the class MetadataRaftGroupTest method when_nonMetadataRaftGroupLosesMajority_then_itCanBeForceDestroyed.

@Test
public void when_nonMetadataRaftGroupLosesMajority_then_itCanBeForceDestroyed() throws ExecutionException, InterruptedException {
    instances = newInstances(5);
    waitAllForLeaderElection(instances, getMetadataGroupId(instances[0]));
    CPGroupId groupId = createNewRaftGroup(instances[0], "id", 3);
    CPGroup group = instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup("id").toCompletableFuture().get();
    assertNotNull(group);
    assertEquals(groupId, group.id());
    CPMember[] groupMembers = group.members().toArray(new CPMember[0]);
    assertTrueEventually(() -> {
        for (CPMember member : groupMembers) {
            HazelcastInstance instance = factory.getInstance(member.getAddress());
            assertNotNull(getRaftNode(instance, groupId));
        }
    });
    factory.getInstance(groupMembers[0].getAddress()).getLifecycleService().terminate();
    factory.getInstance(groupMembers[1].getAddress()).getLifecycleService().terminate();
    HazelcastInstance runningInstance = factory.getInstance(groupMembers[2].getAddress());
    getRaftService(runningInstance).forceDestroyCPGroup(groupId.getName()).get();
    group = getRaftService(runningInstance).getCPGroup(groupId).get();
    assertEquals(CPGroupStatus.DESTROYED, group.status());
    assertTrueEventually(() -> assertNull(getRaftNode(runningInstance, groupId)));
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with CPMember

use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.

the class MetadataRaftGroupTest method when_memberIsShutdown_then_itIsRemovedFromRaftGroups.

@Test
public void when_memberIsShutdown_then_itIsRemovedFromRaftGroups() throws ExecutionException, InterruptedException {
    int cpNodeCount = 7;
    int metadataGroupSize = 5;
    int atomicLong1GroupSize = 3;
    instances = newInstances(cpNodeCount, metadataGroupSize, 0);
    CPGroupId groupId1 = createNewRaftGroup(instances[0], "id1", atomicLong1GroupSize);
    CPGroupId groupId2 = createNewRaftGroup(instances[0], "id2", cpNodeCount);
    CPMember endpoint = findCommonEndpoint(instances[0], getMetadataGroupId(instances[0]), groupId1);
    assertNotNull(endpoint);
    RaftInvocationManager invocationService = null;
    HazelcastInstance aliveInstance = null;
    for (HazelcastInstance instance : instances) {
        if (!getAddress(instance).equals(endpoint.getAddress())) {
            aliveInstance = instance;
            invocationService = getRaftInvocationManager(instance);
            break;
        }
    }
    assertNotNull(invocationService);
    factory.getInstance(endpoint.getAddress()).shutdown();
    CPGroupId metadataGroupId = getMetadataGroupId(aliveInstance);
    InternalCompletableFuture<List<CPMember>> f1 = invocationService.query(metadataGroupId, new GetActiveCPMembersOp(), LINEARIZABLE);
    List<CPMember> activeEndpoints = f1.get();
    assertThat(activeEndpoints, not(hasItem(endpoint)));
    InternalCompletableFuture<CPGroup> f2 = invocationService.query(metadataGroupId, new GetRaftGroupOp(metadataGroupId), LINEARIZABLE);
    InternalCompletableFuture<CPGroup> f3 = invocationService.query(metadataGroupId, new GetRaftGroupOp(groupId1), LINEARIZABLE);
    InternalCompletableFuture<CPGroup> f4 = invocationService.query(metadataGroupId, new GetRaftGroupOp(groupId2), LINEARIZABLE);
    CPGroup metadataGroup = f2.get();
    assertFalse(metadataGroup.members().contains(endpoint));
    assertEquals(metadataGroupSize, metadataGroup.members().size());
    CPGroup atomicLongGroup1 = f3.get();
    assertFalse(atomicLongGroup1.members().contains(endpoint));
    assertEquals(atomicLong1GroupSize, atomicLongGroup1.members().size());
    CPGroup atomicLongGroup2 = f4.get();
    assertFalse(atomicLongGroup2.members().contains(endpoint));
    assertEquals(cpNodeCount - 1, atomicLongGroup2.members().size());
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) GetRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

CPMember (com.hazelcast.cp.CPMember)57 HazelcastInstance (com.hazelcast.core.HazelcastInstance)40 Test (org.junit.Test)38 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)27 SlowTest (com.hazelcast.test.annotation.SlowTest)27 CPGroup (com.hazelcast.cp.CPGroup)17 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)16 CPGroupId (com.hazelcast.cp.CPGroupId)14 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 ArrayList (java.util.ArrayList)11 Config (com.hazelcast.config.Config)10 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)10 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)7 GetActiveCPMembersOp (com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp)6 JsonArray (com.hazelcast.internal.json.JsonArray)6 JsonObject (com.hazelcast.internal.json.JsonObject)6 TestHazelcastInstanceFactory.initOrCreateConfig (com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig)6 CPSubsystemManagementService (com.hazelcast.cp.CPSubsystemManagementService)4 JsonValue (com.hazelcast.internal.json.JsonValue)4