Search in sources :

Example 31 with IndexSample

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

the class IndexingServiceTest method shouldLogIndexStateOutliersOnStart.

@Test
void shouldLogIndexStateOutliersOnStart() 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();
    List<IndexDescriptor> indexes = new ArrayList<>();
    int nextIndexId = 1;
    IndexDescriptor populatingIndex = storeIndex(nextIndexId, nextIndexId++, 1, PROVIDER_DESCRIPTOR);
    when(provider.getInitialState(eq(populatingIndex), any())).thenReturn(POPULATING);
    indexes.add(populatingIndex);
    IndexDescriptor failedIndex = storeIndex(nextIndexId, nextIndexId++, 1, PROVIDER_DESCRIPTOR);
    when(provider.getInitialState(eq(failedIndex), any())).thenReturn(FAILED);
    indexes.add(failedIndex);
    for (int i = 0; i < 10; i++) {
        IndexDescriptor indexRule = storeIndex(nextIndexId, nextIndexId++, 1, PROVIDER_DESCRIPTOR);
        when(provider.getInitialState(eq(indexRule), any())).thenReturn(ONLINE);
        indexes.add(indexRule);
    }
    for (int i = 0; i < nextIndexId; i++) {
        nameLookup.label(i, "Label" + i);
    }
    IndexingService indexingService = IndexingServiceFactory.createIndexingService(config, mock(JobScheduler.class), providerMap, storeViewFactory, nameLookup, indexes, internalLogProvider, userLogProvider, IndexingService.NO_MONITOR, schemaState, indexStatisticsStore, PageCacheTracer.NULL, INSTANCE, "", writable());
    when(indexStatisticsStore.indexSample(anyLong())).thenReturn(new IndexSample(100, 32, 32));
    nameLookup.propertyKey(1, "prop");
    // when
    indexingService.init();
    internalLogProvider.clear();
    indexingService.start();
    // then
    assertThat(internalLogProvider).forLevel(INFO).containsMessages("IndexingService.start: index 1 on (:Label1 {prop}) is POPULATING", "IndexingService.start: index 2 on (:Label2 {prop}) is FAILED", "IndexingService.start: indexes not specifically mentioned above are ONLINE").doesNotContainMessage("IndexingService.start: index 3 on :Label3(prop) is ONLINE");
}
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) ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 32 with IndexSample

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

the class IndexStatisticsStoreTest method shouldStoreDataOnCheckpoint.

@Test
void shouldStoreDataOnCheckpoint() throws IOException {
    // given
    long indexId1 = 1;
    long indexId2 = 2;
    IndexSample sample1 = new IndexSample(500, 100, 200, 25);
    IndexSample sample2 = new IndexSample(501, 101, 201, 26);
    store.replaceStats(indexId1, sample1);
    store.replaceStats(indexId2, sample2);
    // when
    restartStore();
    // then
    assertEquals(sample1, store.indexSample(indexId1));
    assertEquals(sample2, store.indexSample(indexId2));
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) Test(org.junit.jupiter.api.Test)

Example 33 with IndexSample

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

the class IndexStatisticsStoreTest method shouldAllowMultipleThreadsIncrementIndexUpdates.

@Test
void shouldAllowMultipleThreadsIncrementIndexUpdates() throws Throwable {
    // given
    long indexId = 5;
    Race race = new Race();
    int contestants = 20;
    int delta = 3;
    store.replaceStats(indexId, new IndexSample(0, 0, 0));
    race.addContestants(contestants, () -> store.incrementIndexUpdates(indexId, delta), 1);
    // when
    race.go();
    // then
    assertEquals(new IndexSample(0, 0, 0, contestants * delta), store.indexSample(indexId));
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) Race(org.neo4j.test.Race) Test(org.junit.jupiter.api.Test)

Example 34 with IndexSample

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

the class IndexStatisticsStoreTest method shouldReplaceIndexSample.

@Test
void shouldReplaceIndexSample() {
    // given
    long indexId = 4;
    // when/then
    replaceAndVerifySample(indexId, new IndexSample(456, 123, 456, 3));
    replaceAndVerifySample(indexId, new IndexSample(555, 444, 550, 0));
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) Test(org.junit.jupiter.api.Test)

Example 35 with IndexSample

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

the class IndexStatisticsStoreTest method shouldIncrementIndexUpdates.

@Test
void shouldIncrementIndexUpdates() {
    // given
    long indexId = 4;
    IndexSample initialSample = new IndexSample(456, 5, 200, 123);
    store.replaceStats(indexId, initialSample);
    // when
    int addedUpdates = 5;
    store.incrementIndexUpdates(indexId, addedUpdates);
    // then
    assertEquals(new IndexSample(initialSample.indexSize(), initialSample.uniqueValues(), initialSample.sampleSize(), initialSample.updates() + addedUpdates), store.indexSample(indexId));
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) Test(org.junit.jupiter.api.Test)

Aggregations

IndexSample (org.neo4j.kernel.api.index.IndexSample)56 Test (org.junit.jupiter.api.Test)43 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)14 CursorContext (org.neo4j.io.pagecache.context.CursorContext)13 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)10 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)8 IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)8 NodePropertyAccessor (org.neo4j.storageengine.api.NodePropertyAccessor)8 IndexProvider (org.neo4j.kernel.api.index.IndexProvider)7 IndexSampler (org.neo4j.kernel.api.index.IndexSampler)7 ArrayList (java.util.ArrayList)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Config (org.neo4j.configuration.Config)6 Transaction (org.neo4j.graphdb.Transaction)6 IOException (java.io.IOException)5 Path (java.nio.file.Path)4 Arrays.asList (java.util.Arrays.asList)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4