Search in sources :

Example 41 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.

the class MapPredicateJsonTest method testSkipsNestedObjectsInAnyQuery.

@Test
public void testSkipsNestedObjectsInAnyQuery() {
    JsonObject value1 = Json.object();
    JsonObject value2 = Json.object();
    JsonObject value3 = Json.object();
    JsonObject innerObject = Json.object().add("s1", 1001).add("s2", 1002);
    JsonArray array1 = Json.array();
    array1.add(1).add(2).add(innerObject).add(3).add(4).add(20);
    JsonArray array2 = Json.array(new int[] { 10, 20, 30 });
    JsonArray array3 = Json.array(new int[] { 100, 200, 300, 400 });
    value1.add("numbers", array1);
    value2.add("numbers", array2);
    value3.add("numbers", array3);
    IMap<String, HazelcastJsonValue> map = instance.getMap(randomMapName());
    putJsonString(map, "one", value1);
    HazelcastJsonValue p2 = putJsonString(map, "two", value2);
    HazelcastJsonValue p3 = putJsonString(map, "three", value3);
    Collection<HazelcastJsonValue> vals = map.values(Predicates.greaterThan("numbers[any]", 20));
    assertEquals(2, vals.size());
    assertTrue(vals.contains(p2));
    assertTrue(vals.contains(p3));
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) 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 42 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.

the class MapPredicateJsonTest method testNonTerminalAttributeIs_queriedWithNotEqualsNull_shouldReturn.

@Test
public void testNonTerminalAttributeIs_queriedWithNotEqualsNull_shouldReturn() {
    String jsonWithNonTerminalQueryField = Json.object().add("user", Json.object().add("name", "abc").add("age", 23)).toString();
    IMap<Integer, HazelcastJsonValue> map = instance.getMap(randomMapName());
    map.put(1, new HazelcastJsonValue(jsonWithNonTerminalQueryField));
    Collection<Integer> keys = map.keySet(Predicates.notEqual("user", null));
    assertEquals(1, keys.size());
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 43 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.

the class MapPredicateJsonTest method putJsonString.

private static HazelcastJsonValue putJsonString(Map map, String name, int age, boolean onDuty) {
    String f = createNameAgeOnDuty(name, age, onDuty).toString();
    HazelcastJsonValue json = new HazelcastJsonValue(f);
    map.put(name, json);
    return json;
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue)

Example 44 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.

the class MapPredicateJsonTest method testSecondTimeKnownPatternIsUsed.

@Test
public void testSecondTimeKnownPatternIsUsed() {
    IMap<String, JsonValue> map = instance.getMap(randomMapName());
    HazelcastJsonValue p1 = putJsonString(map, "a", 30, true);
    HazelcastJsonValue p2 = putJsonString(map, "b", 20, false);
    HazelcastJsonValue p3 = putJsonString(map, "c", 10, true);
    Collection<JsonValue> vals = map.values(Predicates.greaterEqual("name", "b"));
    assertEquals(2, vals.size());
    assertTrue(vals.contains(p2));
    assertTrue(vals.contains(p3));
    vals = map.values(Predicates.greaterEqual("name", "b"));
    assertEquals(2, vals.size());
    assertTrue(vals.contains(p2));
    assertTrue(vals.contains(p3));
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 45 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.

the class JsonValueSerializationTest method testSerializeDeserializeJsonValue.

@Test
public void testSerializeDeserializeJsonValue() {
    HazelcastJsonValue jsonValue = new HazelcastJsonValue("{ \"key\": \"value\" }");
    Data jsonData = serializationService.toData(jsonValue);
    HazelcastJsonValue jsonDeserialized = serializationService.toObject(jsonData);
    assertEquals(jsonValue, jsonDeserialized);
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) Data(com.hazelcast.internal.serialization.Data) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)99 Test (org.junit.Test)80 QuickTest (com.hazelcast.test.annotation.QuickTest)74 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)67 JsonObject (com.hazelcast.internal.json.JsonObject)25 JsonValue (com.hazelcast.internal.json.JsonValue)19 NavigableJsonInputAdapter (com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter)12 JsonArray (com.hazelcast.internal.json.JsonArray)9 IMap (com.hazelcast.map.IMap)9 Map (java.util.Map)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 Data (com.hazelcast.internal.serialization.Data)5 JsonSchemaNode (com.hazelcast.json.internal.JsonSchemaNode)3 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)2 CompactGenericRecord (com.hazelcast.internal.serialization.impl.compact.CompactGenericRecord)2 PortableGenericRecord (com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord)2 StringUtil.bytesToString (com.hazelcast.internal.util.StringUtil.bytesToString)2 ExpressionValue (com.hazelcast.jet.sql.impl.support.expressions.ExpressionValue)2