use of com.hazelcast.cp.CPSubsystemManagementService 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.CPSubsystemManagementService 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.CPSubsystemManagementService in project hazelcast by hazelcast.
the class GetCPMembersMessageTask method processInternal.
@Override
protected CompletableFuture<List<SimpleEntry<UUID, UUID>>> processInternal() {
CPSubsystemManagementService cpService = nodeEngine.getHazelcastInstance().getCPSubsystem().getCPSubsystemManagementService();
ClusterService clusterService = nodeEngine.getClusterService();
return cpService.getCPMembers().toCompletableFuture().thenApply(cpMembers -> {
List<SimpleEntry<UUID, UUID>> result = new ArrayList<>(cpMembers.size());
for (CPMember cpMember : cpMembers) {
UUID apUuid = clusterService.getMember(cpMember.getAddress()).getUuid();
result.add(new SimpleEntry<>(cpMember.getUuid(), apUuid));
}
return result;
});
}
use of com.hazelcast.cp.CPSubsystemManagementService in project hazelcast by hazelcast.
the class CPMemberAddRemoveTest method testExpandMultipleRaftGroupsMultipleTimes.
@Test
public void testExpandMultipleRaftGroupsMultipleTimes() throws ExecutionException, InterruptedException, TimeoutException {
HazelcastInstance[] instances = newInstances(5, 5, 2);
CPGroupId metadataGroupId = getMetadataGroupId(instances[0]);
CPSubsystemManagementService managementService = instances[6].getCPSubsystem().getCPSubsystemManagementService();
String groupName = "group1";
instances[0].getCPSubsystem().getAtomicLong("long1@" + groupName).set(5);
CPGroup otherGroup = managementService.getCPGroup(groupName).toCompletableFuture().get();
CPGroupId groupId = otherGroup.id();
waitAllForLeaderElection(Arrays.copyOf(instances, 5), groupId);
CPMember[] otherGroupMembers = otherGroup.members().toArray(new CPMember[0]);
List<Address> shutdownAddresses = asList(otherGroupMembers[0].getAddress(), otherGroupMembers[1].getAddress());
instances[5].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get(30, TimeUnit.SECONDS);
HazelcastInstance[] runningInstances = new HazelcastInstance[instances.length - shutdownAddresses.size()];
for (int i = 0, j = 0; i < instances.length; i++) {
HazelcastInstance instance = instances[i];
if (shutdownAddresses.contains(getAddress(instance))) {
instance.shutdown();
} else {
runningInstances[j++] = instance;
}
}
CPGroup metadataGroup = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
otherGroup = managementService.getCPGroup(groupName).toCompletableFuture().get();
assertEquals(4, metadataGroup.members().size());
assertEquals(4, otherGroup.members().size());
assertTrueEventually(() -> {
assertNotNull(getRaftNode(instances[5], metadataGroupId));
assertNotNull(getRaftNode(instances[5], groupId));
});
instances[6].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get(30, TimeUnit.SECONDS);
metadataGroup = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
otherGroup = managementService.getCPGroup(groupName).toCompletableFuture().get();
assertEquals(5, metadataGroup.members().size());
assertEquals(5, otherGroup.members().size());
CPGroup metadataGroupRef = metadataGroup;
CPGroup otherGroupRef = otherGroup;
assertTrueEventually(() -> {
long commitIndex = getCommitIndex(getLeaderNode(runningInstances, metadataGroupId));
assertNotNull(getRaftNode(instances[6], groupId));
for (HazelcastInstance instance : asList(instances[5], instances[6])) {
RaftNodeImpl raftNode = getRaftNode(instance, metadataGroupId);
assertNotNull(raftNode);
assertEquals(commitIndex, getCommitIndex(raftNode));
CPGroup g1 = queryRaftGroupLocally(instance, metadataGroupId);
CPGroup g2 = queryRaftGroupLocally(instance, otherGroupRef.id());
assertNotNull(g1);
assertNotNull(g2);
assertArrayEquals(metadataGroupRef.members().toArray(new CPMember[0]), g1.members().toArray(new CPMember[0]));
assertArrayEquals(otherGroupRef.members().toArray(new CPMember[0]), g2.members().toArray(new CPMember[0]));
}
});
}
Aggregations