Search in sources :

Example 21 with IndexProvider

use of org.neo4j.kernel.api.index.IndexProvider in project neo4j by neo4j.

the class IndexingServiceTest method mockIndexProvider.

private static IndexProvider mockIndexProvider(IndexProviderDescriptor descriptor) {
    IndexProvider provider = mock(IndexProvider.class);
    when(provider.getProviderDescriptor()).thenReturn(descriptor);
    return provider;
}
Also used : IndexProvider(org.neo4j.kernel.api.index.IndexProvider)

Example 22 with IndexProvider

use of org.neo4j.kernel.api.index.IndexProvider in project neo4j by neo4j.

the class IndexingServiceTest method shouldLogIndexStateOnInit.

@Test
void shouldLogIndexStateOnInit() throws Exception {
    // given
    IndexProvider provider = mockIndexProviderWithAccessor(PROVIDER_DESCRIPTOR);
    Config config = Config.defaults(default_schema_provider, PROVIDER_DESCRIPTOR.name());
    IndexProviderMap providerMap = life.add(new DefaultIndexProviderMap(buildIndexDependencies(provider, fulltextProvider()), config));
    IndexDescriptor onlineIndex = storeIndex(1, 1, 1, PROVIDER_DESCRIPTOR);
    IndexDescriptor populatingIndex = storeIndex(2, 1, 2, PROVIDER_DESCRIPTOR);
    IndexDescriptor failedIndex = storeIndex(3, 2, 2, PROVIDER_DESCRIPTOR);
    life.add(IndexingServiceFactory.createIndexingService(config, mock(JobScheduler.class), providerMap, mock(IndexStoreViewFactory.class), nameLookup, asList(onlineIndex, populatingIndex, failedIndex), internalLogProvider, userLogProvider, IndexingService.NO_MONITOR, schemaState, indexStatisticsStore, PageCacheTracer.NULL, INSTANCE, "", writable()));
    when(provider.getInitialState(eq(onlineIndex), any())).thenReturn(ONLINE);
    when(provider.getInitialState(eq(populatingIndex), any())).thenReturn(POPULATING);
    when(provider.getInitialState(eq(failedIndex), any())).thenReturn(FAILED);
    nameLookup.label(1, "LabelOne");
    nameLookup.label(2, "LabelTwo");
    nameLookup.propertyKey(1, "propertyOne");
    nameLookup.propertyKey(2, "propertyTwo");
    // when
    life.init();
    // then
    assertThat(internalLogProvider).forLevel(DEBUG).containsMessages("IndexingService.init: index 1 on (:LabelOne {propertyOne}) is ONLINE", "IndexingService.init: index 2 on (:LabelOne {propertyTwo}) is POPULATING", "IndexingService.init: index 3 on (:LabelTwo {propertyTwo}) is FAILED");
}
Also used : IndexProvider(org.neo4j.kernel.api.index.IndexProvider) DefaultIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultIndexProviderMap) Config(org.neo4j.configuration.Config) IndexConfig(org.neo4j.internal.schema.IndexConfig) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) DefaultIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultIndexProviderMap) Test(org.junit.jupiter.api.Test)

Example 23 with IndexProvider

use of org.neo4j.kernel.api.index.IndexProvider in project neo4j by neo4j.

the class IndexingServiceTest method shouldLogDeprecatedIndexesOnStart.

@Test
void shouldLogDeprecatedIndexesOnStart() throws Exception {
    // given two indexes per available index provider
    int id = 1;
    List<IndexDescriptor> indexDescriptors = new ArrayList<>();
    IndexProvider[] indexProviders = new IndexProvider[indexProviderDescriptors.length];
    for (int i = 0; i < indexProviderDescriptors.length; i++) {
        IndexProviderDescriptor indexProviderDescriptor = indexProviderDescriptors[i];
        IndexProvider indexProvider = mockIndexProviderWithAccessor(indexProviderDescriptor);
        indexProviders[i] = indexProvider;
        // Two indexes per provider
        for (int j = 0; j < 2; j++) {
            IndexDescriptor index = storeIndex(id, 1, id, indexProviderDescriptor);
            indexDescriptors.add(index);
            when(indexProvider.getInitialState(eq(index), any())).thenReturn(ONLINE);
            id++;
        }
    }
    Config config = Config.defaults(default_schema_provider, nativeBtree10Descriptor.name());
    DependencyResolver dependencies = buildIndexDependencies(indexProviders);
    DefaultIndexProviderMap providerMap = new DefaultIndexProviderMap(dependencies, config);
    providerMap.init();
    when(indexStatisticsStore.indexSample(anyLong())).thenReturn(new IndexSample(1, 1, 1));
    IndexingService indexingService = IndexingServiceFactory.createIndexingService(config, mock(JobScheduler.class), providerMap, storeViewFactory, nameLookup, indexDescriptors, internalLogProvider, userLogProvider, IndexingService.NO_MONITOR, schemaState, indexStatisticsStore, PageCacheTracer.NULL, INSTANCE, "", writable());
    // when starting IndexingService
    indexingService.init();
    for (IndexProviderDescriptor indexProviderDescriptor : indexProviderDescriptors) {
        onBothLogProviders(logProvider -> assertThat(logProvider).doesNotContainMessage(indexProviderDescriptor.name()));
    }
    userLogProvider.clear();
    indexingService.start();
    // then we should see log messages about deprecated providers if any
    for (IndexProviderDescriptor indexProviderDescriptor : indexProviderDescriptors) {
        if (isDeprecated(indexProviderDescriptor)) {
            assertThat(userLogProvider).containsMessages("Deprecated index providers in use:", indexProviderDescriptor.name() + " (2 indexes)", "Use procedure 'db.indexes()' to see what indexes use which index provider.");
        } else {
            onBothLogProviders(logProvider -> assertThat(logProvider).doesNotContainMessage(indexProviderDescriptor.name()));
        }
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) Config(org.neo4j.configuration.Config) IndexConfig(org.neo4j.internal.schema.IndexConfig) ArrayList(java.util.ArrayList) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) DependencyResolver(org.neo4j.common.DependencyResolver) IndexProvider(org.neo4j.kernel.api.index.IndexProvider) DefaultIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultIndexProviderMap) IndexSample(org.neo4j.kernel.api.index.IndexSample) Test(org.junit.jupiter.api.Test)

