use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class OrPredicateTest method negate_whenContainsNegatablePredicate_thenReturnAndPredicateWithNegationInside.
@Test
public void negate_whenContainsNegatablePredicate_thenReturnAndPredicateWithNegationInside() {
// ~(foo or bar) --> (~foo and ~bar)
// this is testing the case where the inner predicate implements {@link Negatable}
Predicate negated = mock(Predicate.class);
Predicate negatable = createMockNegatablePredicate(negated);
OrPredicate or = (OrPredicate) or(negatable);
AndPredicate result = (AndPredicate) or.negate();
Predicate[] inners = result.predicates;
assertThat(inners, arrayWithSize(1));
assertThat(inners, arrayContainingInAnyOrder(negated));
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class OrToInVisitorTest method whenThresholdExceeded_thenRewriteToOrPredicate.
@Test
public void whenThresholdExceeded_thenRewriteToOrPredicate() {
// (age = 1 or age = 2 or age = 3 or age = 4 or age = 5 or age != 6) --> (age in (1, 2, 3, 4, 5) or age != 6)
Predicate p1 = equal("age", 1);
Predicate p2 = equal("age", 2);
Predicate p3 = equal("age", 3);
Predicate p4 = equal("age", 4);
Predicate p5 = equal("age", 5);
Predicate p6 = notEqual("age", 6);
OrPredicate or = (OrPredicate) or(p1, p2, p3, p4, p5, p6);
OrPredicate result = (OrPredicate) visitor.visit(or, mockIndexes);
Predicate[] predicates = result.predicates;
for (Predicate predicate : predicates) {
if (predicate instanceof InPredicate) {
Comparable[] values = ((InPredicate) predicate).values;
assertThat(values, arrayWithSize(5));
assertThat(values, Matchers.is(Matchers.<Comparable>arrayContainingInAnyOrder(1, 2, 3, 4, 5)));
} else {
assertThat(predicate, instanceOf(NotEqualPredicate.class));
}
}
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class OrToInVisitorTest method whenThresholdNotExceeded_thenReturnItself.
@Test
public void whenThresholdNotExceeded_thenReturnItself() {
Predicate p1 = equal("age", 1);
Predicate p2 = equal("age", 2);
OrPredicate or = (OrPredicate) or(p1, p2);
OrPredicate result = (OrPredicate) visitor.visit(or, mockIndexes);
assertThat(or, equalTo(result));
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class OrToInVisitorTest method whenThresholdExceeded_thenRewriteToInPredicate.
@Test
public void whenThresholdExceeded_thenRewriteToInPredicate() {
// (age = 1 or age = 2 or age = 3 or age = 4 or age = 5) --> (age in (1, 2, 3, 4, 5))
Predicate p1 = equal("age", 1);
Predicate p2 = equal("age", 2);
Predicate p3 = equal("age", 3);
Predicate p4 = equal("age", 4);
Predicate p5 = equal("age", 5);
OrPredicate or = (OrPredicate) or(p1, p2, p3, p4, p5);
InPredicate result = (InPredicate) visitor.visit(or, mockIndexes);
Comparable[] values = result.values;
assertThat(values, arrayWithSize(5));
assertThat(values, Matchers.is(Matchers.<Comparable>arrayContainingInAnyOrder(1, 2, 3, 4, 5)));
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class PredicateTestUtils method createMockVisitablePredicate.
static Predicate createMockVisitablePredicate() {
VisitablePredicate visitablePredicate = mock(VisitablePredicate.class, withSettings().extraInterfaces(Predicate.class));
when(visitablePredicate.accept((Visitor) anyObject(), (Indexes) anyObject())).thenReturn((Predicate) visitablePredicate);
return (Predicate) visitablePredicate;
}
Aggregations