Search in sources :

Example 56 with JsonObject

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);
}
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 57 with JsonObject

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", "")));
}
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)

Example 58 with JsonObject

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());
}
Also used : MemberHotRestartStatus(com.hazelcast.internal.management.dto.ClusterHotRestartStatusDTO.MemberHotRestartStatus) HashMap(java.util.HashMap) JsonObject(com.hazelcast.internal.json.JsonObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 59 with JsonObject

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());
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 60 with JsonObject

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());
}
Also used : JsonObject(com.hazelcast.internal.json.JsonObject) RunnableEx(com.hazelcast.internal.json.TestUtil.RunnableEx) ParseException(com.hazelcast.internal.json.ParseException) IOException(java.io.IOException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

JsonObject (com.hazelcast.internal.json.JsonObject)151 Test (org.junit.Test)56 JsonArray (com.hazelcast.internal.json.JsonArray)41 QuickTest (com.hazelcast.test.annotation.QuickTest)38 JsonValue (com.hazelcast.internal.json.JsonValue)34 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)26 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)23 HazelcastInstance (com.hazelcast.core.HazelcastInstance)11 JsonUtil.getString (com.hazelcast.internal.util.JsonUtil.getString)10 SlowTest (com.hazelcast.test.annotation.SlowTest)9 HashMap (java.util.HashMap)8 CPMember (com.hazelcast.cp.CPMember)7 ArrayList (java.util.ArrayList)7 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)6 NavigableJsonInputAdapter (com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter)6 JsonUtil.fromJsonObject (com.hazelcast.internal.util.JsonUtil.fromJsonObject)5 JsonUtil.toJsonObject (com.hazelcast.internal.util.JsonUtil.toJsonObject)5 Map (java.util.Map)5 ClusterService (com.hazelcast.internal.cluster.ClusterService)4 Address (com.hazelcast.cluster.Address)3