Search in sources :

Example 6 with CPGroup

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

the class CPMemberAddRemoveTest method testExpandRaftGroupMultipleTimes.

@Test
public void testExpandRaftGroupMultipleTimes() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(5, 5, 3);
    CPGroupId metadataGroupId = getMetadataGroupId(instances[0]);
    waitAllForLeaderElection(Arrays.copyOf(instances, 5), metadataGroupId);
    instances[0].shutdown();
    instances[1].shutdown();
    instances[2].shutdown();
    CPSubsystemManagementService managementService = instances[3].getCPSubsystem().getCPSubsystemManagementService();
    CPGroup group = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    assertEquals(2, group.members().size());
    instances[5].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    group = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    assertEquals(3, group.members().size());
    Collection<CPMember> members = group.members();
    assertTrue(members.contains(instances[5].getCPSubsystem().getLocalCPMember()));
    assertTrueEventually(() -> assertNotNull(getRaftNode(instances[5], metadataGroupId)));
    instances[6].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    group = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    assertEquals(4, group.members().size());
    members = group.members();
    assertTrue(members.contains(instances[6].getCPSubsystem().getLocalCPMember()));
    assertTrueEventually(() -> assertNotNull(getRaftNode(instances[5], metadataGroupId)));
    instances[7].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    group = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    assertEquals(5, group.members().size());
    members = group.members();
    assertTrue(members.contains(instances[7].getCPSubsystem().getLocalCPMember()));
    assertTrueEventually(() -> assertNotNull(getRaftNode(instances[5], metadataGroupId)));
    CPGroup metadataGroup = group;
    HazelcastInstance[] newInstances = { instances[3], instances[4], instances[5], instances[6], instances[7] };
    assertTrueEventually(() -> {
        long commitIndex = getCommitIndex(getLeaderNode(newInstances, metadataGroupId));
        for (int i = 3; i < instances.length; i++) {
            HazelcastInstance instance = instances[i];
            RaftNodeImpl raftNode = getRaftNode(instance, metadataGroupId);
            assertNotNull(raftNode);
            assertEquals(commitIndex, getCommitIndex(raftNode));
            CPGroup g = queryRaftGroupLocally(instance, metadataGroupId);
            assertNotNull(g);
            assertArrayEquals(metadataGroup.members().toArray(new CPMember[0]), g.members().toArray(new CPMember[0]));
        }
    });
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) CPSubsystemManagementService(com.hazelcast.cp.CPSubsystemManagementService) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 7 with CPGroup

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

the class CPMemberAddRemoveTest method testRemoveMemberFromForceDestroyedRaftGroup.

@Test
public void testRemoveMemberFromForceDestroyedRaftGroup() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(3, 3, 0);
    waitAllForLeaderElection(instances, getMetadataGroupId(instances[0]));
    CPGroupId groupId = getRaftInvocationManager(instances[0]).createRaftGroup("test", 2).get();
    CPGroup group = instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup(groupId.getName()).toCompletableFuture().get();
    CPMember crashedMember = group.members().iterator().next();
    HazelcastInstance runningInstance = (getAddress(instances[0])).equals(crashedMember.getAddress()) ? instances[1] : instances[0];
    factory.getInstance(crashedMember.getAddress()).getLifecycleService().terminate();
    CPSubsystemManagementService cpSubsystemManagementService = runningInstance.getCPSubsystem().getCPSubsystemManagementService();
    cpSubsystemManagementService.forceDestroyCPGroup(groupId.getName()).toCompletableFuture().get();
    cpSubsystemManagementService.removeCPMember(crashedMember.getUuid()).toCompletableFuture().get();
    Collection<CPMember> activeMembers = cpSubsystemManagementService.getCPMembers().toCompletableFuture().get();
    assertFalse(activeMembers.contains(crashedMember));
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) CPSubsystemManagementService(com.hazelcast.cp.CPSubsystemManagementService) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 8 with CPGroup

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

the class CPMemberAddRemoveTest method when_crashedMemberIsRemovedAndThenNewCPMemberIsPromoted_then_membershipChangeSucceeds.

