Search in sources :

Example 71 with CPGroupId

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

the class MetadataRaftGroupTest method when_raftGroupDestroyTriggeredMultipleTimes_then_destroyDoesNotFail.

@Test
public void when_raftGroupDestroyTriggeredMultipleTimes_then_destroyDoesNotFail() {
    int metadataGroupSize = 3;
    int cpNodeCount = 5;
    instances = newInstances(cpNodeCount, metadataGroupSize, 0);
    CPGroupId groupId = createNewRaftGroup(instances[0], "id", cpNodeCount);
    destroyRaftGroup(instances[0], groupId);
    destroyRaftGroup(instances[0], groupId);
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) 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 72 with CPGroupId

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

the class MetadataRaftGroupTest method when_raftGroupIsCreatedWithSameSizeMultipleTimes_then_itSucceeds.

@Test
public void when_raftGroupIsCreatedWithSameSizeMultipleTimes_then_itSucceeds() {
    int nodeCount = 3;
    instances = newInstances(nodeCount);
    CPGroupId groupId1 = createNewRaftGroup(instances[0], "id", nodeCount);
    CPGroupId groupId2 = createNewRaftGroup(instances[1], "id", nodeCount);
    assertEquals(groupId1, groupId2);
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) 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 73 with CPGroupId

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

the class MetadataRaftGroupTest method when_raftGroupIsCreatedWithAllCPNodes_then_raftNodeIsCreatedOnAll.

@Test
public void when_raftGroupIsCreatedWithAllCPNodes_then_raftNodeIsCreatedOnAll() {
    int nodeCount = 5;
    instances = newInstances(nodeCount);
    CPGroupId groupId = createNewRaftGroup(instances[0], "id", nodeCount);
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            assertNotNull(getRaftNode(instance, groupId));
        }
    });
}
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 74 with CPGroupId

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

the class MetadataRaftGroupTest method when_nonMetadataRaftGroupIsAlive_then_itCanBeForceDestroyed.

@Test
public void when_nonMetadataRaftGroupIsAlive_then_itCanBeForceDestroyed() throws ExecutionException, InterruptedException {
    instances = newInstances(3);
    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());
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            assertNotNull(getRaftService(instance).getRaftNode(groupId));
        }
    });
    getRaftService(instances[0]).forceDestroyCPGroup(groupId.getName()).get();
    group = getRaftService(instances[0]).getCPGroup(groupId).get();
    assertEquals(CPGroupStatus.DESTROYED, group.status());
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            assertNull(getRaftNode(instance, groupId));
        }
    });
    CPGroupId newGroupId = createNewRaftGroup(instances[0], "id", 3);
    assertNotEquals(groupId, newGroupId);
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 75 with CPGroupId

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

the class MetadataRaftGroupTest method when_raftGroupIsCreated_onNonMetadataMembers_thenLeaderShouldBeElected.

@Test
public void when_raftGroupIsCreated_onNonMetadataMembers_thenLeaderShouldBeElected() throws ExecutionException, InterruptedException {
    int metadataGroupSize = 3;
    int otherRaftGroupSize = 2;
    instances = newInstances(metadataGroupSize + otherRaftGroupSize, metadataGroupSize, 0);
    HazelcastInstance leaderInstance = getLeaderInstance(instances, getMetadataGroupId(instances[0]));
    RaftService raftService = getRaftService(leaderInstance);
    Collection<CPMemberInfo> allEndpoints = raftService.getMetadataGroupManager().getActiveMembers();
    assertTrueEventually(() -> assertNotNull(raftService.getMetadataGroupManager().getGroup(getMetadataGroupId(leaderInstance))));
    CPGroup metadataGroup = raftService.getMetadataGroupManager().getGroup(getMetadataGroupId(leaderInstance));
    Collection<CPMemberInfo> endpoints = new HashSet<>(otherRaftGroupSize);
    for (CPMemberInfo endpoint : allEndpoints) {
        if (!metadataGroup.members().contains(endpoint)) {
            endpoints.add(endpoint);
        }
    }
    assertEquals(otherRaftGroupSize, endpoints.size());
    List<RaftEndpoint> groupEndpoints = new ArrayList<>();
    for (CPMemberInfo member : endpoints) {
        groupEndpoints.add(member.toRaftEndpoint());
    }
    RaftOp op = new CreateRaftGroupOp("test", groupEndpoints, RandomPicker.getInt(Integer.MAX_VALUE));
    InternalCompletableFuture<CPGroupSummary> f = raftService.getInvocationManager().invoke(getMetadataGroupId(leaderInstance), op);
    f.whenCompleteAsync((group, t) -> {
        if (t == null) {
            raftService.getInvocationManager().triggerRaftNodeCreation(group);
        }
    });
    CPGroupId groupId = f.get().id();
    for (HazelcastInstance instance : instances) {
        if (endpoints.contains(instance.getCPSubsystem().getLocalCPMember())) {
            assertTrueEventually(() -> {
                RaftNodeImpl raftNode = getRaftNode(instance, groupId);
                assertNotNull(raftNode);
                assertNotNull("Leader is null on " + raftNode, getLeaderMember(raftNode));
            });
        }
    }
}
Also used : RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ArrayList(java.util.ArrayList) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CreateRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.CreateRaftGroupOp) HashSet(java.util.HashSet) 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