Search in sources :

Example 51 with Indexes

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

the class AttributeCanonicalizationTest method testIndexes.

@Test
public void testIndexes() {
    Indexes indexes = Indexes.newBuilder(new DefaultSerializationServiceBuilder().build(), IndexCopyBehavior.NEVER, DEFAULT_IN_MEMORY_FORMAT).build();
    checkIndex(indexes, "foo", "foo");
    checkIndex(indexes, "this.foo", "foo");
    checkIndex(indexes, "this", "this");
    checkIndex(indexes, "foo.this.bar", "foo.this.bar");
    checkIndex(indexes, "this.foo.bar", "foo.bar");
    checkIndex(indexes, "foo.bar", "foo.bar");
    checkIndex(indexes, "__key", "__key");
    checkIndex(indexes, "__key.foo", "__key.foo");
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) Indexes(com.hazelcast.query.impl.Indexes) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 52 with Indexes

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

the class AbstractVisitorTest method testAllVisitMethodReturnTheOriginalPredicate.

@Test
public void testAllVisitMethodReturnTheOriginalPredicate() throws Exception {
    // Contract of AbstractVisitor mandates to return original predicate
    // for all methods on Visitor interface.
    // This test makes sure if a new method is added into Visitor interface
    // then it's added to AbstractVisitor and honour its contract
    AbstractVisitor visitor = new AbstractVisitor() {
    };
    Method[] methods = Visitor.class.getMethods();
    for (Method method : methods) {
        Class<?> predicateType = method.getParameterTypes()[0];
        Predicate predicate = (Predicate) predicateType.newInstance();
        Indexes indexes = mock(Indexes.class);
        Object result = method.invoke(visitor, predicate, indexes);
        assertSame("Method " + method + " does not return identity of the original predicate." + " See contract of " + AbstractVisitor.class.getSimpleName(), predicate, result);
    }
}
Also used : Method(java.lang.reflect.Method) 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 53 with Indexes

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

the class AttributeCanonicalizationTest method testCompositeIndexes.

@Test
public void testCompositeIndexes() {
    Indexes indexes = Indexes.newBuilder(new DefaultSerializationServiceBuilder().build(), IndexCopyBehavior.NEVER, DEFAULT_IN_MEMORY_FORMAT).build();
    checkIndex(indexes, new String[] { "foo", "bar" }, new String[] { "foo", "bar" });
    checkIndex(indexes, new String[] { "this.foo", "bar" }, new String[] { "foo", "bar" });
    checkIndex(indexes, new String[] { "this", "__key" }, new String[] { "this", "__key" });
    checkIndex(indexes, new String[] { "foo", "bar.this.baz" }, new String[] { "foo", "bar.this.baz" });
    checkIndex(indexes, new String[] { "this.foo", "bar.this.baz" }, new String[] { "foo", "bar.this.baz" });
    checkIndex(indexes, new String[] { "foo.bar", "baz" }, new String[] { "foo.bar", "baz" });
    checkIndex(indexes, new String[] { "foo", "this.bar", "__key.baz" }, new String[] { "foo", "bar", "__key.baz" });
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) Indexes(com.hazelcast.query.impl.Indexes) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 54 with Indexes

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

the class IndexCreateTest method checkIndex.

private void checkIndex(IndexConfig... indexConfigs) {
    List<HazelcastInstanceProxy> members = handler.initialize(hazelcastFactory, indexConfigs);
    for (HazelcastInstanceProxy member : members) {
        MapService service = member.getOriginal().node.nodeEngine.getService(MapService.SERVICE_NAME);
        MapServiceContext mapServiceContext = service.getMapServiceContext();
        MapContainer mapContainer = mapServiceContext.getMapContainer(MAP_NAME);
        Indexes indexes = mapContainer.getIndexes();
        assertEquals(indexConfigs.length, indexes.getIndexes().length);
        for (IndexConfig indexConfig : indexConfigs) {
            String expectedName = getExpectedName(indexConfig);
            InternalIndex index = indexes.getIndex(expectedName);
            assertNotNull("Index not found: " + expectedName, index);
            assertEquals(type == IndexType.SORTED, index.isOrdered());
            assertEquals(type, index.getConfig().getType());
            assertEquals(indexConfig.getAttributes().size(), index.getComponents().length);
            for (int i = 0; i < indexConfig.getAttributes().size(); i++) {
                String expAttributeName = indexConfig.getAttributes().get(i);
                String componentName = index.getComponents()[i];
                assertEquals(IndexUtils.canonicalizeAttribute(expAttributeName), componentName);
            }
        }
    }
}
Also used : InternalIndex(com.hazelcast.query.impl.InternalIndex) IndexConfig(com.hazelcast.config.IndexConfig) MapService(com.hazelcast.map.impl.MapService) Indexes(com.hazelcast.query.impl.Indexes) HazelcastInstanceProxy(com.hazelcast.instance.impl.HazelcastInstanceProxy) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 55 with Indexes

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

the class SingleValueBitmapIndexTest method testClearedIndexes.

@Test
public void testClearedIndexes() {
    for (int i = BATCH_COUNT - 1; i >= 0; --i) {
        for (long j = 0; j < BATCH_SIZE; ++j) {
            long id = i * BATCH_SIZE + j;
            put(id, (int) id);
        }
        verifyQueries();
    }
    for (HazelcastInstance instance : factory.getAllHazelcastInstances()) {
        HazelcastInstanceImpl instanceImpl = (HazelcastInstanceImpl) instance;
        MapService mapService = instanceImpl.node.getNodeEngine().getService(MapService.SERVICE_NAME);
        Indexes indexes = mapService.getMapServiceContext().getMapContainer(persons.getName()).getIndexes();
        indexes.clearAll();
        for (Partition partition : instanceImpl.getPartitionService().getPartitions()) {
            if (partition.getOwner().localMember()) {
                Indexes.beginPartitionUpdate(indexes.getIndexes());
                Indexes.markPartitionAsIndexed(partition.getPartitionId(), indexes.getIndexes());
            }
        }
    }
    for (ExpectedQuery expectedQuery : expectedQueries) {
        expectedQuery.clear();
    }
    // Repopulate the index and run queries. Technically, we are doing index
    // updates here instead of inserts since the map is still populated, but
    // the index interprets them as inserts.
    persons.getLocalMapStats().getIndexStats();
    for (int i = BATCH_COUNT - 1; i >= 0; --i) {
        for (long j = 0; j < BATCH_SIZE; ++j) {
            long id = i * BATCH_SIZE + j;
            put(id, (int) id);
        }
        verifyQueries();
    }
    LocalIndexStats statsA = personsA.getLocalMapStats().getIndexStats().values().iterator().next();
    LocalIndexStats statsB = personsB.getLocalMapStats().getIndexStats().values().iterator().next();
    assertEquals(BATCH_COUNT * BATCH_SIZE, statsA.getInsertCount() + statsB.getInsertCount());
    assertEquals(BATCH_COUNT * BATCH_SIZE, statsA.getUpdateCount() + statsB.getUpdateCount());
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.impl.HazelcastInstanceImpl) Partition(com.hazelcast.partition.Partition) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapService(com.hazelcast.map.impl.MapService) Indexes(com.hazelcast.query.impl.Indexes) LocalIndexStats(com.hazelcast.query.LocalIndexStats) 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