@Test
public void when_crashedMemberIsRemovedAndThenNewCPMemberIsPromoted_then_membershipChangeSucceeds() throws ExecutionException, InterruptedException {
    int cpMemberCount = 3;
    HazelcastInstance[] instances = newInstances(cpMemberCount);
    waitUntilCPDiscoveryCompleted(instances);
    CPMember cpMember3 = instances[2].getCPSubsystem().getLocalCPMember();
    instances[2].getLifecycleService().terminate();
    instances[0].getCPSubsystem().getCPSubsystemManagementService().removeCPMember(cpMember3.getUuid());
    assertTrueEventually(() -> {
        CPGroup metadataGroup = instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup(CPGroup.METADATA_CP_GROUP_NAME).toCompletableFuture().get();
        assertEquals(cpMemberCount - 1, metadataGroup.members().size());
        assertFalse(metadataGroup.members().contains(cpMember3));
    });
    HazelcastInstance instance4 = factory.newHazelcastInstance(createConfig(cpMemberCount, cpMemberCount));
    instance4.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    assertTrueEventually(() -> {
        CPGroup metadataGroup = instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup(CPGroup.METADATA_CP_GROUP_NAME).toCompletableFuture().get();
        assertTrue(metadataGroup.members().contains(instance4.getCPSubsystem().getLocalCPMember()));
        assertEquals(cpMemberCount, metadataGroup.members().size());
    });
}
Also used : CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 9 with CPGroup

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

the class CPMemberAddRemoveTest method testRemoveRaftMember.

@Test
public void testRemoveRaftMember() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(3);
    getRaftInvocationManager(instances[0]).createRaftGroup("test", 3).get();
    Member member = instances[0].getCluster().getLocalMember();
    instances[0].getLifecycleService().terminate();
    assertClusterSizeEventually(2, instances[1]);
    CPMemberInfo removedEndpoint = new CPMemberInfo(member);
    instances[1].getCPSubsystem().getCPSubsystemManagementService().removeCPMember(removedEndpoint.getUuid()).toCompletableFuture().get();
    CPGroup metadataGroup = instances[1].getCPSubsystem().getCPSubsystemManagementService().getCPGroup(METADATA_CP_GROUP_NAME).toCompletableFuture().get();
    assertEquals(2, metadataGroup.members().size());
    assertFalse(metadataGroup.members().contains(removedEndpoint));
    CPGroup testGroup = instances[1].getCPSubsystem().getCPSubsystemManagementService().getCPGroup("test").toCompletableFuture().get();
    assertNotNull(testGroup);
    assertEquals(2, testGroup.members().size());
    assertFalse(testGroup.members().contains(removedEndpoint));
}
Also used : CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) Member(com.hazelcast.cluster.Member) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 10 with CPGroup

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

the class CPMemberAddRemoveTest method when_crashedMemberIsReplacedByAnotherAvailableCPMember_then_membershipChangeSucceeds.

@Test
public void when_crashedMemberIsReplacedByAnotherAvailableCPMember_then_membershipChangeSucceeds() throws InterruptedException, ExecutionException {
    int cpMemberCount = 3;
    HazelcastInstance[] instances = newInstances(cpMemberCount);
    waitUntilCPDiscoveryCompleted(instances);
    HazelcastInstance instance4 = factory.newHazelcastInstance(createConfig(cpMemberCount, cpMemberCount));
    instance4.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    CPMember cpMember3 = instances[2].getCPSubsystem().getLocalCPMember();
    instances[2].getLifecycleService().terminate();
    instances[0].getCPSubsystem().getCPSubsystemManagementService().removeCPMember(cpMember3.getUuid());
    assertTrueEventually(() -> {
        CPGroup metadataGroup = instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup(CPGroup.METADATA_CP_GROUP_NAME).toCompletableFuture().get();
        assertTrue(metadataGroup.members().contains(instance4.getCPSubsystem().getLocalCPMember()));
        assertEquals(cpMemberCount, metadataGroup.members().size());
    });
}
Also used : CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

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