use of com.hazelcast.query.PredicateBuilder in project hazelcast by hazelcast.
the class QueryBasicTest method testInPredicateWithEmptyArray.
@Test(timeout = 1000 * 60)
public void testInPredicateWithEmptyArray() {
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
Config cfg = getConfig();
HazelcastInstance instance = nodeFactory.newHazelcastInstance(cfg);
final IMap<String, Value> map = instance.getMap("default");
for (int i = 0; i < 10; i++) {
final Value v = new Value("name" + i, new ValueType("type" + i), i);
map.put("" + i, v);
}
String[] emptyArray = new String[2];
final Predicate predicate = new PredicateBuilder().getEntryObject().get("name").in(emptyArray);
final Collection<Value> values = map.values(predicate);
assertEquals(values.size(), 0);
}
use of com.hazelcast.query.PredicateBuilder in project hazelcast by hazelcast.
the class NestedPredicateTest method nestedAttributeQuery_predicates.
@Test
public void nestedAttributeQuery_predicates() throws Exception {
// GIVEN
map.put(1, new Body("body1", new Limb("hand")));
map.put(2, new Body("body2", new Limb("leg")));
// WHEN
EntryObject e = new PredicateBuilder().getEntryObject();
Predicate predicate = e.get("limb.name").equal("leg");
Collection<Body> values = map.values(predicate);
// THEN
assertEquals(1, values.size());
assertEquals("body2", values.toArray(new Body[values.size()])[0].getName());
}
use of com.hazelcast.query.PredicateBuilder in project hazelcast by hazelcast.
the class NestedPredicateTest method singleAttributeQuery_predicates.
@Test
public void singleAttributeQuery_predicates() throws Exception {
// GIVEN
map.put(1, new Body("body1", new Limb("hand")));
map.put(2, new Body("body2", new Limb("leg")));
// WHEN
EntryObject e = new PredicateBuilder().getEntryObject();
Predicate predicate = e.get("name").equal("body1");
Collection<Body> values = map.values(predicate);
// THEN
assertEquals(1, values.size());
assertEquals("body1", values.toArray(new Body[values.size()])[0].getName());
}
use of com.hazelcast.query.PredicateBuilder in project hazelcast by hazelcast.
the class NestedPredicateWithExtractorTest method singleAttributeQuery_predicates.
@Test
public void singleAttributeQuery_predicates() throws Exception {
// GIVEN
map.put(1, new Body("body1", new Limb("hand")));
map.put(2, new Body("body2", new Limb("leg")));
// WHEN
EntryObject e = new PredicateBuilder().getEntryObject();
Predicate predicate = e.get("name").equal("body1");
Collection<Body> values = map.values(predicate);
// THEN
assertEquals(1, values.size());
assertEquals("body1", values.toArray(new Body[values.size()])[0].getName());
assertEquals(2 + 1, bodyExtractorExecutions);
assertEquals(0, limbExtractorExecutions);
}
use of com.hazelcast.query.PredicateBuilder in project hazelcast by hazelcast.
the class QueryBasicTest method testIndexingEnumAttributeIssue597.
@Test(timeout = 1000 * 60)
public void testIndexingEnumAttributeIssue597() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<Integer, Value> map = instance.getMap("default");
map.addIndex("state", true);
for (int i = 0; i < 4; i++) {
Value v = new Value(i % 2 == 0 ? State.STATE1 : State.STATE2, new ValueType(), i);
map.put(i, v);
}
Predicate predicate = new PredicateBuilder().getEntryObject().get("state").equal(State.STATE1);
Collection<Value> values = map.values(predicate);
int[] expectedValues = new int[] { 0, 2 };
assertEquals(expectedValues.length, values.size());
int[] indexes = new int[2];
int index = 0;
for (Value configObject : values) {
indexes[index++] = configObject.getIndex();
}
Arrays.sort(indexes);
assertArrayEquals(indexes, expectedValues);
}
Aggregations