Search in sources :

Example 6 with UniquenessConstraintDescriptor

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));
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) IndexUpdateListener(org.neo4j.storageengine.api.IndexUpdateListener) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) Test(org.junit.jupiter.api.Test)

Example 7 with UniquenessConstraintDescriptor

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);
}
Also used : UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 8 with UniquenessConstraintDescriptor

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);
}
Also used : UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor)

Example 9 with UniquenessConstraintDescriptor

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);
}
Also used : UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) Test(org.junit.jupiter.api.Test)

Example 10 with UniquenessConstraintDescriptor

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()));
}
Also used : UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

UniquenessConstraintDescriptor (org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)26 Test (org.junit.jupiter.api.Test)17 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)10 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)7 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)6 NodeKeyConstraintDescriptor (org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor)6 RepeatedTest (org.junit.jupiter.api.RepeatedTest)4 IndexBackedConstraintDescriptor (org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor)4 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)2 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)2 NodeExistenceConstraintDescriptor (org.neo4j.internal.schema.constraints.NodeExistenceConstraintDescriptor)2 RelExistenceConstraintDescriptor (org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor)2 KernelException (org.neo4j.exceptions.KernelException)1 UnspecifiedKernelException (org.neo4j.exceptions.UnspecifiedKernelException)1 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)1 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)1 IndexNotApplicableKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException)1 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)1 MalformedSchemaRuleException (org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException)1 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)1