use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class MetadataRaftGroupTest method when_raftGroupIsCreatedWithSomeCPNodes_then_raftNodeIsCreatedOnOnlyTheSelectedEndpoints.
private void when_raftGroupIsCreatedWithSomeCPNodes_then_raftNodeIsCreatedOnOnlyTheSelectedEndpoints(boolean invokeOnCP) {
int cpNodeCount = 6;
int metadataGroupSize = 3;
int nonCpNodeCount = 2;
instances = newInstances(cpNodeCount, metadataGroupSize, nonCpNodeCount);
int newGroupCount = metadataGroupSize + 1;
HazelcastInstance instance = instances[invokeOnCP ? 0 : instances.length - 1];
CPGroupId groupId = createNewRaftGroup(instance, "id", newGroupCount);
assertTrueEventually(() -> {
int count = 0;
for (HazelcastInstance instance1 : instances) {
RaftNodeImpl raftNode = getRaftNode(instance1, groupId);
if (raftNode != null) {
count++;
}
}
assertEquals(newGroupCount, count);
});
}
use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class MetadataRaftGroupTest method when_nonMetadataRaftGroupLosesMajority_then_itCanBeForceDestroyed.
@Test
public void when_nonMetadataRaftGroupLosesMajority_then_itCanBeForceDestroyed() throws ExecutionException, InterruptedException {
instances = newInstances(5);
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());
CPMember[] groupMembers = group.members().toArray(new CPMember[0]);
assertTrueEventually(() -> {
for (CPMember member : groupMembers) {
HazelcastInstance instance = factory.getInstance(member.getAddress());
assertNotNull(getRaftNode(instance, groupId));
}
});
factory.getInstance(groupMembers[0].getAddress()).getLifecycleService().terminate();
factory.getInstance(groupMembers[1].getAddress()).getLifecycleService().terminate();
HazelcastInstance runningInstance = factory.getInstance(groupMembers[2].getAddress());
getRaftService(runningInstance).forceDestroyCPGroup(groupId.getName()).get();
group = getRaftService(runningInstance).getCPGroup(groupId).get();
assertEquals(CPGroupStatus.DESTROYED, group.status());
assertTrueEventually(() -> assertNull(getRaftNode(runningInstance, groupId)));
}
use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class MetadataRaftGroupTest method when_metadataClusterNodeFallsFarBehind_then_itInstallsSnapshot.
@Test
public void when_metadataClusterNodeFallsFarBehind_then_itInstallsSnapshot() {
int nodeCount = 3;
int commitCountToSnapshot = 5;
Config config = createConfig(nodeCount, nodeCount);
config.getCPSubsystemConfig().getRaftAlgorithmConfig().setCommitIndexAdvanceCountToSnapshot(commitCountToSnapshot);
HazelcastInstance[] instances = new HazelcastInstance[nodeCount];
for (int i = 0; i < nodeCount; i++) {
instances[i] = factory.newHazelcastInstance(config);
}
waitUntilCPDiscoveryCompleted(instances);
waitAllForLeaderElection(instances, getMetadataGroupId(instances[0]));
RaftEndpoint leaderEndpoint = getLeaderMember(getRaftNode(instances[0], getMetadataGroupId(instances[0])));
HazelcastInstance leader = getInstance(leaderEndpoint);
HazelcastInstance follower = getRandomFollowerInstance(instances, getMetadataGroupId(instances[0]));
dropOperationsBetween(leader, follower, RaftServiceDataSerializerHook.F_ID, singletonList(APPEND_REQUEST_OP));
List<CPGroupId> groupIds = new ArrayList<>();
for (int i = 0; i < commitCountToSnapshot; i++) {
CPGroupId groupId = createNewRaftGroup(leader, "id" + i, nodeCount);
groupIds.add(groupId);
}
assertTrueEventually(() -> assertTrue(getSnapshotEntry(getRaftNode(leader, getMetadataGroupId(leader))).index() > 0));
assertTrueEventually(() -> {
for (CPGroupId groupId : groupIds) {
assertNotNull(getRaftNode(follower, groupId));
}
});
}
use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class MetadataRaftGroupTest method when_raftGroupIsDestroyed_then_itCanBeCreatedAgain.
@Test
public void when_raftGroupIsDestroyed_then_itCanBeCreatedAgain() {
int metadataGroupSize = 3;
int cpNodeCount = 5;
instances = newInstances(cpNodeCount, metadataGroupSize, 0);
CPGroupId groupId = createNewRaftGroup(instances[0], "id", cpNodeCount);
assertTrueEventually(() -> {
for (HazelcastInstance instance : instances) {
assertNotNull(getRaftNode(instance, groupId));
}
});
destroyRaftGroup(instances[0], groupId);
assertTrueEventually(() -> {
for (HazelcastInstance instance : instances) {
assertNull(getRaftNode(instance, groupId));
}
});
createNewRaftGroup(instances[0], "id", cpNodeCount - 1);
}
use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class MetadataRaftGroupTest method when_raftGroupDestroyTriggered_then_raftGroupIsDestroyed.
@Test
public void when_raftGroupDestroyTriggered_then_raftGroupIsDestroyed() throws ExecutionException, InterruptedException {
int metadataGroupSize = 3;
int cpNodeCount = 5;
instances = newInstances(cpNodeCount, metadataGroupSize, 0);
CPGroupId groupId = createNewRaftGroup(instances[0], "id", cpNodeCount);
CPGroup group = instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup("id").toCompletableFuture().get();
assertNotNull(group);
assertEquals(groupId, group.id());
destroyRaftGroup(instances[0], groupId);
assertTrueEventually(() -> {
for (HazelcastInstance instance : instances) {
assertNull(getRaftNode(instance, groupId));
}
});
assertTrueEventually(() -> {
CPGroup g = getRaftService(instances[0]).getCPGroup(groupId).get();
assertEquals(CPGroupStatus.DESTROYED, g.status());
});
}
Aggregations