Search in sources :

Example 16 with ConnectionResponse

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

the class RestCPSubsystemTest method test_forceDestroyMETADATACPGroup.

@Test
public void test_forceDestroyMETADATACPGroup() throws IOException {
    HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    ConnectionResponse response = new HTTPCommunicator(instance1).forceDestroyCPGroup(METADATA_CP_GROUP_NAME, clusterName, null);
    assertEquals(400, 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 17 with ConnectionResponse

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

the class RestCPSubsystemTest method test_removeCPMember_withInvalidCredentials.

@Test
public void test_removeCPMember_withInvalidCredentials() throws IOException {
    HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(config);
    waitUntilCPDiscoveryCompleted(instance1, instance2, instance3);
    CPMember crashedCPMember = instance3.getCPSubsystem().getLocalCPMember();
    instance3.getLifecycleService().terminate();
    assertClusterSizeEventually(2, instance1, instance2);
    ConnectionResponse response = new HTTPCommunicator(instance1).removeCPMember(crashedCPMember.getUuid(), "x", "x");
    assertEquals(403, response.responseCode);
}
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 18 with ConnectionResponse

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

the class RestCPSubsystemTest method test_getDefaultCPGroupByName.

@Test
public void test_getDefaultCPGroupByName() throws IOException {
    final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(config);
    waitUntilCPDiscoveryCompleted(instance1, instance2, instance3);
    instance1.getCPSubsystem().getAtomicLong("long1").set(5);
    HTTPCommunicator communicator = new HTTPCommunicator(instance1);
    ConnectionResponse response = communicator.getCPGroupByName(DEFAULT_GROUP_NAME);
    assertEquals(200, response.responseCode);
    CPMember cpMember1 = instance1.getCPSubsystem().getLocalCPMember();
    CPMember cpMember2 = instance2.getCPSubsystem().getLocalCPMember();
    CPMember cpMember3 = instance3.getCPSubsystem().getLocalCPMember();
    boolean cpMember1Found = false;
    boolean cpMember2Found = false;
    boolean cpMember3Found = false;
    JsonObject json = (JsonObject) Json.parse(response.response);
    assertEquals(DEFAULT_GROUP_NAME, ((JsonObject) json.get("id")).getString("name", ""));
    assertEquals(CPGroupStatus.ACTIVE.name(), json.getString("status", ""));
    for (JsonValue val : (JsonArray) json.get("members")) {
        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 19 with ConnectionResponse

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

the class RestCPSubsystemTest method test_removeInvalidCPMember.

@Test
public void test_removeInvalidCPMember() throws IOException {
    HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    ConnectionResponse response = new HTTPCommunicator(instance1).removeCPMember(newUnsecureUUID(), clusterName, null);
    assertEquals(400, 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 20 with ConnectionResponse

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

the class RestCPSubsystemTest method test_getLocalCPMember.

@Test
public void test_getLocalCPMember() throws IOException {
    final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(config);
    HazelcastInstance instance4 = Hazelcast.newHazelcastInstance(config);
    waitUntilCPDiscoveryCompleted(instance1, instance2, instance3, instance4);
    ConnectionResponse response1 = new HTTPCommunicator(instance1).getLocalCPMember();
    ConnectionResponse response2 = new HTTPCommunicator(instance2).getLocalCPMember();
    ConnectionResponse response3 = new HTTPCommunicator(instance3).getLocalCPMember();
    ConnectionResponse response4 = new HTTPCommunicator(instance4).getLocalCPMember();
    assertEquals(200, response1.responseCode);
    assertEquals(200, response2.responseCode);
    assertEquals(200, response3.responseCode);
    assertEquals(404, response4.responseCode);
    CPMember cpMember1 = instance1.getCPSubsystem().getLocalCPMember();
    CPMember cpMember2 = instance2.getCPSubsystem().getLocalCPMember();
    CPMember cpMember3 = instance3.getCPSubsystem().getLocalCPMember();
    assertEquals(cpMember1.getUuid(), UUID.fromString(((JsonObject) Json.parse(response1.response)).getString("uuid", "")));
    assertEquals(cpMember2.getUuid(), UUID.fromString(((JsonObject) Json.parse(response2.response)).getString("uuid", "")));
    assertEquals(cpMember3.getUuid(), UUID.fromString(((JsonObject) Json.parse(response3.response)).getString("uuid", "")));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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

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