Search in sources :

Example 21 with JsonArray

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

the class RestCPSubsystemTest method test_getMetadataCPGroupByName.

@Test
public void test_getMetadataCPGroupByName() throws IOException {
    final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(config);
    waitUntilCPDiscoveryCompleted(instance1, instance2, instance3);
    HTTPCommunicator communicator = new HTTPCommunicator(instance1);
    ConnectionResponse response = communicator.getCPGroupByName(METADATA_CP_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(METADATA_CP_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 22 with JsonArray

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

the class RestCPSubsystemTest method test_getCustomCPGroupByName.

@Test
public void test_getCustomCPGroupByName() 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@custom").set(5);
    HTTPCommunicator communicator = new HTTPCommunicator(instance1);
    ConnectionResponse response = communicator.getCPGroupByName("custom");
    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("custom", ((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 23 with JsonArray

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

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

the class JsonParser_Test method parse_doesNotFailWithManyEmptyArrays.

@Test
public void parse_doesNotFailWithManyEmptyArrays() {
    JsonArray array = new JsonArray();
    for (int i = 0; i < 1001; i++) {
        array.add(new JsonArray());
    }
    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) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 25 with JsonArray

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

Aggregations

JsonArray (com.hazelcast.internal.json.JsonArray)74 JsonObject (com.hazelcast.internal.json.JsonObject)42 Test (org.junit.Test)39 QuickTest (com.hazelcast.test.annotation.QuickTest)31 JsonValue (com.hazelcast.internal.json.JsonValue)28 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 CPMember (com.hazelcast.cp.CPMember)7 JsonUtil.getString (com.hazelcast.internal.util.JsonUtil.getString)7 SlowTest (com.hazelcast.test.annotation.SlowTest)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)4 Address (com.hazelcast.cluster.Address)3 JetException (com.hazelcast.jet.JetException)3 InputStreamReader (java.io.InputStreamReader)3 Collection (java.util.Collection)3 Map (java.util.Map)3 Request (org.elasticsearch.client.Request)3