use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.
the class HazelcastRaftTestSupport method getRandomFollowerInstance.
protected static HazelcastInstance getRandomFollowerInstance(HazelcastInstance[] instances, CPGroupId groupId) {
RaftNodeImpl[] raftNodeRef = new RaftNodeImpl[1];
assertTrueEventually(() -> {
for (HazelcastInstance instance : instances) {
RaftNodeImpl raftNode = getRaftNode(instance, groupId);
if (raftNode != null) {
raftNodeRef[0] = raftNode;
return;
}
}
fail();
});
RaftNodeImpl raftNode = raftNodeRef[0];
waitUntilLeaderElected(raftNode);
RaftEndpoint leaderEndpoint = getLeaderMember(raftNode);
assertNotNull(leaderEndpoint);
for (HazelcastInstance instance : instances) {
CPMember cpMember = instance.getCPSubsystem().getLocalCPMember();
if (cpMember != null && !cpMember.getUuid().equals(leaderEndpoint.getUuid())) {
return instance;
}
}
throw new AssertionError();
}
use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.
the class CPLiteMemberTest method liteMembers_shouldNotBePromotedToCPMember.
@Test
public void liteMembers_shouldNotBePromotedToCPMember() throws Exception {
Config config = createConfig(3, 3);
HazelcastInstance hz1 = factory.newHazelcastInstance(config);
HazelcastInstance hz2 = factory.newHazelcastInstance(config);
HazelcastInstance hz3 = factory.newHazelcastInstance(config);
HazelcastInstance hz_lite = factory.newHazelcastInstance(createConfig(3, 3).setLiteMember(true));
assertTrue(awaitUntilDiscoveryCompleted(hz1, 60));
assertTrue(awaitUntilDiscoveryCompleted(hz_lite, 60));
try {
hz_lite.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
fail("CP member promotion should have failed!");
} catch (ExecutionException e) {
assertInstanceOf(IllegalStateException.class, e.getCause());
}
Collection<CPMember> cpMembers = hz1.getCPSubsystem().getCPSubsystemManagementService().getCPMembers().toCompletableFuture().get();
assertEquals(3, cpMembers.size());
assertNotCpMember(hz_lite, cpMembers);
}
use of com.hazelcast.cp.CPMember 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.CPMember in project hazelcast by hazelcast.
the class RestCPSubsystemTest method test_promoteAPMemberToCPMember_withInvalidCredentials.
@Test
public void test_promoteAPMemberToCPMember_withInvalidCredentials() throws IOException, ExecutionException, InterruptedException {
HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
Hazelcast.newHazelcastInstance(config);
Hazelcast.newHazelcastInstance(config);
HazelcastInstance instance4 = Hazelcast.newHazelcastInstance(config);
ConnectionResponse response = new HTTPCommunicator(instance4).promoteCPMember("x", "x");
assertEquals(403, response.responseCode);
Collection<CPMember> cpMembers = instance1.getCPSubsystem().getCPSubsystemManagementService().getCPMembers().toCompletableFuture().get();
assertEquals(3, cpMembers.size());
}
use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.
the class RestCPSubsystemTest method test_getCPMembers.
@Test
public void test_getCPMembers() throws IOException {
final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);
final HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(config);
waitUntilCPDiscoveryCompleted(instance1, instance2, instance3);
ConnectionResponse response = new HTTPCommunicator(instance1).getCPMembers();
CPMember cpMember1 = instance1.getCPSubsystem().getLocalCPMember();
CPMember cpMember2 = instance2.getCPSubsystem().getLocalCPMember();
CPMember cpMember3 = instance3.getCPSubsystem().getLocalCPMember();
boolean cpMember1Found = false;
boolean cpMember2Found = false;
boolean cpMember3Found = false;
JsonArray arr = (JsonArray) Json.parse(response.response);
for (JsonValue val : arr) {
JsonObject mem = (JsonObject) val;
cpMember1Found |= cpMember1.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
cpMember2Found |= cpMember2.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
cpMember3Found |= cpMember3.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
}
assertTrue(cpMember1Found);
assertTrue(cpMember2Found);
assertTrue(cpMember3Found);
}
Aggregations