use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class MetadataRaftGroupTest method when_memberIsShutdown_then_itIsRemovedFromRaftGroups.
@Test
public void when_memberIsShutdown_then_itIsRemovedFromRaftGroups() throws ExecutionException, InterruptedException {
int cpNodeCount = 7;
int metadataGroupSize = 5;
int atomicLong1GroupSize = 3;
instances = newInstances(cpNodeCount, metadataGroupSize, 0);
CPGroupId groupId1 = createNewRaftGroup(instances[0], "id1", atomicLong1GroupSize);
CPGroupId groupId2 = createNewRaftGroup(instances[0], "id2", cpNodeCount);
CPMember endpoint = findCommonEndpoint(instances[0], getMetadataGroupId(instances[0]), groupId1);
assertNotNull(endpoint);
RaftInvocationManager invocationService = null;
HazelcastInstance aliveInstance = null;
for (HazelcastInstance instance : instances) {
if (!getAddress(instance).equals(endpoint.getAddress())) {
aliveInstance = instance;
invocationService = getRaftInvocationManager(instance);
break;
}
}
assertNotNull(invocationService);
factory.getInstance(endpoint.getAddress()).shutdown();
CPGroupId metadataGroupId = getMetadataGroupId(aliveInstance);
InternalCompletableFuture<List<CPMember>> f1 = invocationService.query(metadataGroupId, new GetActiveCPMembersOp(), LINEARIZABLE);
List<CPMember> activeEndpoints = f1.get();
assertThat(activeEndpoints, not(hasItem(endpoint)));
InternalCompletableFuture<CPGroup> f2 = invocationService.query(metadataGroupId, new GetRaftGroupOp(metadataGroupId), LINEARIZABLE);
InternalCompletableFuture<CPGroup> f3 = invocationService.query(metadataGroupId, new GetRaftGroupOp(groupId1), LINEARIZABLE);
InternalCompletableFuture<CPGroup> f4 = invocationService.query(metadataGroupId, new GetRaftGroupOp(groupId2), LINEARIZABLE);
CPGroup metadataGroup = f2.get();
assertFalse(metadataGroup.members().contains(endpoint));
assertEquals(metadataGroupSize, metadataGroup.members().size());
CPGroup atomicLongGroup1 = f3.get();
assertFalse(atomicLongGroup1.members().contains(endpoint));
assertEquals(atomicLong1GroupSize, atomicLongGroup1.members().size());
CPGroup atomicLongGroup2 = f4.get();
assertFalse(atomicLongGroup2.members().contains(endpoint));
assertEquals(cpNodeCount - 1, atomicLongGroup2.members().size());
}
use of com.hazelcast.cp.CPGroupId 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.CPGroupId in project hazelcast by hazelcast.
the class RaftInvocationManagerQueryTest method when_queryLocalFromFollower_onStableCluster_thenReadLatestValueEventually.
@Test
public void when_queryLocalFromFollower_onStableCluster_thenReadLatestValueEventually() throws Exception {
int nodeCount = 3;
instances = newInstances(nodeCount);
RaftInvocationManager invocationService = getRaftInvocationManager(instances[0]);
CPGroupId groupId = invocationService.createRaftGroup("test", nodeCount).get();
String value = "value";
invocationService.invoke(groupId, new RaftTestApplyOp(value)).get();
HazelcastInstance follower = getRandomFollowerInstance(instances, groupId);
assertTrueEventually(() -> {
Future<Object> future = getRaftInvocationManager(follower).query(groupId, new RaftTestQueryOp(), ANY_LOCAL);
assertEquals(value, future.get());
});
}
use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class RaftInvocationManagerQueryTest method when_queryLocalFromFollower_withLeaderLocalPolicy_thenFail.
@Test
public void when_queryLocalFromFollower_withLeaderLocalPolicy_thenFail() throws Exception {
int nodeCount = 3;
instances = newInstances(nodeCount);
RaftInvocationManager invocationService = getRaftInvocationManager(instances[0]);
CPGroupId groupId = invocationService.createRaftGroup("test", nodeCount).get();
String value = "value";
invocationService.invoke(groupId, new RaftTestApplyOp(value)).get();
HazelcastInstance follower = getRandomFollowerInstance(instances, groupId);
Future<Object> future = getRaftInvocationManager(follower).queryLocally(groupId, new RaftTestQueryOp(), LEADER_LOCAL);
try {
future.get();
} catch (ExecutionException e) {
assertInstanceOf(NotLeaderException.class, e.getCause());
}
}
use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class RaftInvocationManagerQueryTest method when_queryLocalFromLeader_onStableCluster_thenReadLatestValue.
@Test
public void when_queryLocalFromLeader_onStableCluster_thenReadLatestValue() throws Exception {
int nodeCount = 3;
instances = newInstances(nodeCount);
RaftInvocationManager invocationService = getRaftInvocationManager(instances[0]);
CPGroupId groupId = invocationService.createRaftGroup("test", nodeCount).get();
String value = "value";
invocationService.invoke(groupId, new RaftTestApplyOp(value)).get();
Future<Object> future = invocationService.query(groupId, new RaftTestQueryOp(), LEADER_LOCAL);
assertEquals(value, future.get());
}
Aggregations