Example 24 with IndexProvider

use of org.neo4j.kernel.api.index.IndexProvider in project neo4j by neo4j.

the class IndexingServiceTest method mockIndexProviderWithAccessor.

private static IndexProvider mockIndexProviderWithAccessor(IndexProviderDescriptor descriptor) throws IOException {
    IndexProvider provider = mockIndexProvider(descriptor);
    IndexAccessor indexAccessor = mock(IndexAccessor.class);
    when(provider.getOnlineAccessor(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(TokenNameLookup.class))).thenReturn(indexAccessor);
    return provider;
}
Also used : IndexProvider(org.neo4j.kernel.api.index.IndexProvider) TokenNameLookup(org.neo4j.common.TokenNameLookup) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 25 with IndexProvider

use of org.neo4j.kernel.api.index.IndexProvider in project neo4j by neo4j.

the class IndexingServiceTest method shouldLogIndexStateOnStart.

@Test
void shouldLogIndexStateOnStart() throws Throwable {
    // given
    IndexProvider provider = mockIndexProviderWithAccessor(PROVIDER_DESCRIPTOR);
    Config config = Config.defaults(default_schema_provider, PROVIDER_DESCRIPTOR.name());
    DefaultIndexProviderMap providerMap = new DefaultIndexProviderMap(buildIndexDependencies(provider, fulltextProvider()), config);
    providerMap.init();
    IndexDescriptor onlineIndex = storeIndex(1, 1, 1, PROVIDER_DESCRIPTOR);
    IndexDescriptor populatingIndex = storeIndex(2, 1, 2, PROVIDER_DESCRIPTOR);
    IndexDescriptor failedIndex = storeIndex(3, 2, 2, PROVIDER_DESCRIPTOR);
    IndexingService indexingService = IndexingServiceFactory.createIndexingService(config, mock(JobScheduler.class), providerMap, storeViewFactory, nameLookup, asList(onlineIndex, populatingIndex, failedIndex), internalLogProvider, userLogProvider, IndexingService.NO_MONITOR, schemaState, indexStatisticsStore, PageCacheTracer.NULL, INSTANCE, "", writable());
    when(provider.getInitialState(eq(onlineIndex), any())).thenReturn(ONLINE);
    when(provider.getInitialState(eq(populatingIndex), any())).thenReturn(POPULATING);
    when(provider.getInitialState(eq(failedIndex), any())).thenReturn(FAILED);
    indexingService.init();
    nameLookup.label(1, "LabelOne");
    nameLookup.label(2, "LabelTwo");
    nameLookup.propertyKey(1, "propertyOne");
    nameLookup.propertyKey(2, "propertyTwo");
    when(indexStatisticsStore.indexSample(anyLong())).thenReturn(new IndexSample(100L, 32L, 32L));
    internalLogProvider.clear();
    // when
    indexingService.start();
    // then
    verify(provider).getPopulationFailure(eq(failedIndex), any());
    assertThat(internalLogProvider).forLevel(DEBUG).containsMessages("IndexingService.start: index 1 on (:LabelOne {propertyOne}) is ONLINE", "IndexingService.start: index 2 on (:LabelOne {propertyTwo}) is POPULATING", "IndexingService.start: index 3 on (:LabelTwo {propertyTwo}) is FAILED");
}
Also used : IndexProvider(org.neo4j.kernel.api.index.IndexProvider) DefaultIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultIndexProviderMap) JobScheduler(org.neo4j.scheduler.JobScheduler) IndexSample(org.neo4j.kernel.api.index.IndexSample) Config(org.neo4j.configuration.Config) IndexConfig(org.neo4j.internal.schema.IndexConfig) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

IndexProvider (org.neo4j.kernel.api.index.IndexProvider)40 Test (org.junit.jupiter.api.Test)23 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)17 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)14 ArrayList (java.util.ArrayList)9 Config (org.neo4j.configuration.Config)9 GenericNativeIndexProvider (org.neo4j.kernel.impl.index.schema.GenericNativeIndexProvider)7 DefaultIndexProviderMap (org.neo4j.kernel.impl.transaction.state.DefaultIndexProviderMap)7 CursorContext (org.neo4j.io.pagecache.context.CursorContext)6 IndexSample (org.neo4j.kernel.api.index.IndexSample)6 TokenNameLookup (org.neo4j.common.TokenNameLookup)5 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)5 TokenIndexProvider (org.neo4j.kernel.impl.index.schema.TokenIndexProvider)5 JobScheduler (org.neo4j.scheduler.JobScheduler)5 IOException (java.io.IOException)4 String.format (java.lang.String.format)4 Arrays (java.util.Arrays)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4