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());
}
}
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();
}
}
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();
}
}
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);
}
}
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();
}
}
Aggregations