Search in sources :

Example 11 with SchemaRead

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

the class SchemaReadWriteTestBase method shouldNotFindNonExistentIndex.

@Test
void shouldNotFindNonExistentIndex() throws Exception {
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaRead schemaRead = transaction.schemaRead();
        assertFalse(schemaRead.index(SchemaDescriptor.forLabel(label, prop1)).hasNext());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) Test(org.junit.jupiter.api.Test)

Example 12 with SchemaRead

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

the class SchemaReadWriteTestBase method shouldDropRelationshipPropertyExistenceConstraint.

@Test
void shouldDropRelationshipPropertyExistenceConstraint() throws Exception {
    ConstraintDescriptor constraint;
    try (KernelTransaction transaction = beginTransaction()) {
        constraint = transaction.schemaWrite().relationshipPropertyExistenceConstraintCreate(forRelType(type, prop1), "constraint name");
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        transaction.schemaWrite().constraintDrop(constraint);
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaRead schemaRead = transaction.schemaRead();
        assertFalse(schemaRead.constraintExists(constraint));
        assertThat(asList(schemaRead.constraintsGetForRelationshipType(type))).isEmpty();
        assertThat(asList(schemaRead.snapshot().constraintsGetForRelationshipType(type))).isEmpty();
    }
}
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 13 with SchemaRead

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

the class SchemaReadWriteTestBase method shouldNotSeeDroppedNodePropertyExistenceConstraintFromTransaction.

@Test
void shouldNotSeeDroppedNodePropertyExistenceConstraintFromTransaction() throws Exception {
    ConstraintDescriptor existing;
    try (KernelTransaction transaction = beginTransaction()) {
        existing = transaction.schemaWrite().nodePropertyExistenceConstraintCreate(forLabel(label, 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(label, 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 14 with SchemaRead

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

the class SchemaReadWriteTestBase method shouldDropUniquePropertyConstraint.

@Test
void shouldDropUniquePropertyConstraint() throws Exception {
    ConstraintDescriptor constraint;
    try (KernelTransaction transaction = beginTransaction()) {
        constraint = transaction.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label, prop1)));
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        transaction.schemaWrite().constraintDrop(constraint);
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaRead schemaRead = transaction.schemaRead();
        assertFalse(schemaRead.constraintExists(constraint));
        assertThat(asList(schemaRead.constraintsGetForLabel(label))).isEmpty();
        assertThat(asList(schemaRead.snapshot().constraintsGetForLabel(label))).isEmpty();
    }
}
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 15 with SchemaRead

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

the class SchemaReadWriteTestBase method shouldNotSeeDroppedNodeKeyConstraintFromTransaction.

@Test
void shouldNotSeeDroppedNodeKeyConstraintFromTransaction() throws Exception {
    ConstraintDescriptor existing;
    try (KernelTransaction transaction = beginTransaction()) {
        existing = transaction.schemaWrite().nodeKeyConstraintCreate(uniqueForSchema(forLabel(label, prop1)).withName("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));
        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)

Aggregations

SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)52 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)36 Test (org.junit.jupiter.api.Test)28 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)26 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)22 TokenRead (org.neo4j.internal.kernel.api.TokenRead)12 SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)9 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)8 ArrayList (java.util.ArrayList)7 Read (org.neo4j.internal.kernel.api.Read)5 HashMap (java.util.HashMap)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Arrays (java.util.Arrays)3 Iterator (java.util.Iterator)3 List (java.util.List)3 Map (java.util.Map)3 EntityType (org.neo4j.common.EntityType)3 KernelException (org.neo4j.exceptions.KernelException)3 Transaction (org.neo4j.graphdb.Transaction)3 Iterators (org.neo4j.internal.helpers.collection.Iterators)3