use of org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor 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.constraints.UniquenessConstraintDescriptor 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.constraints.UniquenessConstraintDescriptor in project neo4j by neo4j.
the class PlainOperationsTest method shouldAcquireSchemaNameWriteLockBeforeDroppingConstraintByName.
@Test
void shouldAcquireSchemaNameWriteLockBeforeDroppingConstraintByName() throws Exception {
// given
UniquenessConstraintDescriptor constraint = uniqueForSchema(schema).withName("constraint");
IndexDescriptor index = IndexPrototype.uniqueForSchema(schema).withName("constraint").materialise(13);
storageReaderWithConstraints(constraint);
when(storageReader.indexExists(index)).thenReturn(true);
when(storageReader.indexGetForName("constraint")).thenReturn(index);
when(storageReader.constraintGetForName("constraint")).thenReturn(constraint);
// when
operations.constraintDrop("constraint");
// then
long nameLock = ResourceIds.schemaNameResourceId("constraint");
order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.SCHEMA_NAME, nameLock);
order.verify(txState).constraintDoDrop(constraint);
order.verify(txState).indexDoDrop(index);
}
use of org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor in project neo4j by neo4j.
the class PlainOperationsTest method shouldReleaseAcquiredSchemaWriteLockIfConstraintCreationFails.
@Test
void shouldReleaseAcquiredSchemaWriteLockIfConstraintCreationFails() throws Exception {
// given
UniquenessConstraintDescriptor constraint = uniqueForSchema(schema);
storageReaderWithConstraints(constraint);
int labelId = schema.getLabelId();
int propertyId = schema.getPropertyId();
when(tokenHolders.labelTokens().getTokenById(labelId)).thenReturn(new NamedToken("Label", labelId));
when(tokenHolders.propertyKeyTokens().getTokenById(propertyId)).thenReturn(new NamedToken("prop", labelId));
// when
try {
operations.uniquePropertyConstraintCreate(IndexPrototype.uniqueForSchema(schema).withName("constraint name"));
fail("Expected an exception because this schema should already be constrained.");
} catch (AlreadyConstrainedException ignore) {
// Good.
}
// then
order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.LABEL, labelId);
order.verify(storageReader).constraintsGetForSchema(schema);
order.verify(locks).releaseExclusive(ResourceTypes.LABEL, labelId);
}
use of org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor in project neo4j by neo4j.
the class SchemaStorageIT method makeIndexRuleForConstraint.
private IndexDescriptor makeIndexRuleForConstraint(long ruleId, String label, String propertyKey, long constraintId) {
LabelSchemaDescriptor schema = forLabel(labelId(label), propId(propertyKey));
IndexPrototype prototype = uniqueForSchema(schema, GenericNativeIndexProvider.DESCRIPTOR);
UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(schema);
prototype = prototype.withName(SchemaRule.generateName(constraint, new String[] { label }, new String[] { propertyKey }));
return prototype.materialise(ruleId).withOwningConstraintId(constraintId);
}
Aggregations