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]));
}
});
}
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));
}
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());
});
}
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));
}
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());
});
}
Aggregations