use of com.hazelcast.internal.json.JsonObject 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);
}
use of com.hazelcast.internal.json.JsonObject 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", "")));
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class ClusterHotRestartStatusDTOTest method testSerialization.
@Test
public void testSerialization() {
Map<String, MemberHotRestartStatus> memberHotRestartStatusMap = new HashMap<String, MemberHotRestartStatus>();
memberHotRestartStatusMap.put("127.0.0.1:5701", MemberHotRestartStatus.PENDING);
memberHotRestartStatusMap.put("127.0.0.1:5702", MemberHotRestartStatus.SUCCESSFUL);
ClusterHotRestartStatusDTO dto = new ClusterHotRestartStatusDTO(HotRestartClusterDataRecoveryPolicy.FULL_RECOVERY_ONLY, ClusterHotRestartStatus.IN_PROGRESS, 23, 42, memberHotRestartStatusMap);
JsonObject json = dto.toJson();
ClusterHotRestartStatusDTO deserialized = new ClusterHotRestartStatusDTO();
deserialized.fromJson(json);
assertEquals(dto.getDataRecoveryPolicy(), deserialized.getDataRecoveryPolicy());
assertEquals(dto.getHotRestartStatus(), deserialized.getHotRestartStatus());
assertEquals(dto.getRemainingValidationTimeMillis(), deserialized.getRemainingValidationTimeMillis());
assertEquals(dto.getRemainingDataLoadTimeMillis(), deserialized.getRemainingDataLoadTimeMillis());
assertEquals(dto.getMemberHotRestartStatusMap(), deserialized.getMemberHotRestartStatusMap());
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class JsonParser_Test method parse_doesNotFailWithManyEmptyObjects.
@Test
public void parse_doesNotFailWithManyEmptyObjects() {
JsonArray array = new JsonArray();
for (int i = 0; i < 1001; i++) {
array.add(new JsonObject());
}
final String input = array.toString();
JsonValue result = parse(input);
assertTrue(result.isArray());
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class JsonParser_Test method parse_failsOnTooDeeplyNestedObject.
@Test
public void parse_failsOnTooDeeplyNestedObject() {
JsonObject object = new JsonObject();
for (int i = 0; i < 1001; i++) {
object = new JsonObject().add("foo", object);
}
final String input = object.toString();
ParseException exception = assertException(ParseException.class, new RunnableEx() {
public void run() throws IOException {
parser.parse(input);
}
});
assertEquals("Nesting too deep at 1:7002", exception.getMessage());
}
Aggregations