Search in sources :

Example 56 with Predicate

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));
}
Also used : PredicateTestUtils.createMockNegatablePredicate(com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockNegatablePredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 57 with Predicate

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));
        }
    }
}
Also used : Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 58 with Predicate

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));
}
Also used : Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 59 with Predicate

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)));
}
Also used : Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 60 with Predicate

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;
}
Also used : VisitablePredicate(com.hazelcast.query.VisitablePredicate) Predicate(com.hazelcast.query.Predicate) VisitablePredicate(com.hazelcast.query.VisitablePredicate)

Aggregations

Predicate (com.hazelcast.query.Predicate)160 Test (org.junit.Test)125 QuickTest (com.hazelcast.test.annotation.QuickTest)124 ParallelTest (com.hazelcast.test.annotation.ParallelTest)107 TruePredicate (com.hazelcast.query.TruePredicate)41 SqlPredicate (com.hazelcast.query.SqlPredicate)33 HazelcastInstance (com.hazelcast.core.HazelcastInstance)26 FalsePredicate (com.hazelcast.query.impl.FalsePredicate)23 PredicateBuilder (com.hazelcast.query.PredicateBuilder)19 EntryListener (com.hazelcast.core.EntryListener)16 MapListener (com.hazelcast.map.listener.MapListener)16 EntryObject (com.hazelcast.query.EntryObject)14 IndexAwarePredicate (com.hazelcast.query.IndexAwarePredicate)12 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)10 Value (com.hazelcast.query.SampleObjects.Value)9 PredicateTestUtils.createMockVisitablePredicate (com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate)9 ArrayList (java.util.ArrayList)9 EntryEvent (com.hazelcast.core.EntryEvent)8 MapListenerAdapter (com.hazelcast.map.impl.MapListenerAdapter)8 ValueType (com.hazelcast.query.SampleObjects.ValueType)7