Search in sources :

Example 6 with QueryContext

use of com.hazelcast.query.impl.QueryContext in project hazelcast by hazelcast.

the class LikePredicateTest method likePredicateIsNotIndexed_whenPercentWildcardIsUsedAtTheBeginning.

@Test
public void likePredicateIsNotIndexed_whenPercentWildcardIsUsedAtTheBeginning() {
    QueryContext queryContext = mock(QueryContext.class);
    when(queryContext.matchIndex("this", QueryContext.IndexMatchHint.PREFER_ORDERED)).thenReturn(createIndex(IndexType.SORTED));
    assertFalse(new LikePredicate("this", "%string").isIndexed(queryContext));
}
Also used : QueryContext(com.hazelcast.query.impl.QueryContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with QueryContext

use of com.hazelcast.query.impl.QueryContext in project hazelcast by hazelcast.

the class LikePredicateTest method likePredicateIsNotIndexed_whenPercentWildcardIsNotTheLastSymbol.

@Test
public void likePredicateIsNotIndexed_whenPercentWildcardIsNotTheLastSymbol() {
    QueryContext queryContext = mock(QueryContext.class);
    when(queryContext.matchIndex("this", QueryContext.IndexMatchHint.PREFER_ORDERED)).thenReturn(createIndex(IndexType.SORTED));
    assertFalse(new LikePredicate("this", "sub%str").isIndexed(queryContext));
    assertFalse(new LikePredicate("this", "sub%   ").isIndexed(queryContext));
}
Also used : QueryContext(com.hazelcast.query.impl.QueryContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with QueryContext

use of com.hazelcast.query.impl.QueryContext in project hazelcast by hazelcast.

the class LikePredicateTest method likePredicateIsIndexed_whenPercentWildcardIsUsed_andIndexIsSorted.

@Test
public void likePredicateIsIndexed_whenPercentWildcardIsUsed_andIndexIsSorted() {
    QueryContext queryContext = mock(QueryContext.class);
    when(queryContext.matchIndex("this", QueryContext.IndexMatchHint.PREFER_ORDERED)).thenReturn(createIndex(IndexType.SORTED));
    assertTrue(new LikePredicate("this", "sub%").isIndexed(queryContext));
    assertTrue(new LikePredicate("this", "sub\\\\%").isIndexed(queryContext));
    assertTrue(new LikePredicate("this", "sub\\%string%").isIndexed(queryContext));
    assertTrue(new LikePredicate("this", "sub\\_string%").isIndexed(queryContext));
}
Also used : QueryContext(com.hazelcast.query.impl.QueryContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with QueryContext

use of com.hazelcast.query.impl.QueryContext in project hazelcast by hazelcast.

the class PredicatesTest method testNotEqualsPredicateDoesNotUseIndex.

@Test
public void testNotEqualsPredicateDoesNotUseIndex() {
    Index dummyIndex = new IndexImpl("foo", false, ss, Extractors.empty());
    QueryContext mockQueryContext = mock(QueryContext.class);
    when(mockQueryContext.getIndex(anyString())).thenReturn(dummyIndex);
    NotEqualPredicate p = new NotEqualPredicate("foo", "bar");
    boolean indexed = p.isIndexed(mockQueryContext);
    assertFalse(indexed);
}
Also used : IndexImpl(com.hazelcast.query.impl.IndexImpl) Index(com.hazelcast.query.impl.Index) QueryContext(com.hazelcast.query.impl.QueryContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with QueryContext

use of com.hazelcast.query.impl.QueryContext in project hazelcast by hazelcast.

the class NotEqualPredicateTest method filter_givenAttributeNameIsFoo_whenTheFooFieldIsIndex_thenReturnsNullAndDoesNotTouchQueryContext.

@Test
public void filter_givenAttributeNameIsFoo_whenTheFooFieldIsIndex_thenReturnsNullAndDoesNotTouchQueryContext() {
    /** see {@link #isIndexed_givenAttributeNameIsFoo_whenTheFooFieldIsIndexed_returnFalse()} */
    String fieldName = "foo";
    NotEqualPredicate predicate = new NotEqualPredicate(fieldName, "foo");
    QueryContext queryContext = newMockContextWithIndex(fieldName);
    Set<QueryableEntry> filter = predicate.filter(queryContext);
    assertNull(filter);
    verifyZeroInteractions(queryContext);
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) Matchers.containsString(org.hamcrest.Matchers.containsString) QueryContext(com.hazelcast.query.impl.QueryContext) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

QueryContext (com.hazelcast.query.impl.QueryContext)13 QuickTest (com.hazelcast.test.annotation.QuickTest)12 Test (org.junit.Test)12 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)8 Index (com.hazelcast.query.impl.Index)2 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Matchers.anyString (org.mockito.Matchers.anyString)2 PartitionMigrationEvent (com.hazelcast.internal.partition.PartitionMigrationEvent)1 Predicate (com.hazelcast.query.Predicate)1 IndexImpl (com.hazelcast.query.impl.IndexImpl)1 EqualPredicate (com.hazelcast.query.impl.predicates.EqualPredicate)1