Search in sources :

Example 26 with IndexPrototype

use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.

the class IndexingServiceTest method shouldCreateMultipleIndexesInOneCall.

@Test
void shouldCreateMultipleIndexesInOneCall() throws Exception {
    // GIVEN
    IndexingService.Monitor monitor = IndexingService.NO_MONITOR;
    IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, accessor, withData(addNodeUpdate(0, "value", 1)), monitor);
    life.start();
    // WHEN
    IndexDescriptor index1 = storeIndex(0, 0, 0, PROVIDER_DESCRIPTOR);
    IndexDescriptor index2 = storeIndex(1, 0, 1, PROVIDER_DESCRIPTOR);
    IndexDescriptor index3 = storeIndex(2, 1, 0, PROVIDER_DESCRIPTOR);
    indexing.createIndexes(AUTH_DISABLED, index1, index2, index3);
    // THEN
    IndexPrototype prototype = forSchema(forLabel(0, 0)).withIndexProvider(PROVIDER_DESCRIPTOR);
    verify(indexProvider).getPopulator(eq(prototype.withName("index_0").materialise(0)), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class));
    verify(indexProvider).getPopulator(eq(prototype.withSchemaDescriptor(forLabel(0, 1)).withName("index_1").materialise(1)), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class));
    verify(indexProvider).getPopulator(eq(prototype.withSchemaDescriptor(forLabel(1, 0)).withName("index_2").materialise(2)), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class));
    waitForIndexesToComeOnline(indexing, index1, index2, index3);
}
Also used : TokenNameLookup(org.neo4j.common.TokenNameLookup) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 27 with IndexPrototype

use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.

the class IndexingServiceTest method shouldLogTriggerSamplingOnAnIndexes.

@Test
void shouldLogTriggerSamplingOnAnIndexes() throws Exception {
    // given
    long indexId = 0;
    IndexSamplingMode mode = backgroundRebuildAll();
    IndexPrototype prototype = forSchema(forLabel(0, 1)).withIndexProvider(PROVIDER_DESCRIPTOR).withName("index");
    IndexDescriptor index = prototype.materialise(indexId);
    when(accessor.newValueReader()).thenReturn(ValueIndexReader.EMPTY);
    IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData(), index);
    life.init();
    life.start();
    // when
    indexingService.triggerIndexSampling(index, mode);
    // then
    String userDescription = index.userDescription(nameLookup);
    assertThat(internalLogProvider).forLevel(INFO).containsMessages("Manual trigger for sampling index " + userDescription + " [" + mode + "]");
}
Also used : IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexSamplingMode(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 28 with IndexPrototype

use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.

the class ConstraintIndexCreatorTest method shouldCreateConstraintIndexForSpecifiedProvider.

@Test
void shouldCreateConstraintIndexForSpecifiedProvider() throws Exception {
    // given
    IndexingService indexingService = mock(IndexingService.class);
    IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("Groovy", "1.2");
    IndexPrototype prototype = this.prototype.withIndexProvider(providerDescriptor);
    IndexDescriptor index = prototype.materialise(this.index.getId());
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
    when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX);
    // when
    KernelTransactionImplementation transaction = createTransaction();
    creator.createUniquenessConstraintIndex(transaction, constraint, prototype);
    // then
    assertEquals(1, kernel.transactions.size());
    KernelTransactionImplementation transactionInstance = kernel.transactions.get(0);
    verify(transactionInstance).indexUniqueCreate(prototype);
    verify(schemaRead).indexGetForName(constraint.getName());
    verifyNoMoreInteractions(schemaRead);
}
Also used : ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 29 with IndexPrototype

use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.

the class SchemaRuleSerialization35 method readIndexRule.

// PRIVATE
// READ INDEX
private static IndexDescriptor readIndexRule(long id, ByteBuffer source) throws MalformedSchemaRuleException {
    String providerKey = getDecodedStringFrom(source);
    String providerVersion = getDecodedStringFrom(source);
    IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor(providerKey, providerVersion);
    byte indexRuleType = source.get();
    Optional<String> name;
    switch(indexRuleType) {
        case GENERAL_INDEX:
            {
                SchemaDescriptor schema = readSchema(source);
                name = readRuleName(source);
                IndexPrototype prototype = IndexPrototype.forSchema(schema, providerDescriptor);
                if (schema.isFulltextSchemaDescriptor()) {
                    prototype = prototype.withIndexType(IndexType.FULLTEXT);
                }
                if (name.isPresent()) {
                    prototype = prototype.withName(name.get());
                } else {
                    prototype = prototype.withName(defaultIndexName(id));
                }
                return prototype.materialise(id);
            }
        case UNIQUE_INDEX:
            {
                long readOwningConstraint = source.getLong();
                SchemaDescriptor schema = readSchema(source);
                name = readRuleName(source);
                IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema, providerDescriptor);
                if (name.isPresent()) {
                    prototype = prototype.withName(name.get());
                } else {
                    prototype = prototype.withName(defaultIndexName(id));
                }
                IndexDescriptor index = prototype.materialise(id);
                if (readOwningConstraint != NO_OWNING_CONSTRAINT_YET) {
                    index = index.withOwningConstraintId(readOwningConstraint);
                }
                return index;
            }
        default:
            throw new MalformedSchemaRuleException(format("Got unknown index rule type '%d'.", indexRuleType));
    }
}
Also used : LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) MalformedSchemaRuleException(org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 30 with IndexPrototype

use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.

the class DefaultPooledCursorsTestBase method shouldReuseRelationshipIndexCursors.

@Test
void shouldReuseRelationshipIndexCursors() throws Exception {
    // given
    int connection;
    int name;
    String indexName = "myIndex";
    IndexDescriptor index;
    try (KernelTransaction tx = beginTransaction()) {
        connection = tx.tokenWrite().relationshipTypeGetOrCreateForName("Connection");
        name = tx.tokenWrite().propertyKeyGetOrCreateForName("name");
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        SchemaDescriptor schema = SchemaDescriptor.fulltext(EntityType.RELATIONSHIP, array(connection), array(name));
        IndexPrototype prototype = IndexPrototype.forSchema(schema, DESCRIPTOR).withName(indexName).withIndexType(IndexType.FULLTEXT);
        index = tx.schemaWrite().indexCreate(prototype);
        tx.commit();
    }
    Predicates.awaitEx(() -> tx.schemaRead().indexGetState(index) == ONLINE, 1, MINUTES);
    RelationshipValueIndexCursor c1 = cursors.allocateRelationshipValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
    IndexReadSession indexSession = tx.dataRead().indexReadSession(index);
    read.relationshipIndexSeek(indexSession, c1, IndexQueryConstraints.unconstrained(), PropertyIndexQuery.fulltextSearch("hello"));
    c1.close();
    RelationshipValueIndexCursor c2 = cursors.allocateRelationshipValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
    assertThat(c1).isSameAs(c2);
    c2.close();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) RelationshipValueIndexCursor(org.neo4j.internal.kernel.api.RelationshipValueIndexCursor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Aggregations

IndexPrototype (org.neo4j.internal.schema.IndexPrototype)45 Test (org.junit.jupiter.api.Test)25 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)24 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)16 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)9 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)8 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)7 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)7 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)7 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)5 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)3 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)3 NamedToken (org.neo4j.token.api.NamedToken)3 KernelException (org.neo4j.exceptions.KernelException)2 Transaction (org.neo4j.graphdb.Transaction)2 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)2 RelationshipValueIndexCursor (org.neo4j.internal.kernel.api.RelationshipValueIndexCursor)2 IndexConfig (org.neo4j.internal.schema.IndexConfig)2 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)2