Search in sources :

Example 11 with SchemaWrite

use of org.neo4j.internal.kernel.api.SchemaWrite in project neo4j by neo4j.

the class IndexIT method shouldDisallowDroppingIndexByNameThatBelongsToConstraint.

@Test
void shouldDisallowDroppingIndexByNameThatBelongsToConstraint() throws KernelException {
    // given
    String constraintName = "my constraint";
    {
        SchemaWrite statement = schemaWriteInNewTransaction();
        statement.uniquePropertyConstraintCreate(uniqueForSchema(schema).withName("constraint name"));
        commit();
    }
    // when
    SchemaWrite statement = schemaWriteInNewTransaction();
    SchemaKernelException e = assertThrows(SchemaKernelException.class, () -> statement.indexDrop(constraintName));
    assertEquals("Unable to drop index called `my constraint`. There is no such index.", e.getMessage());
    rollback();
}
Also used : SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 12 with SchemaWrite

use of org.neo4j.internal.kernel.api.SchemaWrite in project neo4j by neo4j.

the class IndexIT method shouldBeAbleToRemoveAConstraintIndexWithoutOwner.

@Test
void shouldBeAbleToRemoveAConstraintIndexWithoutOwner() throws Exception {
    // given
    AssertableLogProvider logProvider = new AssertableLogProvider();
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
    IndexProviderDescriptor provider = GenericNativeIndexProvider.DESCRIPTOR;
    IndexPrototype prototype = uniqueForSchema(schema).withName("constraint name").withIndexProvider(provider);
    IndexDescriptor constraintIndex = creator.createConstraintIndex(prototype);
    // then
    KernelTransaction transaction = newTransaction();
    assertEquals(emptySet(), asSet(transaction.schemaRead().constraintsGetForLabel(labelId)));
    commit();
    // when
    SchemaWrite schemaWrite = schemaWriteInNewTransaction();
    schemaWrite.indexDrop(constraintIndex);
    commit();
    // then
    transaction = newTransaction();
    assertEquals(emptySet(), asSet(transaction.schemaRead().indexesGetForLabel(labelId)));
    commit();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 13 with SchemaWrite

use of org.neo4j.internal.kernel.api.SchemaWrite in project neo4j by neo4j.

the class IndexIT method rollBackIndexRuleShouldNotBeCommitted.

@Test
void rollBackIndexRuleShouldNotBeCommitted() throws Exception {
    // GIVEN
    SchemaWrite schemaWrite = schemaWriteInNewTransaction();
    // WHEN
    schemaWrite.indexCreate(schema, "my index");
    // don't mark as success
    rollback();
    // THEN
    KernelTransaction transaction = newTransaction();
    assertEquals(emptySet(), asSet(transaction.schemaRead().indexesGetForLabel(labelId)));
    commit();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 14 with SchemaWrite

use of org.neo4j.internal.kernel.api.SchemaWrite in project neo4j by neo4j.

the class IndexIT method shouldListAll.

@Test
void shouldListAll() throws Exception {
    // given
    SchemaWrite schemaWrite = schemaWriteInNewTransaction();
    IndexDescriptor index1 = schemaWrite.indexCreate(schema, "my index");
    IndexBackedConstraintDescriptor constraint = schemaWrite.uniquePropertyConstraintCreate(uniqueForSchema(schema2).withName("constraint name")).asIndexBackedConstraint();
    commit();
    // then/when
    SchemaRead schemaRead = newTransaction().schemaRead();
    IndexDescriptor index2 = Iterators.single(schemaRead.index(constraint.schema()));
    List<IndexDescriptor> indexes = Iterators.asList(schemaRead.indexesGetAll());
    assertThat(indexes).contains(index1, index2);
    commit();
}
Also used : SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) IndexBackedConstraintDescriptor(org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 15 with SchemaWrite

use of org.neo4j.internal.kernel.api.SchemaWrite in project neo4j by neo4j.

the class IndexIT method committedAndTransactionalIndexRulesShouldBeMerged.

@Test
void committedAndTransactionalIndexRulesShouldBeMerged() throws Exception {
    // GIVEN
    SchemaWrite schemaWriteOperations = schemaWriteInNewTransaction();
    IndexDescriptor existingRule = schemaWriteOperations.indexCreate(schema, "my index");
    commit();
    // WHEN
    KernelTransaction transaction = newTransaction(AUTH_DISABLED);
    LabelSchemaDescriptor schema = SchemaDescriptor.forLabel(labelId, propertyKeyId2);
    IndexDescriptor addedRule = transaction.schemaWrite().indexCreate(schema, "my other index");
    Set<IndexDescriptor> indexRulesInTx = asSet(transaction.schemaRead().indexesGetForLabel(labelId));
    commit();
    // THEN
    assertEquals(asSet(existingRule, addedRule), indexRulesInTx);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Aggregations

SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)27 Test (org.junit.jupiter.api.Test)21 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)15 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)11 TokenWrite (org.neo4j.internal.kernel.api.TokenWrite)9 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)9 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)5 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)4 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)4 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)4 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)4 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)3 FulltextSchemaDescriptor (org.neo4j.internal.schema.FulltextSchemaDescriptor)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 FutureTask (java.util.concurrent.FutureTask)2 Timeout (org.junit.jupiter.api.Timeout)2 KernelException (org.neo4j.exceptions.KernelException)2 Resource (org.neo4j.graphdb.Resource)2 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)2 IndexBackedConstraintDescriptor (org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor)2