use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class CPGroupRebalanceTest method getLeadershipsMap.
private Map<CPMember, Collection<CPGroupId>> getLeadershipsMap(HazelcastInstance instance, Collection<CPMember> members) {
OperationServiceImpl operationService = getOperationService(instance);
Map<CPMember, Collection<CPGroupId>> leaderships = new HashMap<>();
for (CPMember member : members) {
Collection<CPGroupId> groups = operationService.<Collection<CPGroupId>>invokeOnTarget(null, new GetLeadedGroupsOp(), member.getAddress()).join();
leaderships.put(member, groups);
}
return leaderships;
}
use of com.hazelcast.cp.CPGroupId 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.CPGroupId 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.CPGroupId in project hazelcast by hazelcast.
the class AbstractCountDownLatchAdvancedTest method testSuccessfulAwaitClearsWaitTimeouts.
@Test
public void testSuccessfulAwaitClearsWaitTimeouts() {
latch.trySetCount(1);
CPGroupId groupId = getGroupId(latch);
HazelcastInstance leader = leaderInstanceOf(groupId);
CountDownLatchService service = getNodeEngineImpl(leader).getService(CountDownLatchService.SERVICE_NAME);
CountDownLatchRegistry registry = service.getRegistryOrNull(groupId);
CountDownLatch threadLatch = new CountDownLatch(1);
spawn(() -> {
try {
latch.await(10, MINUTES);
threadLatch.countDown();
} catch (InterruptedException e) {
e.printStackTrace();
}
});
assertTrueEventually(() -> {
assertFalse(registry.getWaitTimeouts().isEmpty());
assertFalse(registry.getLiveOperations().isEmpty());
});
latch.countDown();
assertOpenEventually(threadLatch);
assertTrue(registry.getWaitTimeouts().isEmpty());
assertTrue(registry.getLiveOperations().isEmpty());
}
use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class AbstractCountDownLatchAdvancedTest method testFailedAwaitClearsWaitTimeouts.
@Test
public void testFailedAwaitClearsWaitTimeouts() throws InterruptedException {
latch.trySetCount(1);
CPGroupId groupId = getGroupId(latch);
HazelcastInstance leader = leaderInstanceOf(groupId);
CountDownLatchService service = getNodeEngineImpl(leader).getService(CountDownLatchService.SERVICE_NAME);
CountDownLatchRegistry registry = service.getRegistryOrNull(groupId);
boolean success = latch.await(1, TimeUnit.SECONDS);
assertFalse(success);
assertTrue(registry.getWaitTimeouts().isEmpty());
assertTrue(registry.getLiveOperations().isEmpty());
}
Aggregations