use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.
the class MetadataRaftGroupTest method when_nonReachableEndpointsExist_createRaftGroupPrefersReachableEndpoints.
@Test
public void when_nonReachableEndpointsExist_createRaftGroupPrefersReachableEndpoints() throws ExecutionException, InterruptedException {
HazelcastInstance[] instances = newInstances(5);
assertTrueEventually(() -> {
for (HazelcastInstance instance : instances) {
Collection<CPMemberInfo> raftMembers = getRaftService(instance).getMetadataGroupManager().getActiveMembers();
assertFalse(raftMembers.isEmpty());
}
});
CPMember endpoint3 = instances[3].getCPSubsystem().getLocalCPMember();
CPMember endpoint4 = instances[4].getCPSubsystem().getLocalCPMember();
instances[3].getLifecycleService().terminate();
instances[4].getLifecycleService().terminate();
RaftInvocationManager invocationManager = getRaftInvocationManager(instances[0]);
CPGroupId groupId3 = invocationManager.createRaftGroup("groupId3", 3).get();
CPGroupId groupId4 = invocationManager.createRaftGroup("g4", 4).get();
RaftNodeImpl leaderNode = waitAllForLeaderElection(Arrays.copyOf(instances, 3), getMetadataGroupId(instances[0]));
HazelcastInstance leader = getInstance(leaderNode.getLocalMember());
CPGroup group3 = queryRaftGroupLocally(leader, groupId3);
assertNotNull(group3);
assertThat(group3.members(), not(hasItem(endpoint3)));
assertThat(group3.members(), not(hasItem(endpoint4)));
CPGroup group4 = queryRaftGroupLocally(leader, groupId4);
assertNotNull(group4);
boolean b3 = group4.members().contains(endpoint3);
boolean b4 = group4.members().contains(endpoint4);
assertTrue(b3 ^ b4);
}
use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.
the class MetadataRaftGroupTest method when_shutdownLeader_thenNewLeaderElected.
@Test
public void when_shutdownLeader_thenNewLeaderElected() {
int cpNodeCount = 6;
int metadataGroupSize = 5;
instances = newInstances(cpNodeCount, metadataGroupSize, 0);
HazelcastInstance leaderInstance = getLeaderInstance(instances, getMetadataGroupId(instances[0]));
leaderInstance.shutdown();
assertTrueEventually(() -> {
for (HazelcastInstance instance : instances) {
if (instance == leaderInstance) {
continue;
}
RaftNodeImpl raftNode = getRaftNode(instance, getMetadataGroupId(instance));
assertNotNull(raftNode);
assertNotNull("Leader is null on " + raftNode, getLeaderMember(raftNode));
}
});
}
use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl 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.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.
the class CPMemberAddRemoveTest method when_newCPMemberIsAddedToTheMetadataGroupAfterSnapshot_newMemberInstallsSnapshot.
@Test
public void when_newCPMemberIsAddedToTheMetadataGroupAfterSnapshot_newMemberInstallsSnapshot() throws ExecutionException, InterruptedException {
int nodeCount = 3;
int commitIndexAdvanceCountToSnapshot = 50;
Config config = createConfig(nodeCount, nodeCount);
config.getCPSubsystemConfig().getRaftAlgorithmConfig().setCommitIndexAdvanceCountToSnapshot(commitIndexAdvanceCountToSnapshot);
HazelcastInstance[] instances = new HazelcastInstance[nodeCount];
for (int i = 0; i < nodeCount; i++) {
instances[i] = factory.newHazelcastInstance(config);
}
assertClusterSizeEventually(nodeCount, instances);
waitUntilCPDiscoveryCompleted(instances);
instances[0].getCPSubsystem().getAtomicLong("long@group1").set(1);
instances[0].getCPSubsystem().getAtomicLong("long@group2").set(2);
for (int i = 0; i < commitIndexAdvanceCountToSnapshot; i++) {
getRaftInvocationManager(instances[0]).invoke(getMetadataGroupId(instances[0]), new GetActiveCPMembersOp()).get();
}
assertTrueEventually(() -> assertTrue(getSnapshotEntry(getLeaderNode(instances, getMetadataGroupId(instances[0]))).index() >= commitIndexAdvanceCountToSnapshot));
for (int i = 0; i < 5; i++) {
instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup(METADATA_CP_GROUP_NAME).toCompletableFuture().get();
}
instances[0].shutdown();
HazelcastInstance newInstance = factory.newHazelcastInstance(config);
newInstance.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
CPGroup metadataGroup = newInstance.getCPSubsystem().getCPSubsystemManagementService().getCPGroup(METADATA_CP_GROUP_NAME).toCompletableFuture().get();
CPGroup group1 = newInstance.getCPSubsystem().getCPSubsystemManagementService().getCPGroup("group1").toCompletableFuture().get();
CPGroup group2 = newInstance.getCPSubsystem().getCPSubsystemManagementService().getCPGroup("group2").toCompletableFuture().get();
List<CPMember> cpMembers = new ArrayList<>(newInstance.getCPSubsystem().getCPSubsystemManagementService().getCPMembers().toCompletableFuture().get());
assertTrueEventually(() -> {
long commitIndex = getCommitIndex(getLeaderNode(new HazelcastInstance[] { instances[1], instances[2], newInstance }, metadataGroup.id()));
RaftNodeImpl raftNode = getRaftNode(newInstance, metadataGroup.id());
assertNotNull(raftNode);
assertEquals(commitIndex, getCommitIndex(raftNode));
CPGroup m = queryRaftGroupLocally(newInstance, metadataGroup.id());
CPGroup g1 = queryRaftGroupLocally(newInstance, group1.id());
CPGroup g2 = queryRaftGroupLocally(newInstance, group2.id());
assertNotNull(m);
assertNotNull(g1);
assertNotNull(g2);
assertArrayEquals(metadataGroup.members().toArray(new CPMember[0]), m.members().toArray(new CPMember[0]));
assertArrayEquals(group1.members().toArray(new CPMember[0]), g1.members().toArray(new CPMember[0]));
assertArrayEquals(group2.members().toArray(new CPMember[0]), g2.members().toArray(new CPMember[0]));
List<CPMemberInfo> activeMembers = new ArrayList<>(getRaftService(newInstance).getMetadataGroupManager().getActiveMembers());
assertEquals(cpMembers, activeMembers);
});
}
use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl 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]));
}
});
}
Aggregations