Search in sources :

Example 31 with ConnectionResponse

use of com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse in project hazelcast by hazelcast.

the class RestCPSubsystemTest method test_getCPGroupByInvalidName.

@Test
public void test_getCPGroupByInvalidName() throws IOException {
    HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    HTTPCommunicator communicator = new HTTPCommunicator(instance1);
    ConnectionResponse response = communicator.getCPGroupByName("custom");
    assertEquals(404, response.responseCode);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ConnectionResponse(com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 32 with ConnectionResponse

use of com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse in project hazelcast by hazelcast.

the class RestCPSubsystemTest method test_forceCloseCPSessionOfInvalidCPGroup.

@Test
public void test_forceCloseCPSessionOfInvalidCPGroup() throws IOException {
    HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    ConnectionResponse response1 = new HTTPCommunicator(instance1).forceCloseCPSession(DEFAULT_GROUP_NAME, 1, clusterName, null);
    assertEquals(400, response1.responseCode);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ConnectionResponse(com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 33 with ConnectionResponse

use of com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse 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)

Example 34 with ConnectionResponse

use of com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse in project hazelcast by hazelcast.

the class RestCPSubsystemTest method test_promoteAPMemberToCPMember.

@Test
public void test_promoteAPMemberToCPMember() throws ExecutionException, InterruptedException {
    final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance instance4 = Hazelcast.newHazelcastInstance(config);
    waitUntilCPDiscoveryCompleted(instance1, instance2, instance3, instance4);
    assertTrueEventually(() -> {
        ConnectionResponse response = new HTTPCommunicator(instance4).promoteCPMember(clusterName, null);
        assertEquals(200, response.responseCode);
    });
    Collection<CPMember> cpMembers = instance1.getCPSubsystem().getCPSubsystemManagementService().getCPMembers().toCompletableFuture().get();
    assertEquals(4, cpMembers.size());
    assertNotNull(instance4.getCPSubsystem().getLocalCPMember());
}
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 35 with ConnectionResponse

use of com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse in project hazelcast by hazelcast.

the class RestCPSubsystemTest method test_getCPSessions.

@Test
public void test_getCPSessions() throws IOException {
    HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);
    HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(config);
    instance1.getCPSubsystem().getLock("lock1").lock();
    instance1.getCPSubsystem().getLock("lock1").unlock();
    instance2.getCPSubsystem().getLock("lock1").lock();
    instance2.getCPSubsystem().getLock("lock1").unlock();
    instance3.getCPSubsystem().getLock("lock1").lock();
    instance3.getCPSubsystem().getLock("lock1").unlock();
    ConnectionResponse response = new HTTPCommunicator(instance1).getCPSessions(DEFAULT_GROUP_NAME);
    assertEquals(200, response.responseCode);
    JsonArray sessions = (JsonArray) Json.parse(response.response);
    assertEquals(3, sessions.size());
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ConnectionResponse(com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)39 Test (org.junit.Test)39 HazelcastInstance (com.hazelcast.core.HazelcastInstance)36 SlowTest (com.hazelcast.test.annotation.SlowTest)25 QuickTest (com.hazelcast.test.annotation.QuickTest)14 CPMember (com.hazelcast.cp.CPMember)11 Config (com.hazelcast.config.Config)10 RestApiConfig (com.hazelcast.config.RestApiConfig)10 RestServerEndpointConfig (com.hazelcast.config.RestServerEndpointConfig)10 HazelcastTestSupport.smallInstanceConfig (com.hazelcast.test.HazelcastTestSupport.smallInstanceConfig)10 JsonArray (com.hazelcast.internal.json.JsonArray)6 JsonObject (com.hazelcast.internal.json.JsonObject)6 JsonValue (com.hazelcast.internal.json.JsonValue)5 CPSession (com.hazelcast.cp.session.CPSession)2 CPGroup (com.hazelcast.cp.CPGroup)1 IAtomicLong (com.hazelcast.cp.IAtomicLong)1 RaftGroupId (com.hazelcast.cp.internal.RaftGroupId)1