Search in sources :

Example 86 with HazelcastJsonValue

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

the class AbstractJsonGetterTest method testDifferentQueriesCreateNewContexts.

@Test
public void testDifferentQueriesCreateNewContexts() throws Exception {
    String jsonText = Json.object().add("at1", "val1").add("at2", "val2").toString();
    HazelcastJsonValue jsonValue = new HazelcastJsonValue(jsonText);
    JsonSchemaNode node = JsonSchemaHelper.createSchema(factory.createParser(jsonText));
    assertEquals("val1", getter.getValue(jsonValue, "at1", node));
    assertEquals("val1", getter.getValue(jsonValue, "at1", node));
    assertEquals("val1", getter.getValue(jsonValue, "at1", node));
    assertEquals("val1", getter.getValue(jsonValue, "at1", node));
    assertEquals("val2", getter.getValue(jsonValue, "at2", node));
    assertEquals("val2", getter.getValue(jsonValue, "at2", node));
    assertEquals("val2", getter.getValue(jsonValue, "at2", node));
    assertEquals("val2", getter.getValue(jsonValue, "at2", node));
    assertEquals(2, getter.getContextCacheSize());
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) JsonSchemaNode(com.hazelcast.json.internal.JsonSchemaNode) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 87 with HazelcastJsonValue

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

the class EntryProcessorTest method testEntryProcessorOnJsonStrings.

@Test
public void testEntryProcessorOnJsonStrings() {
    Config cfg = getConfig();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance(cfg);
    HazelcastInstance instance2 = factory.newHazelcastInstance(cfg);
    IMap<String, HazelcastJsonValue> map = instance2.getMap(MAP_NAME);
    Set<String> keys = new HashSet<>();
    for (int i = 0; i < 4; i++) {
        final String key = generateKeyOwnedBy(instance1);
        keys.add(key);
    }
    for (String key : keys) {
        HazelcastJsonValue jsonString = new HazelcastJsonValue("{ \"value\": \"" + key + "\" }");
        map.put(key, jsonString);
    }
    map.executeOnKeys(keys, new JsonStringPropAdder());
    for (String key : keys) {
        HazelcastJsonValue jsonObject = map.get(key);
        assertNotNull(jsonObject);
        assertTrue(Json.parse(jsonObject.toString()).asObject().get(JsonStringPropAdder.NEW_FIELD).asBoolean());
    }
    instance1.shutdown();
    for (String key : keys) {
        HazelcastJsonValue jsonObject = map.get(key);
        assertNotNull(jsonObject);
        assertTrue(Json.parse(jsonObject.toString()).asObject().get(JsonStringPropAdder.NEW_FIELD).asBoolean());
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 88 with HazelcastJsonValue

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

the class IndexJsonTest method testJsonIndex.

@Test
public void testJsonIndex() {
    InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
    Indexes indexes = Indexes.newBuilder(ss, copyBehavior, DEFAULT_IN_MEMORY_FORMAT).extractors(Extractors.newBuilder(ss).build()).indexProvider(new DefaultIndexProvider()).usesCachedQueryableEntries(true).statsEnabled(true).global(true).build();
    Index numberIndex = indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "age"));
    Index boolIndex = indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "active"));
    Index stringIndex = indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "name"));
    for (int i = 0; i < 1001; i++) {
        Data key = ss.toData(i);
        String jsonString = "{\"age\" : " + i + "  , \"name\" : \"sancar\" , \"active\" :  " + (i % 2 == 0) + " } ";
        indexes.putEntry(new QueryEntry(ss, key, new HazelcastJsonValue(jsonString), Extractors.newBuilder(ss).build()), null, Index.OperationSource.USER);
    }
    assertEquals(1, numberIndex.getRecords(10).size());
    assertEquals(0, numberIndex.getRecords(-1).size());
    assertEquals(1001, stringIndex.getRecords("sancar").size());
    assertEquals(501, boolIndex.getRecords(true).size());
    assertEquals(501, size(indexes.query(new AndPredicate(new EqualPredicate("name", "sancar"), new EqualPredicate("active", "true")), SKIP_PARTITIONS_COUNT_CHECK)));
    assertEquals(300, size(indexes.query(Predicates.and(Predicates.greaterThan("age", 400), Predicates.equal("active", true)), SKIP_PARTITIONS_COUNT_CHECK)));
    assertEquals(1001, size(indexes.query(new SqlPredicate("name == sancar"), SKIP_PARTITIONS_COUNT_CHECK)));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) AndPredicate(com.hazelcast.query.impl.predicates.AndPredicate) EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) SqlPredicate(com.hazelcast.query.impl.predicates.SqlPredicate) Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 89 with HazelcastJsonValue

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

the class JsonIndexIntegrationTest method testEntryProcessorChanges_viaQueries.

@Test
public void testEntryProcessorChanges_viaQueries() {
    HazelcastInstance instance = createHazelcastInstance();
    IMap<Integer, HazelcastJsonValue> map = instance.getMap(MAP_NAME);
    map.addIndex(IndexType.HASH, "age");
    map.addIndex(IndexType.HASH, "active");
    map.addIndex(IndexType.HASH, "name");
    for (int i = 0; i < 1000; i++) {
        String jsonString = "{\"age\" : " + i + "  , \"name\" : \"sancar\" , \"active\" :  " + (i % 2 == 0) + " } ";
        map.put(i, new HazelcastJsonValue(jsonString));
    }
    assertEquals(500, map.values(Predicates.and(Predicates.equal("name", "sancar"), Predicates.equal("active", "true"))).size());
    assertEquals(299, map.values(Predicates.and(Predicates.greaterThan("age", 400), Predicates.equal("active", true))).size());
    assertEquals(1000, map.values(Predicates.sql("name == sancar")).size());
    map.executeOnEntries(new JsonEntryProcessor());
    assertEquals(1000, map.values(Predicates.and(Predicates.equal("name", "sancar"), Predicates.equal("active", false))).size());
    assertEquals(0, map.values(Predicates.and(Predicates.greaterThan("age", 400), Predicates.equal("active", false))).size());
    assertEquals(1000, map.values(Predicates.sql("name == sancar")).size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 90 with HazelcastJsonValue

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

the class JsonIndexIntegrationTest method testEntryProcessorChanges_viaQueries_withoutIndex.

@Test
public void testEntryProcessorChanges_viaQueries_withoutIndex() {
    HazelcastInstance instance = createHazelcastInstance();
    IMap<Integer, HazelcastJsonValue> map = instance.getMap(MAP_NAME);
    for (int i = 0; i < 1000; i++) {
        String jsonString = "{\"age\" : " + i + "  , \"name\" : \"sancar\" , \"active\" :  " + (i % 2 == 0) + " } ";
        map.put(i, new HazelcastJsonValue(jsonString));
    }
    assertEquals(500, map.values(Predicates.and(Predicates.equal("name", "sancar"), Predicates.equal("active", "true"))).size());
    assertEquals(299, map.values(Predicates.and(Predicates.greaterThan("age", 400), Predicates.equal("active", true))).size());
    assertEquals(1000, map.values(Predicates.sql("name == sancar")).size());
    map.executeOnEntries(new JsonEntryProcessor());
    assertEquals(1000, map.values(Predicates.and(Predicates.equal("name", "sancar"), Predicates.equal("active", false))).size());
    assertEquals(0, map.values(Predicates.and(Predicates.greaterThan("age", 400), Predicates.equal("active", false))).size());
    assertEquals(1000, map.values(Predicates.sql("name == sancar")).size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) 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