Search in sources :

Example 16 with SchemaReadCore

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

the class SchemaReadWriteTestBase method shouldListAllConstraintsInSnapshot.

@Test
void shouldListAllConstraintsInSnapshot() throws Exception {
    ConstraintDescriptor toRetain;
    ConstraintDescriptor toRetain2;
    ConstraintDescriptor toDrop;
    ConstraintDescriptor created;
    try (KernelTransaction tx = beginTransaction()) {
        toRetain = tx.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label, prop1)).withName("first constraint"));
        toRetain2 = tx.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label2, prop1)).withName("second constraint"));
        toDrop = tx.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label, prop2)).withName("third constraint"));
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        SchemaReadCore before = tx.schemaRead().snapshot();
        created = tx.schemaWrite().nodePropertyExistenceConstraintCreate(forLabel(label, prop1), "new constraint");
        tx.schemaWrite().constraintDrop(toDrop);
        Iterable<ConstraintDescriptor> allConstraints = () -> tx.schemaRead().snapshot().constraintsGetAll();
        assertThat(allConstraints).contains(toRetain, toRetain2, created);
        assertThat(before.constraintsGetAll()).toIterable().contains(toRetain, toRetain2, created);
        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 17 with SchemaReadCore

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

the class SchemaReadWriteTestBase method shouldListIndexesByLabelInSnapshot.

@Test
void shouldListIndexesByLabelInSnapshot() throws Exception {
    int wrongLabel;
    IndexDescriptor inStore;
    IndexDescriptor droppedInTx;
    IndexDescriptor createdInTx;
    try (KernelTransaction tx = beginTransaction()) {
        wrongLabel = tx.tokenWrite().labelGetOrCreateForName("wrongLabel");
        tx.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(wrongLabel, prop1)));
        inStore = tx.schemaWrite().indexCreate(forLabel(label, prop1), "a");
        droppedInTx = tx.schemaWrite().indexCreate(forLabel(label, prop2), "b");
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        SchemaReadCore before = tx.schemaRead().snapshot();
        createdInTx = tx.schemaWrite().indexCreate(forLabel(label, prop3), "c");
        tx.schemaWrite().indexCreate(forLabel(wrongLabel, prop2), "d");
        tx.schemaWrite().indexDrop(droppedInTx);
        Iterable<IndexDescriptor> indexes = () -> tx.schemaRead().snapshot().indexesGetForLabel(label);
        assertThat(indexes).contains(inStore, createdInTx);
        assertThat(before.indexesGetForLabel(label)).toIterable().contains(inStore, createdInTx);
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) Test(org.junit.jupiter.api.Test)

Example 18 with SchemaReadCore

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

the class SchemaReadWriteTestBase method shouldSeeRelationshipPropertyExistenceConstraintFromTransaction.

@Test
void shouldSeeRelationshipPropertyExistenceConstraintFromTransaction() throws Exception {
    ConstraintDescriptor existing;
    try (KernelTransaction transaction = beginTransaction()) {
        existing = transaction.schemaWrite().relationshipPropertyExistenceConstraintCreate(forRelType(type, prop1), "existing constraint");
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaReadCore before = transaction.schemaRead().snapshot();
        ConstraintDescriptor newConstraint = transaction.schemaWrite().relationshipPropertyExistenceConstraintCreate(forRelType(type, prop2), "new constraint");
        SchemaRead schemaRead = transaction.schemaRead();
        assertTrue(schemaRead.constraintExists(existing));
        assertTrue(schemaRead.constraintExists(newConstraint));
        assertThat(asList(schemaRead.constraintsGetForRelationshipType(type))).contains(existing, newConstraint);
        assertThat(asList(schemaRead.snapshot().constraintsGetForRelationshipType(type))).contains(existing, newConstraint);
        assertThat(asList(before.constraintsGetForRelationshipType(type))).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 19 with SchemaReadCore

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

the class SchemaReadWriteTestBase method shouldSeeNodeKeyConstraintFromTransaction.

@Test
void shouldSeeNodeKeyConstraintFromTransaction() throws Exception {
    ConstraintDescriptor existing;
    try (KernelTransaction transaction = beginTransaction()) {
        existing = transaction.schemaWrite().nodeKeyConstraintCreate(uniqueForSchema(forLabel(label, prop1)).withName("existing constraint"));
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaReadCore before = transaction.schemaRead().snapshot();
        ConstraintDescriptor newConstraint = transaction.schemaWrite().nodeKeyConstraintCreate(uniqueForSchema(forLabel(label, prop2)).withName("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 20 with SchemaReadCore

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

the class SchemaReadWriteTestBase method shouldListAllIndexesInSnapshot.

@Test
void shouldListAllIndexesInSnapshot() throws Exception {
    IndexDescriptor toRetain;
    IndexDescriptor toRetain2;
    IndexDescriptor toDrop;
    IndexDescriptor created;
    try (KernelTransaction tx = beginTransaction()) {
        toRetain = tx.schemaWrite().indexCreate(forLabel(label, prop1), "a");
        toRetain2 = tx.schemaWrite().indexCreate(forLabel(label2, prop1), "b");
        toDrop = tx.schemaWrite().indexCreate(forLabel(label, prop2), "c");
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        SchemaReadCore before = tx.schemaRead().snapshot();
        created = tx.schemaWrite().indexCreate(forLabel(label2, prop2), "d");
        tx.schemaWrite().indexDrop(toDrop);
        SchemaReadCore after = tx.schemaRead().snapshot();
        assertThat(before.indexesGetAll()).toIterable().contains(toRetain, toRetain2, created);
        assertThat(after.indexesGetAll()).toIterable().contains(toRetain, toRetain2, created);
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) Test(org.junit.jupiter.api.Test)

Aggregations

SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)32 Test (org.junit.jupiter.api.Test)27 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)21 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)17 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)17 TokenRead (org.neo4j.internal.kernel.api.TokenRead)13 InternalIndexState (org.neo4j.internal.kernel.api.InternalIndexState)10 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)9 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)5 SystemProcedure (org.neo4j.kernel.api.procedure.SystemProcedure)4 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)4 Description (org.neo4j.procedure.Description)4 Procedure (org.neo4j.procedure.Procedure)4 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 DependencyResolver (org.neo4j.common.DependencyResolver)3 Config (org.neo4j.configuration.Config)3