use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class BasicMapTest method testJsonPutGet.
@Test
public void testJsonPutGet() {
final IMap<String, HazelcastJsonValue> map = getInstance().getMap(randomMapName());
HazelcastJsonValue value = new HazelcastJsonValue("{ \"age\": 4 }");
map.put("item1", value);
HazelcastJsonValue retrieved = map.get("item1");
assertEquals(value, retrieved);
assertEquals(4, Json.parse(retrieved.toString()).asObject().get("age").asInt());
}
use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class JsonIndexIntegrationTest method testIndex_viaQueries.
@Test
public void testIndex_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());
}
use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class JsonIndexIntegrationTest method testViaAccessingInternalIndexes.
@Test
public void testViaAccessingInternalIndexes() {
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));
}
Set<QueryableEntry> records = getRecords(instance, MAP_NAME, "age", 40);
assertEquals(1, records.size());
records = getRecords(instance, MAP_NAME, "active", true);
assertEquals(500, records.size());
records = getRecords(instance, MAP_NAME, "name", "sancar");
assertEquals(1000, records.size());
}
use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class ConvertersTest method testJsonConverter.
@Test
public void testJsonConverter() {
JsonConverter converter = JsonConverter.INSTANCE;
checkConverter(converter, Converter.ID_JSON, JSON, HazelcastJsonValue.class);
checkConverterConversions(converter, VARCHAR, JSON, OBJECT);
assertEquals("[1,2,3]", converter.asVarchar(new HazelcastJsonValue("[1,2,3]")));
assertEquals(new HazelcastJsonValue("[1,2,3]"), converter.asObject(new HazelcastJsonValue("[1,2,3]")));
checkConverterSelf(converter);
}
use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.
the class RestTest method testMapGetWithJson.
@Test
public void testMapGetWithJson() throws IOException {
final String mapName = "mapName";
final String key = "key";
String jsonValue = Json.object().add("arbitrary-attribute", "arbitrary-value").toString();
instance.getMap(mapName).put(key, new HazelcastJsonValue(jsonValue));
HTTPCommunicator.ConnectionResponse response = communicator.mapGet(mapName, key);
assertContains(response.responseHeaders.get("Content-Type").iterator().next(), bytesToString(CONTENT_TYPE_JSON));
assertEquals(jsonValue, response.response);
}
Aggregations