use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.
the class MapPredicateJsonTest method testArrayInNestedQuery_whenOneArrayIsShort_shouldNotThrow.
@Test
public void testArrayInNestedQuery_whenOneArrayIsShort_shouldNotThrow() {
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 });
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);
putJsonString(map, "two", object2);
Collection<JsonValue> vals = map.values(Predicates.lessEqual("inner.arr[2]", 20));
assertEquals(1, vals.size());
assertTrue(vals.contains(p1));
}
use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.
the class MapPredicateJsonTest method testSkipsNestedArraysInAnyQuery.
@Test
public void testSkipsNestedArraysInAnyQuery() {
JsonObject value1 = Json.object();
JsonObject value2 = Json.object();
JsonObject value3 = Json.object();
JsonArray innerArray1 = Json.array(new int[] { 1001, 1002 });
JsonArray array1 = Json.array();
array1.add(1).add(2).add(innerArray1).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, JsonValue> map = instance.getMap(randomMapName());
putJsonString(map, "one", value1);
HazelcastJsonValue p2 = putJsonString(map, "two", value2);
HazelcastJsonValue p3 = putJsonString(map, "three", value3);
Collection<JsonValue> vals = map.values(Predicates.greaterThan("numbers[any]", 20));
assertEquals(2, vals.size());
assertTrue(vals.contains(p2));
assertTrue(vals.contains(p3));
}
use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.
the class MapPredicateJsonTest method testQueryOnArrayIndexOnKey.
@Test
public void testQueryOnArrayIndexOnKey() {
JsonObject value1 = Json.object();
JsonObject value2 = Json.object();
JsonObject value3 = Json.object();
JsonArray array1 = Json.array(new int[] { 1, 2, 3, 4, 5 });
JsonArray array2 = Json.array(new int[] { 10, 20, 30, 40, 50 });
JsonArray array3 = Json.array(new int[] { 100, 200, 300, 400, 500 });
value1.add("numbers", array1);
value2.add("numbers", array2);
value3.add("numbers", array3);
IMap<JsonValue, String> map = instance.getMap(randomMapName());
String p1 = putWithJsonStringKey(map, value1, "one");
String p2 = putWithJsonStringKey(map, value2, "two");
String p3 = putWithJsonStringKey(map, value3, "three");
Collection<String> vals = map.values(Predicates.greaterEqual("__key.numbers[1]", 20));
assertEquals(2, vals.size());
assertTrue(vals.contains(p2));
assertTrue(vals.contains(p3));
}
use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.
the class SlowOperationDetector_JsonTest method testJSON_multipleEntryProcessorClasses.
@Test
public void testJSON_multipleEntryProcessorClasses() throws InterruptedException {
for (int i = 0; i < 2; i++) {
map.executeOnEntries(getSlowEntryProcessor(3));
}
SlowEntryProcessorChild entryProcessorChild = new SlowEntryProcessorChild(3);
map.executeOnEntries(entryProcessorChild);
map.executeOnEntries(getSlowEntryProcessor(4));
awaitSlowEntryProcessors();
entryProcessorChild.await();
logger.finest(getOperationStats(instance).toString());
JsonArray slowOperationLogsJsonArray = getSlowOperationLogsJsonArray(instance);
JsonObject firstLogJsonObject = slowOperationLogsJsonArray.get(0).asObject();
JsonObject secondLogJsonObject = slowOperationLogsJsonArray.get(1).asObject();
assertJSONContainsClassNameJustOnce(firstLogJsonObject, secondLogJsonObject, "SlowEntryProcessor");
assertJSONContainsClassNameJustOnce(firstLogJsonObject, secondLogJsonObject, "SlowEntryProcessorChild");
int firstSize = firstLogJsonObject.get("invocations").asArray().size();
int secondSize = secondLogJsonObject.get("invocations").asArray().size();
assertTrue(format("Expected to find 1 and 3 invocations in logs, but was %d and %d", firstSize, secondSize), (firstSize == 1 ^ secondSize == 1) && (firstSize == 3 ^ secondSize == 3));
}
Aggregations