Search in sources :

Example 11 with QueryContext

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

the class QueryRunnerTest method verifyIndexedQueryFailureWhileMigratingInFlight.

@Test
public void verifyIndexedQueryFailureWhileMigratingInFlight() {
    map.addIndex(IndexType.HASH, "this");
    Predicate predicate = new EqualPredicate("this", value) {

        @Override
        public Set<QueryableEntry> filter(QueryContext queryContext) {
            // start a new migration while executing an indexed query
            mapService.beforeMigration(new PartitionMigrationEvent(MigrationEndpoint.SOURCE, partitionId, 0, 1, UUID.randomUUID()));
            return super.filter(queryContext);
        }
    };
    Query query = Query.of().mapName(map.getName()).predicate(predicate).iterationType(IterationType.ENTRY).partitionIdSet(SetUtil.allPartitionIds(instance.getPartitionService().getPartitions().size())).build();
    QueryResult result = (QueryResult) queryRunner.runIndexOrPartitionScanQueryOnOwnedPartitions(query);
    assertNull(result.getPartitionIds());
}
Also used : EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) PartitionMigrationEvent(com.hazelcast.internal.partition.PartitionMigrationEvent) QueryContext(com.hazelcast.query.impl.QueryContext) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with QueryContext

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

the class LikePredicateTest method likePredicateIsNotIndexed_whenPercentWildcardIsEscaped.

@Test
public void likePredicateIsNotIndexed_whenPercentWildcardIsEscaped() {
    QueryContext queryContext = mock(QueryContext.class);
    when(queryContext.matchIndex("this", QueryContext.IndexMatchHint.PREFER_ORDERED)).thenReturn(createIndex(IndexType.SORTED));
    assertFalse(new LikePredicate("this", "sub\\%").isIndexed(queryContext));
    assertFalse(new LikePredicate("this", "sub\\\\\\%").isIndexed(queryContext));
    assertFalse(new LikePredicate("this", "sub\\%string\\%").isIndexed(queryContext));
    assertFalse(new LikePredicate("this", "sub\\str\\%").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 13 with QueryContext

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

the class LikePredicateTest method likePredicateIsNotIndexed_whenUnderscoreWildcardIsUsed.

@Test
public void likePredicateIsNotIndexed_whenUnderscoreWildcardIsUsed() {
    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)

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