Search in sources :

Example 46 with Indexes

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

the class AndPredicateTest method accept_whenInnerPredicateChangedOnAccept_thenReturnAndNewAndPredicate.

@Test
public void accept_whenInnerPredicateChangedOnAccept_thenReturnAndNewAndPredicate() {
    Visitor mockVisitor = createPassthroughVisitor();
    Indexes mockIndexes = mock(Indexes.class);
    Predicate transformed = mock(Predicate.class);
    Predicate innerPredicate = createMockVisitablePredicate(transformed);
    Predicate[] innerPredicates = new Predicate[1];
    innerPredicates[0] = innerPredicate;
    AndPredicate andPredicate = new AndPredicate(innerPredicates);
    AndPredicate result = (AndPredicate) andPredicate.accept(mockVisitor, mockIndexes);
    assertThat(result, not(sameInstance(andPredicate)));
    Predicate[] newInnerPredicates = result.predicates;
    assertThat(newInnerPredicates, arrayWithSize(1));
    assertThat(newInnerPredicates[0], equalTo(transformed));
}
Also used : PredicateTestUtils.createPassthroughVisitor(com.hazelcast.query.impl.predicates.PredicateTestUtils.createPassthroughVisitor) PredicateTestUtils.createDelegatingVisitor(com.hazelcast.query.impl.predicates.PredicateTestUtils.createDelegatingVisitor) Indexes(com.hazelcast.query.impl.Indexes) PredicateTestUtils.createMockNegatablePredicate(com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockNegatablePredicate) PredicateTestUtils.createMockVisitablePredicate(com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate) Predicate(com.hazelcast.query.Predicate) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 47 with Indexes

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

the class CompositeIndexVisitorTest method before.

@Before
public void before() {
    indexes = mock(Indexes.class);
    o123 = mock(InternalIndex.class);
    when(o123.isOrdered()).thenReturn(true);
    when(o123.getComponents()).thenReturn(components("a1", "a2", "a3"));
    u321 = mock(InternalIndex.class);
    when(u321.isOrdered()).thenReturn(false);
    when(u321.getComponents()).thenReturn(components("a3", "a2", "a1"));
    o567 = mock(InternalIndex.class);
    when(o567.isOrdered()).thenReturn(true);
    when(o567.getComponents()).thenReturn(components("a5", "a6", "a7"));
    // needed to test the preference of shorter indexes over longer ones
    InternalIndex o1234 = mock(InternalIndex.class);
    when(o1234.isOrdered()).thenReturn(true);
    when(o1234.getComponents()).thenReturn(components("a1", "a2", "a3", "a4"));
    when(indexes.getCompositeIndexes()).thenReturn(new InternalIndex[] { o1234, o123, u321, o567 });
    visitor = new CompositeIndexVisitor();
}
Also used : InternalIndex(com.hazelcast.query.impl.InternalIndex) Indexes(com.hazelcast.query.impl.Indexes) Before(org.junit.Before)

Example 48 with Indexes

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

the class EmptyOptimizerTest method optimize_returnsOriginalPredicate.

@Test
public void optimize_returnsOriginalPredicate() {
    EmptyOptimizer emptyOptimizer = new EmptyOptimizer();
    Predicate predicate = mock(Predicate.class);
    Indexes indexes = mock(Indexes.class);
    Predicate result = emptyOptimizer.optimize(predicate, indexes);
    assertSame(predicate, result);
}
Also used : Indexes(com.hazelcast.query.impl.Indexes) Predicate(com.hazelcast.query.Predicate) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 49 with Indexes

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

the class NotPredicateTest method accept_whenNullPredicate_thenReturnItself.

@Test
public void accept_whenNullPredicate_thenReturnItself() {
    Visitor mockVisitor = createPassthroughVisitor();
    Indexes mockIndexes = mock(Indexes.class);
    NotPredicate notPredicate = new NotPredicate(null);
    NotPredicate result = (NotPredicate) notPredicate.accept(mockVisitor, mockIndexes);
    assertThat(result, sameInstance(notPredicate));
}
Also used : PredicateTestUtils.createPassthroughVisitor(com.hazelcast.query.impl.predicates.PredicateTestUtils.createPassthroughVisitor) Indexes(com.hazelcast.query.impl.Indexes) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 50 with Indexes

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

the class NotPredicateTest method accept_whenPredicateChangedOnAccept_thenReturnAndNewNotPredicate.

@Test
public void accept_whenPredicateChangedOnAccept_thenReturnAndNewNotPredicate() {
    Visitor mockVisitor = createPassthroughVisitor();
    Indexes mockIndexes = mock(Indexes.class);
    Predicate transformed = mock(Predicate.class);
    Predicate predicate = createMockVisitablePredicate(transformed);
    NotPredicate notPredicate = new NotPredicate(predicate);
    NotPredicate result = (NotPredicate) notPredicate.accept(mockVisitor, mockIndexes);
    assertThat(result, not(sameInstance(notPredicate)));
    assertThat(result.predicate, equalTo(transformed));
}
Also used : PredicateTestUtils.createPassthroughVisitor(com.hazelcast.query.impl.predicates.PredicateTestUtils.createPassthroughVisitor) Indexes(com.hazelcast.query.impl.Indexes) Predicate(com.hazelcast.query.Predicate) PredicateTestUtils.createMockVisitablePredicate(com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Indexes (com.hazelcast.query.impl.Indexes)56 MapContainer (com.hazelcast.map.impl.MapContainer)15 QuickTest (com.hazelcast.test.annotation.QuickTest)14 Test (org.junit.Test)14 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)13 Predicate (com.hazelcast.query.Predicate)11 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)11 InternalIndex (com.hazelcast.query.impl.InternalIndex)10 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)9 IndexConfig (com.hazelcast.config.IndexConfig)8 Record (com.hazelcast.map.impl.record.Record)8 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)7 MapService (com.hazelcast.map.impl.MapService)6 Data (com.hazelcast.nio.serialization.Data)6 ArrayList (java.util.ArrayList)6 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)5 PredicateTestUtils.createPassthroughVisitor (com.hazelcast.query.impl.predicates.PredicateTestUtils.createPassthroughVisitor)5 Index (com.hazelcast.query.impl.Index)4 Map (java.util.Map)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3