use of org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor in project neo4j by neo4j.
the class IntegrityValidatorTest method shouldValidateUniquenessIndexes.
@Test
void shouldValidateUniquenessIndexes() throws Exception {
// Given
NeoStores store = mock(NeoStores.class);
IndexUpdateListener indexes = mock(IndexUpdateListener.class);
IntegrityValidator validator = new IntegrityValidator(store);
validator.setIndexValidator(indexes);
UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel(1, 1);
doThrow(new ConstraintViolationException("error", new RuntimeException())).when(indexes).validateIndex(2L);
ConstraintDescriptor record = constraint.withId(1).withOwnedIndexId(2);
// When
assertThrows(Exception.class, () -> validator.validateSchemaRule(record));
}
use of org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor in project neo4j by neo4j.
the class PlainOperationsTest method shouldAcquireSchemaWriteLockBeforeDroppingConstraint.
@Test
void shouldAcquireSchemaWriteLockBeforeDroppingConstraint() 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
operations.constraintDrop(constraint);
// then
order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.LABEL, schema.getLabelId());
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 ConstraintDescriptorTest method assertEqualityByDescriptor.
private static void assertEqualityByDescriptor(UniquenessConstraintDescriptor descriptor) {
ConstraintDescriptor rule1 = descriptor.withId(RULE_ID).withOwnedIndexId(RULE_ID_2);
ConstraintDescriptor rule2 = descriptor.withId(RULE_ID_2);
assertEquality(rule1, rule2);
}
use of org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor in project neo4j by neo4j.
the class ConstraintDescriptorTest method shouldCreateUniquenessConstraintWithOwnedIndex.
@Test
void shouldCreateUniquenessConstraintWithOwnedIndex() {
// GIVEN
UniquenessConstraintDescriptor descriptor = ConstraintDescriptorFactory.uniqueForLabel(LABEL_ID, PROPERTY_ID_1);
UniquenessConstraintDescriptor constraint = descriptor.withId(RULE_ID).withOwnedIndexId(RULE_ID_2);
// THEN
assertThat(constraint).isEqualTo(descriptor);
assertThat(constraint.ownedIndexId()).isEqualTo(RULE_ID_2);
}
use of org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor in project neo4j by neo4j.
the class SchemaCheckerTest method shouldReportMissingObligationConstraintIndexRule.
@Test
void shouldReportMissingObligationConstraintIndexRule() throws Exception {
// given
try (AutoCloseable ignored = tx()) {
var cursorContext = CursorContext.NULL;
UniquenessConstraintDescriptor constraintDescriptor = ConstraintDescriptorFactory.uniqueForLabel(label1, propertyKey1).withId(schemaStore.nextId(cursorContext)).withName(NAME).withOwnedIndexId(UNUSED);
schemaStorage.writeSchemaRule(constraintDescriptor, cursorContext, INSTANCE);
}
// when
check();
// then
expect(SchemaConsistencyReport.class, report -> report.missingObligation(any()));
}
Aggregations