use of com.hazelcast.query.PredicateBuilder in project hazelcast by hazelcast.
the class QueryBasicTest method testPredicateCustomAttribute.
@Test(timeout = 1000 * 60)
public void testPredicateCustomAttribute() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<Integer, CustomObject> map = instance.getMap("testPredicateCustomAttribute");
CustomAttribute attribute = new CustomAttribute(78, 145);
CustomObject customObject = new CustomObject("name1", UuidUtil.newUnsecureUUID(), attribute);
map.put(1, customObject);
CustomObject object2 = new CustomObject("name2", UuidUtil.newUnsecureUUID(), attribute);
map.put(2, object2);
assertEquals(customObject, map.values(new PredicateBuilder().getEntryObject().get("uuid").equal(customObject.getUuid())).iterator().next());
assertEquals(2, map.values(new PredicateBuilder().getEntryObject().get("attribute").equal(attribute)).size());
assertEquals(object2, map.values(new PredicateBuilder().getEntryObject().get("uuid").in(object2.getUuid())).iterator().next());
assertEquals(2, map.values(new PredicateBuilder().getEntryObject().get("attribute").in(attribute)).size());
}
use of com.hazelcast.query.PredicateBuilder in project hazelcast by hazelcast.
the class QueryBasicTest method testPredicateEnumAttribute.
private void testPredicateEnumAttribute(IMap<Integer, NodeType> map) {
map.put(1, NodeType.MEMBER);
map.put(2, NodeType.LITE_MEMBER);
map.put(3, NodeType.JAVA_CLIENT);
assertEquals(NodeType.MEMBER, map.values(new SqlPredicate("this=MEMBER")).iterator().next());
assertEquals(2, map.values(new SqlPredicate("this in (MEMBER, LITE_MEMBER)")).size());
assertEquals(NodeType.JAVA_CLIENT, map.values(new PredicateBuilder().getEntryObject().get("this").equal(NodeType.JAVA_CLIENT)).iterator().next());
assertEquals(0, map.values(new PredicateBuilder().getEntryObject().get("this").equal(NodeType.CSHARP_CLIENT)).size());
assertEquals(2, map.values(new PredicateBuilder().getEntryObject().get("this").in(NodeType.LITE_MEMBER, NodeType.MEMBER)).size());
}
use of com.hazelcast.query.PredicateBuilder in project hazelcast by hazelcast.
the class QueryBasicTest method queryWithThis.
@Test(timeout = 1000 * 60)
public void queryWithThis() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, String> map = instance.getMap("queryWithThis");
map.addIndex("this", false);
for (int i = 0; i < 1000; i++) {
map.put("" + i, "" + i);
}
Predicate predicate = new PredicateBuilder().getEntryObject().get("this").equal("10");
Collection<String> set = map.values(predicate);
assertEquals(1, set.size());
assertEquals(1, map.values(new SqlPredicate("this=15")).size());
}
use of com.hazelcast.query.PredicateBuilder in project hazelcast by hazelcast.
the class MapLiteMemberTest method testMapKeysQuery.
public static void testMapKeysQuery(final IMap<Integer, Object> map) {
map.put(1, 2);
EntryObject entryObject = new PredicateBuilder().getEntryObject();
PredicateBuilder predicateBuilder = entryObject.key().equal(1);
Collection values = map.keySet(predicateBuilder);
assertEquals(1, values.size());
assertEquals(1, values.iterator().next());
}
use of com.hazelcast.query.PredicateBuilder in project hazelcast by hazelcast.
the class IndexIntegrationTest method putRemove_withIndex_whereAttributeIsNull.
@Test
public void putRemove_withIndex_whereAttributeIsNull() {
// GIVEN
MapIndexConfig mapIndexConfig = new MapIndexConfig();
mapIndexConfig.setAttribute("amount");
mapIndexConfig.setOrdered(false);
MapConfig mapConfig = new MapConfig().setName("map");
mapConfig.addMapIndexConfig(mapIndexConfig);
Config config = new Config();
config.addMapConfig(mapConfig);
Trade trade = new Trade();
trade.setCurrency("EUR");
trade.setAmount(null);
HazelcastInstance instance = createHazelcastInstance(config);
IMap<Integer, Trade> map = instance.getMap("map");
// WHEN
map.put(1, trade);
map.remove(1);
EntryObject e = new PredicateBuilder().getEntryObject();
Predicate predicate = e.get("amount").isNull();
Collection<Trade> values = map.values(predicate);
// THEN
assertEquals(0, values.size());
assertNull(map.get(1));
}
Aggregations