Search in sources :

Example 66 with ConstraintDescriptor

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

the class SchemaReadWriteTestBase method shouldNotSeeDroppedRelationshipPropertyExistenceConstraintFromTransaction.

@Test
void shouldNotSeeDroppedRelationshipPropertyExistenceConstraintFromTransaction() throws Exception {
    ConstraintDescriptor existing;
    try (KernelTransaction transaction = beginTransaction()) {
        existing = transaction.schemaWrite().relationshipPropertyExistenceConstraintCreate(forRelType(type, prop1), "constraint name");
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaReadCore before = transaction.schemaRead().snapshot();
        transaction.schemaWrite().constraintDrop(existing);
        SchemaRead schemaRead = transaction.schemaRead();
        assertFalse(schemaRead.constraintExists(existing));
        assertFalse(schemaRead.index(SchemaDescriptor.forLabel(type, prop2)).hasNext());
        assertThat(asList(schemaRead.constraintsGetForLabel(label))).isEmpty();
        assertThat(asList(schemaRead.snapshot().constraintsGetForLabel(label))).isEmpty();
        assertThat(asList(before.constraintsGetForLabel(label))).isEmpty();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) Test(org.junit.jupiter.api.Test)

Example 67 with ConstraintDescriptor

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

the class SchemaReadWriteTestBase method shouldCreateRelationshipPropertyExistenceConstraint.

@Test
void shouldCreateRelationshipPropertyExistenceConstraint() throws Exception {
    ConstraintDescriptor constraint;
    try (KernelTransaction transaction = beginTransaction()) {
        constraint = transaction.schemaWrite().relationshipPropertyExistenceConstraintCreate(forRelType(type, prop1), "constraint name");
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaRead schemaRead = transaction.schemaRead();
        assertTrue(schemaRead.constraintExists(constraint));
        assertThat(asList(schemaRead.constraintsGetForRelationshipType(type))).isEqualTo(singletonList(constraint));
        assertThat(asList(schemaRead.snapshot().constraintsGetForRelationshipType(type))).isEqualTo(singletonList(constraint));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) Test(org.junit.jupiter.api.Test)

Example 68 with ConstraintDescriptor

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

the class SchemaReadWriteTestBase method shouldSeeNodePropertyExistenceConstraintFromTransaction.

@Test
void shouldSeeNodePropertyExistenceConstraintFromTransaction() throws Exception {
    ConstraintDescriptor existing;
    try (KernelTransaction transaction = beginTransaction()) {
        existing = transaction.schemaWrite().nodePropertyExistenceConstraintCreate(forLabel(label, prop1), "existing constraint");
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaReadCore before = transaction.schemaRead().snapshot();
        ConstraintDescriptor newConstraint = transaction.schemaWrite().nodePropertyExistenceConstraintCreate(forLabel(label, prop2), "new constraint");
        SchemaRead schemaRead = transaction.schemaRead();
        assertTrue(schemaRead.constraintExists(existing));
        assertTrue(schemaRead.constraintExists(newConstraint));
        assertThat(asList(schemaRead.constraintsGetForLabel(label))).contains(existing, newConstraint);
        assertThat(asList(schemaRead.snapshot().constraintsGetForLabel(label))).contains(existing, newConstraint);
        assertThat(asList(before.constraintsGetForLabel(label))).contains(existing, newConstraint);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) Test(org.junit.jupiter.api.Test)

Example 69 with ConstraintDescriptor

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

the class SchemaReadWriteTestBase method shouldListConstraintsByLabel.

@Test
void shouldListConstraintsByLabel() throws Exception {
    int wrongLabel;
    ConstraintDescriptor inStore;
    ConstraintDescriptor droppedInTx;
    ConstraintDescriptor createdInTx;
    try (KernelTransaction tx = beginTransaction()) {
        wrongLabel = tx.tokenWrite().labelGetOrCreateForName("wrongLabel");
        tx.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(wrongLabel, prop1)).withName("first constraint"));
        inStore = tx.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label, prop1)).withName("second constraint"));
        droppedInTx = tx.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label, prop2)).withName("third constraint"));
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        SchemaReadCore before = tx.schemaRead().snapshot();
        createdInTx = tx.schemaWrite().nodePropertyExistenceConstraintCreate(forLabel(label, prop1), "fourth constraint");
        tx.schemaWrite().nodePropertyExistenceConstraintCreate(forLabel(wrongLabel, prop1), "fifth constraint");
        tx.schemaWrite().constraintDrop(droppedInTx);
        Iterable<ConstraintDescriptor> allConstraints = () -> tx.schemaRead().constraintsGetForLabel(label);
        assertThat(allConstraints).contains(inStore, createdInTx);
        assertThat(before.constraintsGetForLabel(label)).toIterable().contains(inStore, createdInTx);
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) Test(org.junit.jupiter.api.Test)

Example 70 with ConstraintDescriptor

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

the class SchemaReadWriteTestBase method shouldCreateNodeKeyConstraint.

@Test
void shouldCreateNodeKeyConstraint() throws Exception {
    ConstraintDescriptor constraint;
    try (KernelTransaction transaction = beginTransaction()) {
        constraint = transaction.schemaWrite().nodeKeyConstraintCreate(uniqueForSchema(forLabel(label, prop1)));
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaRead schemaRead = transaction.schemaRead();
        assertTrue(schemaRead.constraintExists(constraint));
        assertThat(asList(schemaRead.constraintsGetForLabel(label))).isEqualTo(singletonList(constraint));
        assertThat(asList(schemaRead.snapshot().constraintsGetForLabel(label))).isEqualTo(singletonList(constraint));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)107 Test (org.junit.jupiter.api.Test)62 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)34 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)32 UniquenessConstraintDescriptor (org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)26 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)21 NodeKeyConstraintDescriptor (org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor)20 IndexBackedConstraintDescriptor (org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor)19 SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)16 TokenRead (org.neo4j.internal.kernel.api.TokenRead)9 ArrayList (java.util.ArrayList)8 RepeatedTest (org.junit.jupiter.api.RepeatedTest)6 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)6 SchemaStore (org.neo4j.kernel.impl.store.SchemaStore)6 InternalIndexState (org.neo4j.internal.kernel.api.InternalIndexState)5 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)5 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)5 SchemaRule (org.neo4j.internal.schema.SchemaRule)5 SchemaRecord (org.neo4j.kernel.impl.store.record.SchemaRecord)5 OptionalLong (java.util.OptionalLong)4