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;
}
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");
}
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()));
}
}
}
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;
}
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");
}
Aggregations