use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class AllStoreHolder method constraintGetForName.
ConstraintDescriptor constraintGetForName(StorageSchemaReader reader, String name) {
ktx.assertOpen();
ConstraintDescriptor constraint = reader.constraintGetForName(name);
if (ktx.hasTxStateWithChanges()) {
Predicate<ConstraintDescriptor> namePredicate = constraintDescriptor -> constraintDescriptor.getName().equals(name);
Iterator<ConstraintDescriptor> constraints = ktx.txState().constraintsChanges().filterAdded(namePredicate).apply(Iterators.iterator(constraint));
constraint = singleOrNull(constraints);
}
return lockConstraint(constraint);
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class PlainOperationsTest method shouldNotAcquireSchemaReadLockLazilyBeforeGettingAllConstraintsFromSnapshot.
@Test
void shouldNotAcquireSchemaReadLockLazilyBeforeGettingAllConstraintsFromSnapshot() {
// given
int labelId = 1;
int relTypeId = 2;
UniquenessConstraintDescriptor uniquenessConstraint = uniqueForLabel(labelId, 2, 3, 3);
RelExistenceConstraintDescriptor existenceConstraint = existsForRelType(relTypeId, 3, 4, 5);
when(storageReaderSnapshot.constraintsGetAll()).thenReturn(Iterators.iterator(uniquenessConstraint, existenceConstraint));
// when
Iterator<ConstraintDescriptor> result = allStoreHolder.snapshot().constraintsGetAll();
// then
assertThat(Iterators.count(result)).isEqualTo(2L);
assertThat(asList(result)).isEmpty();
verify(storageReaderSnapshot).constraintsGetAll();
verifyNoMoreInteractions(locks);
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class PlainOperationsTest method shouldAcquireSchemaReadLockLazilyBeforeGettingAllConstraints.
@Test
void shouldAcquireSchemaReadLockLazilyBeforeGettingAllConstraints() {
// given
int labelId = 1;
int relTypeId = 2;
UniquenessConstraintDescriptor uniquenessConstraint = uniqueForLabel(labelId, 2, 3, 3);
RelExistenceConstraintDescriptor existenceConstraint = existsForRelType(relTypeId, 3, 4, 5);
when(storageReader.constraintsGetAll()).thenReturn(Iterators.iterator(uniquenessConstraint, existenceConstraint));
when(storageReader.constraintExists(uniquenessConstraint)).thenReturn(true);
when(storageReader.constraintExists(existenceConstraint)).thenReturn(true);
// when
Iterator<ConstraintDescriptor> result = allStoreHolder.constraintsGetAll();
// then
assertThat(Iterators.count(result)).isEqualTo(2L);
assertThat(asList(result)).isEmpty();
order.verify(storageReader).constraintsGetAll();
order.verify(locks, atLeastOnce()).acquireShared(LockTracer.NONE, ResourceTypes.LABEL, labelId);
order.verify(locks, atLeastOnce()).acquireShared(LockTracer.NONE, ResourceTypes.RELATIONSHIP_TYPE, relTypeId);
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class KernelSchemaStateFlushingTest method createConstraint.
private ConstraintDescriptor createConstraint() throws KernelException {
try (KernelTransaction transaction = beginTransaction()) {
ConstraintDescriptor descriptor = transaction.schemaWrite().uniquePropertyConstraintCreate(IndexPrototype.uniqueForSchema(SchemaDescriptor.forLabel(labelId, propId)));
transaction.commit();
return descriptor;
}
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class RecordStorageReaderSchemaTest method shouldListAllConstraintsAtTimeOfSnapshot.
@Test
void shouldListAllConstraintsAtTimeOfSnapshot() throws Exception {
// Given
createUniquenessConstraint(label1, propertyKey);
// When
StorageSchemaReader snapshot = storageReader.schemaSnapshot();
createUniquenessConstraint(label2, propertyKey);
Set<ConstraintDescriptor> constraints = asSet(snapshot.constraintsGetAll());
// Then
Set<ConstraintDescriptor> expectedConstraints = asSet(uniqueConstraintDescriptor(label1, propertyKey));
assertEquals(expectedConstraints, constraints);
}
Aggregations