Search in sources :

Example 91 with HazelcastJsonValue

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

the class AbstractReplicatedMapListenerTest method testListenWithPredicateWithAttributePath.

@Test
public void testListenWithPredicateWithAttributePath() {
    ReplicatedMap<Integer, HazelcastJsonValue> replicatedMap = createClusterAndGetRandomReplicatedMap();
    EventCountingListener<Integer, HazelcastJsonValue> listener = new EventCountingListener<>();
    replicatedMap.addEntryListener(listener, Predicates.equal("a", "foo"));
    replicatedMap.put(1, new HazelcastJsonValue("{\"a\": \"notFoo\"}"));
    replicatedMap.put(2, new HazelcastJsonValue("{\"a\": \"foo\"}"));
    assertTrueEventually(() -> assertEquals(1, listener.addCount.get()));
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) Test(org.junit.Test)

Example 92 with HazelcastJsonValue

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

the class HazelcastJsonValueConstructorTest method test.

@Test
public void test() {
    HazelcastJsonValue value = new HazelcastJsonValue("{\"a\": 11}");
    HazelcastJsonValueConstructor constructor = new HazelcastJsonValueConstructor(HazelcastJsonValue.class);
    HazelcastJsonValue cloned = (HazelcastJsonValue) constructor.createNew(value);
    assertEquals(cloned, value);
}
Also used : HazelcastJsonValueConstructor(com.hazelcast.test.starter.constructor.HazelcastJsonValueConstructor) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 93 with HazelcastJsonValue

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

the class SqlJsonTest method test_topLevelFieldExtraction.

@Test
public void test_topLevelFieldExtraction() {
    String name = randomName();
    sqlService.execute("CREATE MAPPING " + name + " (" + "id INT EXTERNAL NAME \"__key.id\"" + ", name VARCHAR EXTERNAL NAME \"this.name\"" + ") TYPE " + IMapSqlConnector.TYPE_NAME + ' ' + "OPTIONS (" + '\'' + OPTION_KEY_FORMAT + "'='" + JSON_FLAT_FORMAT + '\'' + ", '" + OPTION_VALUE_FORMAT + "'='" + JSON_FLAT_FORMAT + '\'' + ")");
    sqlService.execute("SINK INTO " + name + " VALUES (1, 'Alice')");
    assertRowsAnyOrder("SELECT __key, this FROM " + name, singletonList(new Row(new HazelcastJsonValue("{\"id\":1}"), new HazelcastJsonValue("{\"name\":\"Alice\"}"))));
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) Test(org.junit.Test)

Example 94 with HazelcastJsonValue

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

the class SqlJsonTest method test_jsonType.

@Test
public void test_jsonType() {
    String name = randomName();
    String createSql = format("CREATE MAPPING %s TYPE %s ", name, IMapSqlConnector.TYPE_NAME) + "OPTIONS ( " + format("'%s' = 'json'", OPTION_KEY_FORMAT) + format(", '%s' = 'json'", OPTION_VALUE_FORMAT) + ")";
    sqlService.execute(createSql);
    sqlService.execute("SINK INTO " + name + " VALUES (CAST('[1,2,3]' AS JSON), CAST('[4,5,6]' AS JSON))");
    assertRowsAnyOrder("SELECT __key, this FROM " + name, singletonList(new Row(new HazelcastJsonValue("[1,2,3]"), new HazelcastJsonValue("[4,5,6]"))));
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) Test(org.junit.Test)

Example 95 with HazelcastJsonValue

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

the class SqlJsonTest method test_jsonType.

@Test
public void test_jsonType() {
    String name = createRandomTopic();
    String createSql = format("CREATE MAPPING %s TYPE %s ", name, KafkaSqlConnector.TYPE_NAME) + "OPTIONS ( " + format("'%s' = 'json'", OPTION_KEY_FORMAT) + format(", '%s' = 'json'", OPTION_VALUE_FORMAT) + format(", 'bootstrap.servers' = '%s'", kafkaTestSupport.getBrokerConnectionString()) + ", 'auto.offset.reset' = 'earliest'" + ")";
    sqlService.execute(createSql);
    assertTopicEventually(name, "INSERT INTO " + name + " VALUES ('[1,2,3]', '[4,5,6]')", createMap("[1,2,3]", "[4,5,6]"));
    assertRowsEventuallyInAnyOrder("SELECT * FROM " + name, singletonList(new Row(new HazelcastJsonValue("[1,2,3]"), new HazelcastJsonValue("[4,5,6]"))));
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) 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