Search in sources :

Example 11 with SchemaReadCore

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

the class SchemaReadWriteTestBase method oldSnapshotShouldNotSeeNewlyCommittedConstraints.

@Test
void oldSnapshotShouldNotSeeNewlyCommittedConstraints() throws Exception {
    try (KernelTransaction longRunning = beginTransaction()) {
        SchemaReadCore snapshot = longRunning.schemaRead().snapshot();
        try (KernelTransaction overlapping = beginTransaction()) {
            overlapping.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label, prop1)).withName("a"));
            overlapping.schemaWrite().nodeKeyConstraintCreate(uniqueForSchema(forLabel(label2, prop1)).withName("b"));
            overlapping.schemaWrite().nodePropertyExistenceConstraintCreate(forLabel(label, prop2), "c");
            overlapping.schemaWrite().relationshipPropertyExistenceConstraintCreate(forRelType(type, prop1), "d");
            overlapping.commit();
        }
        assertThat(snapshot.constraintGetForName("a")).isNull();
        assertThat(snapshot.indexGetForName("a")).isEqualTo(NO_INDEX);
        assertThat(snapshot.constraintGetForName("b")).isNull();
        assertThat(snapshot.indexGetForName("b")).isEqualTo(NO_INDEX);
        assertThat(snapshot.constraintGetForName("c")).isNull();
        assertThat(snapshot.constraintGetForName("d")).isNull();
        assertFalse(snapshot.constraintsGetAll().hasNext());
        assertFalse(snapshot.constraintsGetForLabel(label).hasNext());
        assertFalse(snapshot.constraintsGetForRelationshipType(type).hasNext());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) Test(org.junit.jupiter.api.Test)

Example 12 with SchemaReadCore

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

the class SchemaReadWriteTestBase method createdIndexShouldPopulateInTx.

@Test
void createdIndexShouldPopulateInTx() throws Exception {
    IndexDescriptor index;
    try (KernelTransaction tx = beginTransaction()) {
        SchemaReadCore before = tx.schemaRead().snapshot();
        index = tx.schemaWrite().indexCreate(forLabel(label, prop1), "my index");
        assertThat(tx.schemaRead().indexGetState(index)).isEqualTo(InternalIndexState.POPULATING);
        assertThat(tx.schemaRead().snapshot().indexGetState(index)).isEqualTo(InternalIndexState.POPULATING);
        assertThat(before.indexGetState(index)).isEqualTo(InternalIndexState.POPULATING);
        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 13 with SchemaReadCore

use of org.neo4j.internal.kernel.api.SchemaReadCore 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 SchemaReadCore

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

the class SchemaReadWriteTestBase method shouldSeeIndexFromTransactionInSnapshot.

@Test
void shouldSeeIndexFromTransactionInSnapshot() throws Exception {
    try (KernelTransaction transaction = beginTransaction()) {
        transaction.schemaWrite().indexCreate(forLabel(label, prop1), "my index 1");
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaReadCore schemaReadBefore = transaction.schemaRead().snapshot();
        IndexDescriptor createdIndex = transaction.schemaWrite().indexCreate(forLabel(label, prop2), "my index 2");
        SchemaReadCore schemaReadAfter = transaction.schemaRead().snapshot();
        IndexDescriptor index = single(schemaReadBefore.index(forLabel(label, prop2)));
        assertThat(index.schema().getPropertyIds()).isEqualTo(new int[] { prop2 });
        assertThat(2).isEqualTo(Iterators.asList(schemaReadBefore.indexesGetAll()).size());
        assertThat(index).isEqualTo(createdIndex);
        assertThat(schemaReadBefore.indexGetForName("my index 2")).isEqualTo(createdIndex);
        index = single(schemaReadAfter.index(forLabel(label, prop2)));
        assertThat(index.schema().getPropertyIds()).isEqualTo(new int[] { prop2 });
        assertThat(2).isEqualTo(Iterators.asList(schemaReadAfter.indexesGetAll()).size());
        assertThat(index).isEqualTo(createdIndex);
        assertThat(schemaReadAfter.indexGetForName("my index 2")).isEqualTo(createdIndex);
    }
}
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 15 with SchemaReadCore

use of org.neo4j.internal.kernel.api.SchemaReadCore 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

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