Search in sources :

Example 51 with CPMember

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();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) CPMember(com.hazelcast.cp.CPMember)

Example 52 with CPMember

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) ExecutionException(java.util.concurrent.ExecutionException) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 53 with CPMember

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();
}
Also used : CPGroup(com.hazelcast.cp.CPGroup) CPMember(com.hazelcast.cp.CPMember) HashSet(java.util.HashSet)

Example 54 with CPMember

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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ConnectionResponse(com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse) CPMember(com.hazelcast.cp.CPMember) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 55 with CPMember

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);
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) HazelcastInstance(com.hazelcast.core.HazelcastInstance) JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) ConnectionResponse(com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse) CPMember(com.hazelcast.cp.CPMember) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

CPMember (com.hazelcast.cp.CPMember)57 HazelcastInstance (com.hazelcast.core.HazelcastInstance)40 Test (org.junit.Test)38 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)27 SlowTest (com.hazelcast.test.annotation.SlowTest)27 CPGroup (com.hazelcast.cp.CPGroup)17 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)16 CPGroupId (com.hazelcast.cp.CPGroupId)14 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 ArrayList (java.util.ArrayList)11 Config (com.hazelcast.config.Config)10 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)10 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)7 GetActiveCPMembersOp (com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp)6 JsonArray (com.hazelcast.internal.json.JsonArray)6 JsonObject (com.hazelcast.internal.json.JsonObject)6 TestHazelcastInstanceFactory.initOrCreateConfig (com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig)6 CPSubsystemManagementService (com.hazelcast.cp.CPSubsystemManagementService)4 JsonValue (com.hazelcast.internal.json.JsonValue)4