Search in sources :

Example 1 with IndexDescriptor

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

the class IndexingServiceIntegrationTest method dropIndexDirectlyOnIndexingServiceRaceWithCheckpoint.

@ParameterizedTest
@MethodSource("parameters")
void dropIndexDirectlyOnIndexingServiceRaceWithCheckpoint(GraphDatabaseSettings.SchemaIndex schemaIndex) throws Throwable {
    setUp(schemaIndex);
    IndexingService indexingService = getIndexingService(database);
    CheckPointer checkPointer = getCheckPointer(database);
    IndexDescriptor indexDescriptor;
    try (Transaction tx = database.beginTx()) {
        IndexDefinitionImpl indexDefinition = (IndexDefinitionImpl) tx.schema().indexFor(Label.label("label")).on("prop").create();
        indexDescriptor = indexDefinition.getIndexReference();
        tx.commit();
    }
    try (Transaction tx = database.beginTx()) {
        tx.schema().awaitIndexesOnline(1, TimeUnit.HOURS);
        tx.commit();
    }
    Race race = new Race();
    race.addContestant(Race.throwing(() -> checkPointer.forceCheckPoint(new SimpleTriggerInfo("Test force"))));
    race.addContestant(Race.throwing(() -> indexingService.dropIndex(indexDescriptor)));
    race.go();
}
Also used : SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Race(org.neo4j.test.Race) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexDefinitionImpl(org.neo4j.kernel.impl.coreapi.schema.IndexDefinitionImpl) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with IndexDescriptor

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

the class LuceneFulltextIndexTest method completeConfigurationMustNotOverwriteExistingConfiguration.

@Test
void completeConfigurationMustNotOverwriteExistingConfiguration() {
    IndexConfig indexConfig = IndexConfig.with("A", Values.stringValue("B"));
    FulltextSchemaDescriptor schema = SchemaDescriptor.fulltext(NODE, new int[] { 1 }, new int[] { 1 });
    IndexProviderDescriptor providerDescriptor = indexProvider.getProviderDescriptor();
    IndexDescriptor descriptor = indexProvider.completeConfiguration(IndexPrototype.forSchema(schema, providerDescriptor).withName("index_1").materialise(1)).withIndexConfig(indexConfig);
    assertEquals(Values.stringValue("B"), descriptor.getIndexConfig().get("A"));
}
Also used : IndexConfig(org.neo4j.internal.schema.IndexConfig) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) FulltextSchemaDescriptor(org.neo4j.internal.schema.FulltextSchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 3 with IndexDescriptor

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

the class LuceneFulltextIndexTest method completeConfigurationMustInjectMissingConfigurations.

@Test
void completeConfigurationMustInjectMissingConfigurations() throws Exception {
    int label;
    int propertyKey;
    try (Transaction tx = db.beginTx()) {
        createNodeIndexableByPropertyValue(tx, LABEL, "bla");
        tx.commit();
    }
    try (KernelTransactionImplementation tx = getKernelTransaction()) {
        label = tx.tokenRead().nodeLabel(LABEL.name());
        propertyKey = tx.tokenRead().propertyKey(PROP);
        tx.success();
    }
    IndexConfig indexConfig = IndexConfig.with(EVENTUALLY_CONSISTENT, Values.booleanValue(true));
    FulltextSchemaDescriptor schema = SchemaDescriptor.fulltext(NODE, new int[] { label }, new int[] { propertyKey });
    IndexProviderDescriptor providerDescriptor = indexProvider.getProviderDescriptor();
    IndexDescriptor descriptor = indexProvider.completeConfiguration(IndexPrototype.forSchema(schema, providerDescriptor).withName("index_1").withIndexConfig(indexConfig).materialise(1));
    assertThat((Value) descriptor.getIndexConfig().get(ANALYZER)).isEqualTo(Values.stringValue("standard-no-stop-words"));
    assertThat((Value) descriptor.getIndexConfig().get(EVENTUALLY_CONSISTENT)).isEqualTo(Values.booleanValue(true));
    assertThat(asList(descriptor.getCapability().behaviours())).containsExactlyInAnyOrder(IndexBehaviour.EVENTUALLY_CONSISTENT, IndexBehaviour.SKIP_AND_LIMIT);
}
Also used : IndexConfig(org.neo4j.internal.schema.IndexConfig) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) Value(org.neo4j.values.storable.Value) FulltextSchemaDescriptor(org.neo4j.internal.schema.FulltextSchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 4 with IndexDescriptor

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

the class FulltextIndexProviderTest method shouldAnswerStartsWithIfCypherCompatible.

@Test
void shouldAnswerStartsWithIfCypherCompatible() throws KernelException {
    IndexDescriptor indexReference;
    Label containsLabel = label("containsLabel");
    String containsProp = "containsProp";
    long nodea;
    long nodeapa1;
    long nodeapa2;
    long nodeapaapa;
    long nodeapalong;
    try (Transaction tx = db.beginTx()) {
        nodea = createNode(tx, containsLabel, containsProp, "a");
        createNode(tx, containsLabel, containsProp, "A");
        nodeapa1 = createNode(tx, containsLabel, containsProp, "apa");
        nodeapa2 = createNode(tx, containsLabel, containsProp, "apa");
        createNode(tx, containsLabel, containsProp, "longapa");
        nodeapaapa = createNode(tx, containsLabel, containsProp, "apa apa");
        nodeapalong = createNode(tx, containsLabel, containsProp, "apalong");
        tx.commit();
    }
    int containsLabelId;
    int containsPropertyId;
    try (Transaction tx = db.beginTx()) {
        TokenRead tokenRead = tokenRead(tx);
        containsLabelId = tokenRead.nodeLabel(containsLabel.name());
        containsPropertyId = tokenRead.propertyKey(containsProp);
    }
    indexReference = createIndex(new int[] { containsLabelId }, new int[] { containsPropertyId }, "cypher");
    await(indexReference);
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "a"), nodea, nodeapa1, nodeapa2, nodeapaapa, nodeapalong);
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2, nodeapalong, nodeapaapa);
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa*"));
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa a"), nodeapaapa);
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "*apa"));
    }
    controller.restartDbms();
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "a"), nodea, nodeapa1, nodeapa2, nodeapaapa, nodeapalong);
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2, nodeapalong, nodeapaapa);
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa*"));
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa a"), nodeapaapa);
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "*apa"));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Label(org.neo4j.graphdb.Label) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Test(org.junit.jupiter.api.Test)

Example 5 with IndexDescriptor

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

the class FulltextIndexProviderTest method shouldThrowOnCypherFulltextQueryIfNotCypherCompatibleAnalyzer.

@Test
void shouldThrowOnCypherFulltextQueryIfNotCypherCompatibleAnalyzer() throws KernelException {
    IndexDescriptor indexReference = createIndex(new int[] { labelIdHa }, new int[] { propIdHa }, "english");
    await(indexReference);
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
        IllegalStateException e = assertThrows(IllegalStateException.class, () -> assertQueryResult(ktx, endsWithQuery(1, "a")));
        assertThat(e.getMessage()).contains("This fulltext index does not have support for Cypher semantics because configured analyzer 'english' is not Cypher compatible.");
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)404 Test (org.junit.jupiter.api.Test)231 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)81 Value (org.neo4j.values.storable.Value)43 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)33 ArrayList (java.util.ArrayList)31 Transaction (org.neo4j.graphdb.Transaction)31 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)31 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)30 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)30 TokenRead (org.neo4j.internal.kernel.api.TokenRead)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)26 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)25 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)25 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)23 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)23 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)23 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)22 KernelException (org.neo4j.exceptions.KernelException)20