Search in sources :

Example 36 with ConnectionResponse

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

the class RestCPSubsystemTest method test_getCPGroupIds.

@Test
public void test_getCPGroupIds() throws IOException {
    HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    instance1.getCPSubsystem().getAtomicLong("long1").set(5);
    instance1.getCPSubsystem().getAtomicLong("long1@custom").set(5);
    HTTPCommunicator communicator = new HTTPCommunicator(instance1);
    ConnectionResponse response = communicator.getCPGroupIds();
    assertEquals(200, response.responseCode);
    JsonArray responseArr = (JsonArray) Json.parse(response.response);
    boolean metadataCPGroupExists = false;
    boolean defaultCPGroupExists = false;
    boolean customCPGroupExists = false;
    for (JsonValue val : responseArr) {
        JsonObject obj = (JsonObject) val;
        String name = obj.getString("name", "");
        if (CPGroup.DEFAULT_GROUP_NAME.equals(name)) {
            defaultCPGroupExists = true;
        } else if (METADATA_CP_GROUP_NAME.equals(name)) {
            metadataCPGroupExists = true;
        } else if ("custom".equals(name)) {
            customCPGroupExists = true;
        }
    }
    assertTrue(metadataCPGroupExists);
    assertTrue(defaultCPGroupExists);
    assertTrue(customCPGroupExists);
}
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) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 37 with ConnectionResponse

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

the class RestCPSubsystemTest method test_removeCPMemberFromNonMaster.

@Test
public void test_removeCPMemberFromNonMaster() throws IOException {
    Hazelcast.newHazelcastInstance(config);
    HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);
    HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(config);
    waitUntilCPDiscoveryCompleted(instance2, instance3);
    CPMember crashedCPMember = instance2.getCPSubsystem().getLocalCPMember();
    instance2.getLifecycleService().terminate();
    ConnectionResponse response = new HTTPCommunicator(instance3).removeCPMember(crashedCPMember.getUuid(), clusterName, null);
    assertEquals(200, 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 38 with ConnectionResponse

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

the class RestCPSubsystemTest method test_forceDestroyInvalidCPGroup.

@Test
public void test_forceDestroyInvalidCPGroup() throws IOException {
    HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    ConnectionResponse response = new HTTPCommunicator(instance1).forceDestroyCPGroup("custom", 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 39 with ConnectionResponse

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

the class RestCPSubsystemTest method test_forceCloseValidCPSession_withInvalidCredentials.

@Test
public void test_forceCloseValidCPSession_withInvalidCredentials() throws IOException, ExecutionException, InterruptedException {
    HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    instance1.getCPSubsystem().getLock("lock1").lock();
    instance1.getCPSubsystem().getLock("lock1").unlock();
    Collection<CPSession> sessions1 = instance1.getCPSubsystem().getCPSessionManagementService().getAllSessions(DEFAULT_GROUP_NAME).toCompletableFuture().get();
    assertEquals(1, sessions1.size());
    long sessionId = sessions1.iterator().next().id();
    ConnectionResponse response = new HTTPCommunicator(instance1).forceCloseCPSession(DEFAULT_GROUP_NAME, sessionId, "x", "x");
    assertEquals(403, response.responseCode);
    Collection<CPSession> sessions2 = instance1.getCPSubsystem().getCPSessionManagementService().getAllSessions(DEFAULT_GROUP_NAME).toCompletableFuture().get();
    assertEquals(1, sessions2.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CPSession(com.hazelcast.cp.session.CPSession) 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