Search in sources :

Example 21 with CPGroup

use of com.hazelcast.cp.CPGroup 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 22 with CPGroup

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

the class MetadataRaftGroupTest method findCommonEndpoint.

private CPMember findCommonEndpoint(HazelcastInstance instance, CPGroupId groupId1, CPGroupId groupId2) throws ExecutionException, InterruptedException {
    CPGroup group1 = instance.getCPSubsystem().getCPSubsystemManagementService().getCPGroup(groupId1.getName()).toCompletableFuture().get();
    CPGroup group2 = instance.getCPSubsystem().getCPSubsystemManagementService().getCPGroup(groupId2.getName()).toCompletableFuture().get();
    Set<CPMember> members = new HashSet<>(group1.members());
    members.retainAll(group2.members());
    return members.isEmpty() ? null : members.iterator().next();
}
Also used : CPGroup(com.hazelcast.cp.CPGroup) CPMember(com.hazelcast.cp.CPMember) HashSet(java.util.HashSet)

Example 23 with CPGroup

use of com.hazelcast.cp.CPGroup 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

CPGroup (com.hazelcast.cp.CPGroup)23 Test (org.junit.Test)21 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)20 HazelcastInstance (com.hazelcast.core.HazelcastInstance)19 CPMember (com.hazelcast.cp.CPMember)17 CPGroupId (com.hazelcast.cp.CPGroupId)14 SlowTest (com.hazelcast.test.annotation.SlowTest)13 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)12 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)8 QuickTest (com.hazelcast.test.annotation.QuickTest)8 ArrayList (java.util.ArrayList)5 GetRaftGroupOp (com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp)4 Config (com.hazelcast.config.Config)3 CPSubsystemManagementService (com.hazelcast.cp.CPSubsystemManagementService)3 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)3 GetActiveCPMembersOp (com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp)3 TestHazelcastInstanceFactory.initOrCreateConfig (com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig)3 CPGroupDestroyedException (com.hazelcast.cp.exception.CPGroupDestroyedException)2 RaftInvocationManager (com.hazelcast.cp.internal.RaftInvocationManager)2 GetMembershipChangeScheduleOp (com.hazelcast.cp.internal.raftop.metadata.GetMembershipChangeScheduleOp)2