Search in sources :

Example 1 with SKIP_PARTITIONS_COUNT_CHECK

use of com.hazelcast.query.impl.Indexes.SKIP_PARTITIONS_COUNT_CHECK in project hazelcast by hazelcast.

the class EvaluateVisitorTest method before.

@SuppressWarnings("SuspiciousMethodCalls")
@Before
public void before() {
    indexes = mock(Indexes.class);
    InternalIndex bitmapA = mock(InternalIndex.class);
    when(bitmapA.getConverter()).thenReturn(TypeConverters.INTEGER_CONVERTER);
    when(bitmapA.getName()).thenReturn("a");
    when(indexes.matchIndex(eq("a"), any(), eq(IndexMatchHint.EXACT_NAME), eq(SKIP_PARTITIONS_COUNT_CHECK))).then((Answer<InternalIndex>) invocation -> EVALUABLE_PREDICATES.contains(invocation.getArgument(1)) ? bitmapA : null);
    when(indexes.matchIndex(eq("a"), any(), eq(IndexMatchHint.PREFER_UNORDERED), eq(SKIP_PARTITIONS_COUNT_CHECK))).then((Answer<InternalIndex>) invocation -> EVALUABLE_PREDICATES.contains(invocation.getArgument(1)) ? bitmapA : null);
    InternalIndex bitmapB = mock(InternalIndex.class);
    when(bitmapB.getConverter()).thenReturn(TypeConverters.STRING_CONVERTER);
    when(bitmapB.getName()).thenReturn("b");
    when(indexes.matchIndex(eq("b"), any(), eq(IndexMatchHint.EXACT_NAME), eq(SKIP_PARTITIONS_COUNT_CHECK))).then((Answer<InternalIndex>) invocation -> EVALUABLE_PREDICATES.contains(invocation.getArgument(1)) ? bitmapB : null);
    when(indexes.matchIndex(eq("b"), any(), eq(IndexMatchHint.PREFER_UNORDERED), eq(SKIP_PARTITIONS_COUNT_CHECK))).then((Answer<InternalIndex>) invocation -> EVALUABLE_PREDICATES.contains(invocation.getArgument(1)) ? bitmapB : null);
    InternalIndex bitmapNoConverter = mock(InternalIndex.class);
    when(bitmapNoConverter.getName()).thenReturn("nc");
    when(bitmapNoConverter.getConverter()).thenReturn(null);
    when(indexes.matchIndex(eq("nc"), any(), eq(IndexMatchHint.EXACT_NAME), eq(SKIP_PARTITIONS_COUNT_CHECK))).then((Answer<InternalIndex>) invocation -> EVALUABLE_PREDICATES.contains(invocation.getArgument(1)) ? bitmapNoConverter : null);
    when(indexes.matchIndex(eq("nc"), any(), eq(IndexMatchHint.PREFER_UNORDERED), eq(SKIP_PARTITIONS_COUNT_CHECK))).then((Answer<InternalIndex>) invocation -> EVALUABLE_PREDICATES.contains(invocation.getArgument(1)) ? bitmapNoConverter : null);
    InternalIndex bitmapNoSubPredicates = mock(InternalIndex.class);
    when(bitmapNoSubPredicates.getName()).thenReturn("ns");
    when(bitmapNoSubPredicates.getConverter()).thenReturn(TypeConverters.INTEGER_CONVERTER);
    when(indexes.matchIndex(eq("ns"), any(), eq(IndexMatchHint.EXACT_NAME), eq(SKIP_PARTITIONS_COUNT_CHECK))).then((Answer<InternalIndex>) invocation -> {
        Object clazz = invocation.getArgument(1);
        if (clazz == AndPredicate.class || clazz == OrPredicate.class || clazz == NotPredicate.class) {
            return null;
        } else {
            return bitmapNoSubPredicates;
        }
    });
    when(indexes.matchIndex(eq("ns"), any(), eq(IndexMatchHint.PREFER_UNORDERED), eq(SKIP_PARTITIONS_COUNT_CHECK))).then((Answer<InternalIndex>) invocation -> {
        Object clazz = invocation.getArgument(1);
        if (clazz == AndPredicate.class || clazz == OrPredicate.class || clazz == NotPredicate.class) {
            return null;
        } else {
            return bitmapNoSubPredicates;
        }
    });
    visitor = new EvaluateVisitor();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Indexes(com.hazelcast.query.impl.Indexes) QuickTest(com.hazelcast.test.annotation.QuickTest) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RunWith(org.junit.runner.RunWith) Predicates.notEqual(com.hazelcast.query.Predicates.notEqual) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Assert.assertSame(org.junit.Assert.assertSame) Answer(org.mockito.stubbing.Answer) TypeConverters(com.hazelcast.query.impl.TypeConverters) SKIP_PARTITIONS_COUNT_CHECK(com.hazelcast.query.impl.Indexes.SKIP_PARTITIONS_COUNT_CHECK) Arrays.asList(java.util.Arrays.asList) Predicate(com.hazelcast.query.Predicate) Before(org.junit.Before) Predicates.in(com.hazelcast.query.Predicates.in) Predicates.not(com.hazelcast.query.Predicates.not) Predicates.and(com.hazelcast.query.Predicates.and) IndexMatchHint(com.hazelcast.query.impl.QueryContext.IndexMatchHint) Predicates.or(com.hazelcast.query.Predicates.or) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Predicates.alwaysFalse(com.hazelcast.query.Predicates.alwaysFalse) Mockito.when(org.mockito.Mockito.when) Category(org.junit.experimental.categories.Category) Predicates.equal(com.hazelcast.query.Predicates.equal) List(java.util.List) InternalIndex(com.hazelcast.query.impl.InternalIndex) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) Predicates.like(com.hazelcast.query.Predicates.like) CustomPredicate(com.hazelcast.query.impl.predicates.VisitorTestSupport.CustomPredicate) Mockito.mock(org.mockito.Mockito.mock) InternalIndex(com.hazelcast.query.impl.InternalIndex) Indexes(com.hazelcast.query.impl.Indexes) Before(org.junit.Before)

Aggregations

Predicate (com.hazelcast.query.Predicate)1 Predicates.alwaysFalse (com.hazelcast.query.Predicates.alwaysFalse)1 Predicates.and (com.hazelcast.query.Predicates.and)1 Predicates.equal (com.hazelcast.query.Predicates.equal)1 Predicates.in (com.hazelcast.query.Predicates.in)1 Predicates.like (com.hazelcast.query.Predicates.like)1 Predicates.not (com.hazelcast.query.Predicates.not)1 Predicates.notEqual (com.hazelcast.query.Predicates.notEqual)1 Predicates.or (com.hazelcast.query.Predicates.or)1 Indexes (com.hazelcast.query.impl.Indexes)1 SKIP_PARTITIONS_COUNT_CHECK (com.hazelcast.query.impl.Indexes.SKIP_PARTITIONS_COUNT_CHECK)1 InternalIndex (com.hazelcast.query.impl.InternalIndex)1 IndexMatchHint (com.hazelcast.query.impl.QueryContext.IndexMatchHint)1 TypeConverters (com.hazelcast.query.impl.TypeConverters)1 CustomPredicate (com.hazelcast.query.impl.predicates.VisitorTestSupport.CustomPredicate)1 HazelcastParallelClassRunner (com.hazelcast.test.HazelcastParallelClassRunner)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1