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();
}
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();
}
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());
}
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);
}
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);
}
Aggregations