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());
}
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());
}
}
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)));
}
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());
}
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());
}
Aggregations