Search in sources :

Example 26 with IndexCreator

use of org.neo4j.graphdb.schema.IndexCreator in project neo4j by neo4j.

the class SchemaAcceptanceTest method indexSettingValuesMustHaveCorrectType.

@Test
void indexSettingValuesMustHaveCorrectType() {
    try (Transaction tx = db.beginTx()) {
        IndexCreator creator = tx.schema().indexFor(label).withName("my_index").on(propertyKey);
        assertThrows(IllegalArgumentException.class, () -> creator.withIndexType(IndexType.FULLTEXT).withIndexConfiguration(Map.of(IndexSettingImpl.FULLTEXT_ANALYZER, 1)).create());
        assertThrows(IllegalArgumentException.class, () -> creator.withIndexType(IndexType.FULLTEXT).withIndexConfiguration(Map.of(IndexSettingImpl.FULLTEXT_ANALYZER, true)).create());
        assertThrows(IllegalArgumentException.class, () -> creator.withIndexType(IndexType.FULLTEXT).withIndexConfiguration(Map.of(IndexSettingImpl.FULLTEXT_EVENTUALLY_CONSISTENT, "true")).create());
        assertThrows(IllegalArgumentException.class, () -> creator.withIndexType(IndexType.FULLTEXT).withIndexConfiguration(Map.of(IndexSettingImpl.FULLTEXT_EVENTUALLY_CONSISTENT, 1)).create());
        assertThrows(IllegalArgumentException.class, () -> creator.withIndexConfiguration(Map.of(IndexSettingImpl.SPATIAL_CARTESIAN_MAX, "1")).create());
        assertThrows(IllegalArgumentException.class, () -> creator.withIndexConfiguration(Map.of(IndexSettingImpl.SPATIAL_CARTESIAN_MAX, 1)).create());
        assertThrows(IllegalArgumentException.class, () -> creator.withIndexConfiguration(Map.of(IndexSettingImpl.SPATIAL_CARTESIAN_MAX, 1.0)).create());
        tx.commit();
    }
}
Also used : IndexCreator(org.neo4j.graphdb.schema.IndexCreator) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with IndexCreator

use of org.neo4j.graphdb.schema.IndexCreator in project neo4j by neo4j.

the class SchemaAcceptanceTest method createIndexNoWait.

static IndexDefinition createIndexNoWait(GraphDatabaseService db, String name, RelationshipType relType, String... properties) {
    IndexDefinition indexDef;
    try (Transaction tx = db.beginTx()) {
        IndexCreator indexCreator = tx.schema().indexFor(relType);
        for (String property : properties) {
            indexCreator = indexCreator.on(property);
        }
        if (name != null) {
            indexCreator = indexCreator.withName(name);
        }
        indexDef = indexCreator.create();
        tx.commit();
    }
    return indexDef;
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexCreator(org.neo4j.graphdb.schema.IndexCreator)

Example 28 with IndexCreator

use of org.neo4j.graphdb.schema.IndexCreator in project neo4j by neo4j.

the class SchemaAcceptanceTest method indexNamesInTransactionStateMustBeUniqueEvenWhenGenerated.

@Test
void indexNamesInTransactionStateMustBeUniqueEvenWhenGenerated() {
    try (Transaction tx = db.beginTx()) {
        IndexDefinition index = tx.schema().indexFor(label).on(propertyKey).create();
        IndexCreator creator = tx.schema().indexFor(otherLabel).on(secondPropertyKey).withName(index.getName());
        ConstraintViolationException exception = assertThrows(ConstraintViolationException.class, creator::create);
        assertThat(exception).hasMessageContaining(alreadyExistsIndexMessage(index.getName()));
        tx.commit();
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexCreator(org.neo4j.graphdb.schema.IndexCreator) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with IndexCreator

use of org.neo4j.graphdb.schema.IndexCreator in project neo4j by neo4j.

the class SchemaAcceptanceTest method indexNamesInTransactionStateMustBeUniqueEvenWhenGenerated2.

@Test
void indexNamesInTransactionStateMustBeUniqueEvenWhenGenerated2() {
    try (Transaction tx = db.beginTx()) {
        IndexDefinition index = tx.schema().indexFor(otherLabel).on(secondPropertyKey).withName("index_a0d2924").create();
        IndexCreator creator = tx.schema().indexFor(label).on(propertyKey);
        ConstraintViolationException exception = assertThrows(ConstraintViolationException.class, creator::create);
        assertThat(exception).hasMessageContaining(alreadyExistsIndexMessage(index.getName()));
        tx.commit();
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexCreator(org.neo4j.graphdb.schema.IndexCreator) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

IndexCreator (org.neo4j.graphdb.schema.IndexCreator)29 Test (org.junit.jupiter.api.Test)17 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)15 RepeatedTest (org.junit.jupiter.api.RepeatedTest)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Transaction (org.neo4j.graphdb.Transaction)10 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)5 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)5 ResourceLock (org.junit.jupiter.api.parallel.ResourceLock)4 Schema (org.neo4j.graphdb.schema.Schema)4 Label (org.neo4j.graphdb.Label)2 SystemProcedure (org.neo4j.kernel.api.procedure.SystemProcedure)2 Description (org.neo4j.procedure.Description)2 Procedure (org.neo4j.procedure.Procedure)2 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.Test)1 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)1 RelationshipType (org.neo4j.graphdb.RelationshipType)1 ConstraintCreator (org.neo4j.graphdb.schema.ConstraintCreator)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1