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