Search in sources :

Example 61 with JsonValue

use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.

the class JsonUtil method getInt.

/**
 * Returns a field in a Json object as an int.
 * Throws IllegalArgumentException if the field value is null.
 *
 * @param object the Json Object
 * @param field the field in the Json object to return
 * @return the Json field value as an int
 */
public static int getInt(JsonObject object, String field) {
    final JsonValue value = object.get(field);
    throwExceptionIfNull(value, field);
    return value.asInt();
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue)

Example 62 with JsonValue

use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.

the class JsonUtil method getArray.

/**
 * Returns a field in a Json object as an array.
 * Throws IllegalArgumentException if the field value is null.
 *
 * @param object the Json Object
 * @param field the field in the Json object to return
 * @return the Json field value as an array
 */
public static JsonArray getArray(JsonObject object, String field) {
    final JsonValue value = object.get(field);
    throwExceptionIfNull(value, field);
    return value.asArray();
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue)

Example 63 with JsonValue

use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.

the class RestLogLevelTest method testGetSetResetLogLevel.

@Test
public void testGetSetResetLogLevel() throws IOException {
    Config config = createReadWriteConfig();
    HazelcastInstance instance = factory.newHazelcastInstance(config);
    HTTPCommunicator communicator = new HTTPCommunicator(instance);
    HTTPCommunicator.ConnectionResponse response = communicator.getLogLevel();
    JsonValue jsonValue = Json.parse(response.response).asObject().get("logLevel");
    assertTrue(jsonValue.isNull());
    response = communicator.setLogLevel(config.getClusterName(), getPassword(), Level.FINE);
    jsonValue = Json.parse(response.response).asObject().get("message");
    assertEquals("log level is changed", jsonValue.asString());
    response = communicator.getLogLevel();
    jsonValue = Json.parse(response.response).asObject().get("logLevel");
    assertEquals(Level.FINE.getName(), jsonValue.asString());
    response = communicator.resetLogLevel(config.getClusterName(), getPassword());
    jsonValue = Json.parse(response.response).asObject().get("message");
    assertEquals("log level is reset", jsonValue.asString());
    response = communicator.getLogLevel();
    jsonValue = Json.parse(response.response).asObject().get("logLevel");
    assertTrue(jsonValue.isNull());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) RestApiConfig(com.hazelcast.config.RestApiConfig) JsonValue(com.hazelcast.internal.json.JsonValue) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 64 with JsonValue

use of com.hazelcast.internal.json.JsonValue 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 65 with JsonValue

use of com.hazelcast.internal.json.JsonValue 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)

Aggregations

JsonValue (com.hazelcast.internal.json.JsonValue)85 Test (org.junit.Test)36 JsonObject (com.hazelcast.internal.json.JsonObject)35 QuickTest (com.hazelcast.test.annotation.QuickTest)30 JsonArray (com.hazelcast.internal.json.JsonArray)28 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)25 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)20 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 KubernetesApiProvider.convertToString (com.hazelcast.kubernetes.KubernetesApiProvider.convertToString)6 EndpointAddress (com.hazelcast.kubernetes.KubernetesClient.EndpointAddress)6 HashSet (java.util.HashSet)6 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)5 SlowTest (com.hazelcast.test.annotation.SlowTest)5 Address (com.hazelcast.cluster.Address)4 CPMember (com.hazelcast.cp.CPMember)4 IOException (java.io.IOException)4 JsonUtil.fromJsonObject (com.hazelcast.internal.util.JsonUtil.fromJsonObject)3 JsonUtil.getString (com.hazelcast.internal.util.JsonUtil.getString)3