Search in sources :

Example 21 with JsonValue

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

the class GcpComputeApi method instances.

List<GcpAddress> instances(String project, String zone, Label label, String accessToken) {
    String response = RestClient.create(urlFor(project, zone, label)).withHeader("Authorization", String.format("OAuth %s", accessToken)).get().getBody();
    List<GcpAddress> result = new ArrayList<GcpAddress>();
    for (JsonValue item : toJsonArray(Json.parse(response).asObject().get("items"))) {
        if ("RUNNING".equals(item.asObject().get("status").asString())) {
            String privateAddress = null;
            String publicAddress = null;
            for (JsonValue networkInterface : toJsonArray(item.asObject().get("networkInterfaces"))) {
                privateAddress = networkInterface.asObject().getString("networkIP", null);
                for (JsonValue accessConfig : toJsonArray(networkInterface.asObject().get("accessConfigs"))) {
                    publicAddress = accessConfig.asObject().getString("natIP", null);
                }
            }
            if (privateAddress != null) {
                result.add(new GcpAddress(privateAddress, publicAddress));
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) JsonValue(com.hazelcast.internal.json.JsonValue)

Example 22 with JsonValue

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

the class MapPredicateJsonTest method testSkipsScalarValuesInCaseOfAnyAndAttributeName.

@Test
public void testSkipsScalarValuesInCaseOfAnyAndAttributeName() {
    JsonArray array1 = Json.array(new int[] { 1, 2, 3, 5000 });
    JsonArray array2 = Json.array(new int[] { 1, 5000, 3, 5 });
    JsonArray array3 = Json.array(new int[] { 1, 5000, 30, 40 });
    array1.add(Json.object().add("innerAttribute", 5000));
    JsonValue value1 = Json.object().add("arr", array1);
    JsonValue value2 = Json.object().add("arr", array2);
    JsonValue value3 = Json.object().add("arr", array3);
    IMap<String, HazelcastJsonValue> map = instance.getMap(randomMapName());
    HazelcastJsonValue p1 = putJsonString(map, "one", value1);
    putJsonString(map, "two", value2);
    putJsonString(map, "three", value3);
    Collection<HazelcastJsonValue> vals = map.values(Predicates.equal("arr[any].innerAttribute", 5000));
    assertEquals(1, vals.size());
    assertTrue(vals.contains(p1));
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) 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 23 with JsonValue

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

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

Example 25 with JsonValue

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

the class MapPredicateJsonTest method testQueryOnArrayIndex.

@Test
public void testQueryOnArrayIndex() {
    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<String, JsonValue> map = instance.getMap(randomMapName());
    HazelcastJsonValue p1 = putJsonString(map, "one", value1);
    HazelcastJsonValue p2 = putJsonString(map, "two", value2);
    HazelcastJsonValue p3 = putJsonString(map, "three", value3);
    Collection<String> vals = map.keySet(Predicates.greaterEqual("numbers[1]", 20));
    assertEquals(2, vals.size());
    assertTrue(vals.contains("two"));
    assertTrue(vals.contains("three"));
}
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

JsonValue (com.hazelcast.internal.json.JsonValue)85 Test (org.junit.Test)36 JsonObject (com.hazelcast.internal.json.JsonObject)35 QuickTest (com.hazelcast.test.annotation.QuickTest)30 JsonArray (com.hazelcast.internal.json.JsonArray)28 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)25 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)20 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 KubernetesApiProvider.convertToString (com.hazelcast.kubernetes.KubernetesApiProvider.convertToString)6 EndpointAddress (com.hazelcast.kubernetes.KubernetesClient.EndpointAddress)6 HashSet (java.util.HashSet)6 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)5 SlowTest (com.hazelcast.test.annotation.SlowTest)5 Address (com.hazelcast.cluster.Address)4 CPMember (com.hazelcast.cp.CPMember)4 IOException (java.io.IOException)4 JsonUtil.fromJsonObject (com.hazelcast.internal.util.JsonUtil.fromJsonObject)3 JsonUtil.getString (com.hazelcast.internal.util.JsonUtil.getString)3