Search in sources :

Example 1 with CPGroupId

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

the class MetadataRaftGroupTest method when_raftGroupIsCreatedWithSomeCPNodes_then_raftNodeIsCreatedOnOnlyTheSelectedEndpoints.

private void when_raftGroupIsCreatedWithSomeCPNodes_then_raftNodeIsCreatedOnOnlyTheSelectedEndpoints(boolean invokeOnCP) {
    int cpNodeCount = 6;
    int metadataGroupSize = 3;
    int nonCpNodeCount = 2;
    instances = newInstances(cpNodeCount, metadataGroupSize, nonCpNodeCount);
    int newGroupCount = metadataGroupSize + 1;
    HazelcastInstance instance = instances[invokeOnCP ? 0 : instances.length - 1];
    CPGroupId groupId = createNewRaftGroup(instance, "id", newGroupCount);
    assertTrueEventually(() -> {
        int count = 0;
        for (HazelcastInstance instance1 : instances) {
            RaftNodeImpl raftNode = getRaftNode(instance1, groupId);
            if (raftNode != null) {
                count++;
            }
        }
        assertEquals(newGroupCount, count);
    });
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint)

Example 2 with CPGroupId

use of com.hazelcast.cp.CPGroupId 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 3 with CPGroupId

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

the class MetadataRaftGroupTest method when_metadataClusterNodeFallsFarBehind_then_itInstallsSnapshot.

@Test
public void when_metadataClusterNodeFallsFarBehind_then_itInstallsSnapshot() {
    int nodeCount = 3;
    int commitCountToSnapshot = 5;
    Config config = createConfig(nodeCount, nodeCount);
    config.getCPSubsystemConfig().getRaftAlgorithmConfig().setCommitIndexAdvanceCountToSnapshot(commitCountToSnapshot);
    HazelcastInstance[] instances = new HazelcastInstance[nodeCount];
    for (int i = 0; i < nodeCount; i++) {
        instances[i] = factory.newHazelcastInstance(config);
    }
    waitUntilCPDiscoveryCompleted(instances);
    waitAllForLeaderElection(instances, getMetadataGroupId(instances[0]));
    RaftEndpoint leaderEndpoint = getLeaderMember(getRaftNode(instances[0], getMetadataGroupId(instances[0])));
    HazelcastInstance leader = getInstance(leaderEndpoint);
    HazelcastInstance follower = getRandomFollowerInstance(instances, getMetadataGroupId(instances[0]));
    dropOperationsBetween(leader, follower, RaftServiceDataSerializerHook.F_ID, singletonList(APPEND_REQUEST_OP));
    List<CPGroupId> groupIds = new ArrayList<>();
    for (int i = 0; i < commitCountToSnapshot; i++) {
        CPGroupId groupId = createNewRaftGroup(leader, "id" + i, nodeCount);
        groupIds.add(groupId);
    }
    assertTrueEventually(() -> assertTrue(getSnapshotEntry(getRaftNode(leader, getMetadataGroupId(leader))).index() > 0));
    assertTrueEventually(() -> {
        for (CPGroupId groupId : groupIds) {
            assertNotNull(getRaftNode(follower, groupId));
        }
    });
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ArrayList(java.util.ArrayList) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with CPGroupId

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

the class MetadataRaftGroupTest method when_raftGroupIsDestroyed_then_itCanBeCreatedAgain.

@Test
public void when_raftGroupIsDestroyed_then_itCanBeCreatedAgain() {
    int metadataGroupSize = 3;
    int cpNodeCount = 5;
    instances = newInstances(cpNodeCount, metadataGroupSize, 0);
    CPGroupId groupId = createNewRaftGroup(instances[0], "id", cpNodeCount);
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            assertNotNull(getRaftNode(instance, groupId));
        }
    });
    destroyRaftGroup(instances[0], groupId);
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            assertNull(getRaftNode(instance, groupId));
        }
    });
    createNewRaftGroup(instances[0], "id", cpNodeCount - 1);
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with CPGroupId

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

the class MetadataRaftGroupTest method when_raftGroupDestroyTriggered_then_raftGroupIsDestroyed.

@Test
public void when_raftGroupDestroyTriggered_then_raftGroupIsDestroyed() throws ExecutionException, InterruptedException {
    int metadataGroupSize = 3;
    int cpNodeCount = 5;
    instances = newInstances(cpNodeCount, metadataGroupSize, 0);
    CPGroupId groupId = createNewRaftGroup(instances[0], "id", cpNodeCount);
    CPGroup group = instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup("id").toCompletableFuture().get();
    assertNotNull(group);
    assertEquals(groupId, group.id());
    destroyRaftGroup(instances[0], groupId);
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            assertNull(getRaftNode(instance, groupId));
        }
    });
    assertTrueEventually(() -> {
        CPGroup g = getRaftService(instances[0]).getCPGroup(groupId).get();
        assertEquals(CPGroupStatus.DESTROYED, g.status());
    });
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

CPGroupId (com.hazelcast.cp.CPGroupId)81 Test (org.junit.Test)50 HazelcastInstance (com.hazelcast.core.HazelcastInstance)42 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)37 QuickTest (com.hazelcast.test.annotation.QuickTest)31 CPGroup (com.hazelcast.cp.CPGroup)14 CPMember (com.hazelcast.cp.CPMember)13 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)11 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)9 ArrayList (java.util.ArrayList)8 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 ExecutionException (java.util.concurrent.ExecutionException)7 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)6 SlowTest (com.hazelcast.test.annotation.SlowTest)6 IndeterminateOperationStateException (com.hazelcast.core.IndeterminateOperationStateException)5 MemberLeftException (com.hazelcast.core.MemberLeftException)5 StaleAppendRequestException (com.hazelcast.cp.exception.StaleAppendRequestException)5 DefaultRaftReplicateOp (com.hazelcast.cp.internal.operation.DefaultRaftReplicateOp)5 CallerNotMemberException (com.hazelcast.spi.exception.CallerNotMemberException)5