Search in sources :

Example 36 with JsonObject

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

the class HttpCommandProcessor method response.

protected static JsonObject response(ResponseType type, String... attributes) {
    JsonObject object = new JsonObject().add("status", type.toString());
    if (attributes.length > 0) {
        for (int i = 0; i < attributes.length; ) {
            String key = attributes[i++];
            String value = attributes[i++];
            if (value != null) {
                object.add(key, value);
            }
        }
    }
    return object;
}
Also used : JsonObject(com.hazelcast.internal.json.JsonObject) StringUtil.bytesToString(com.hazelcast.internal.util.StringUtil.bytesToString)

Example 37 with JsonObject

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

the class SlowOperationDetector_JsonTest method testJSON_SlowEntryProcessor.

@Test
public void testJSON_SlowEntryProcessor() {
    for (int i = 0; i < 2; i++) {
        map.executeOnEntries(getSlowEntryProcessor(3));
    }
    map.executeOnEntries(getSlowEntryProcessor(4));
    map.executeOnEntries(getSlowEntryProcessor(3));
    awaitSlowEntryProcessors();
    logger.finest(getOperationStats(instance).toString());
    JsonObject firstLogJsonObject = getSlowOperationLogsJsonArray(instance).get(0).asObject();
    assertJSONContainsClassName(firstLogJsonObject, "SlowEntryProcessor");
    assertEqualsStringFormat("Expected %d invocations, but was %d", 4, firstLogJsonObject.get("invocations").asArray().size());
}
Also used : JsonObject(com.hazelcast.internal.json.JsonObject) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 38 with JsonObject

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

the class WanOpenSourceAntiEntropyMcEventsTest method testSyncAllREST.

@Test
public void testSyncAllREST() throws Exception {
    System.setProperty(HAZELCAST_TEST_USE_NETWORK, "true");
    HazelcastInstance hz = createHazelcastInstance(getConfigWithRest());
    HTTPCommunicator communicator = new HTTPCommunicator(hz);
    NodeEngineImpl nodeEngine = getNodeEngineImpl(hz);
    ManagementCenterService mcService = nodeEngine.getManagementCenterService();
    List<Event> events = new LinkedList<>();
    CountDownLatch latch = new CountDownLatch(1);
    mcService.setEventListener(event -> {
        events.add(event);
        latch.countDown();
    });
    String jsonResult = communicator.syncMapsOverWAN(hz.getConfig().getClusterName(), "", WAN_REPLICATION_NAME, WAN_PUBLISHER_ID);
    assertOpenEventually(latch);
    JsonObject result = Json.parse(jsonResult).asObject();
    Event event = events.get(0);
    assertTrue(event instanceof WanSyncIgnoredEvent);
    WanSyncIgnoredEvent syncIgnoredEvent = (WanSyncIgnoredEvent) event;
    assertNotNull(syncIgnoredEvent.getUuid());
    assertNull(result.getString("uuid", null));
    assertNull(syncIgnoredEvent.getMapName());
    assertEquals(WAN_SYNC_IGNORED, syncIgnoredEvent.getType());
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ManagementCenterService(com.hazelcast.internal.management.ManagementCenterService) Event(com.hazelcast.internal.management.events.Event) WanConsistencyCheckIgnoredEvent(com.hazelcast.internal.management.events.WanConsistencyCheckIgnoredEvent) WanSyncIgnoredEvent(com.hazelcast.internal.management.events.WanSyncIgnoredEvent) JsonObject(com.hazelcast.internal.json.JsonObject) WanSyncIgnoredEvent(com.hazelcast.internal.management.events.WanSyncIgnoredEvent) CountDownLatch(java.util.concurrent.CountDownLatch) LinkedList(java.util.LinkedList) HTTPCommunicator(com.hazelcast.internal.ascii.HTTPCommunicator) Test(org.junit.Test)

Example 39 with JsonObject

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

the class MapPredicateJsonTest method testNestedQuery.

@Test
public void testNestedQuery() {
    JsonObject object1 = Json.object();
    JsonObject nested1 = Json.object();
    JsonObject object2 = Json.object();
    JsonObject nested2 = Json.object();
    nested1.add("lim", 5);
    nested2.add("lim", 6);
    object1.add("inner", nested1);
    object2.add("inner", nested2);
    IMap<String, JsonValue> map = instance.getMap(randomMapName());
    HazelcastJsonValue p1 = putJsonString(map, "one", object1);
    HazelcastJsonValue p2 = putJsonString(map, "two", object2);
    Collection<JsonValue> vals = map.values(Predicates.greaterEqual("inner.lim", 6));
    assertEquals(1, vals.size());
    assertTrue(vals.contains(p2));
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 40 with JsonObject

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

the class MapPredicateJsonTest method testArrayInNestedQuery.

@Test
public void testArrayInNestedQuery() {
    JsonObject object1 = Json.object();
    JsonObject nested1 = Json.object();
    JsonObject object2 = Json.object();
    JsonObject nested2 = Json.object();
    JsonArray array1 = Json.array(new int[] { 1, 2, 3, 4, 5, 6 });
    JsonArray array2 = Json.array(new int[] { 10, 20, 30, 40, 50, 60 });
    nested1.add("arr", array1);
    nested2.add("arr", array2);
    object1.add("inner", nested1);
    object2.add("inner", nested2);
    IMap<String, JsonValue> map = instance.getMap(randomMapName());
    HazelcastJsonValue p1 = putJsonString(map, "one", object1);
    HazelcastJsonValue p2 = putJsonString(map, "two", object2);
    Collection<JsonValue> vals = map.values(Predicates.greaterEqual("inner.arr[2]", 20));
    assertEquals(1, vals.size());
    assertTrue(vals.contains(p2));
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonValue(com.hazelcast.internal.json.JsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) 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