Search in sources :

Example 16 with ConstraintRule

use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.

the class IntegrityValidatorTest method shouldValidateUniquenessIndexes.

@Test
public void shouldValidateUniquenessIndexes() throws Exception {
    // Given
    NeoStores store = mock(NeoStores.class);
    IndexingService indexes = mock(IndexingService.class);
    IntegrityValidator validator = new IntegrityValidator(store, indexes);
    UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel(1, 1);
    doThrow(new UniquePropertyValueValidationException(constraint, ConstraintValidationException.Phase.VERIFICATION, new RuntimeException())).when(indexes).validateIndex(2L);
    ConstraintRule record = ConstraintRule.constraintRule(1L, constraint, 2L);
    // When
    try {
        validator.validateSchemaRule(record);
        fail("Should have thrown integrity error.");
    } catch (Exception e) {
    // good
    }
}
Also used : UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) NeoStores(org.neo4j.kernel.impl.store.NeoStores) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) ConstraintValidationException(org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException) Test(org.junit.Test)

Example 17 with ConstraintRule

use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.

the class SchemaCache method addSchemaRule.

public void addSchemaRule(SchemaRule rule) {
    if (rule instanceof ConstraintRule) {
        ConstraintRule constraintRule = (ConstraintRule) rule;
        constraintRuleById.put(constraintRule.getId(), constraintRule);
        constraints.add(constraintSemantics.readConstraint(constraintRule));
    } else if (rule instanceof IndexRule) {
        IndexRule indexRule = (IndexRule) rule;
        indexRuleById.put(indexRule.getId(), indexRule);
        indexDescriptors.put(indexRule.schema(), indexRule.getIndexDescriptor());
    }
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule)

Example 18 with ConstraintRule

use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.

the class SchemaCache method removeSchemaRule.

public void removeSchemaRule(long id) {
    if (constraintRuleById.containsKey(id)) {
        ConstraintRule rule = constraintRuleById.remove(id);
        constraints.remove(constraintSemantics.readConstraint(rule));
    } else if (indexRuleById.containsKey(id)) {
        IndexRule rule = indexRuleById.remove(id);
        indexDescriptors.remove(rule.schema());
    }
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule)

Example 19 with ConstraintRule

use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.

the class SchemaRecordCheckTest method shouldReportUniquenessConstraintNotReferencingBack.

@Test
public void shouldReportUniquenessConstraintNotReferencingBack() throws Exception {
    // given
    int ruleId1 = 0;
    int ruleId2 = 1;
    DynamicRecord record1 = inUse(dynamicRecord(ruleId1));
    DynamicRecord record2 = inUse(dynamicRecord(ruleId2));
    SchemaIndexProvider.Descriptor providerDescriptor = new SchemaIndexProvider.Descriptor("in-memory", "1.0");
    IndexRule rule1 = constraintIndexRule(ruleId1, labelId, propertyKeyId, providerDescriptor, (long) ruleId2);
    ConstraintRule rule2 = uniquenessConstraintRule(ruleId2, labelId, propertyKeyId, ruleId2);
    when(checker().ruleAccess.loadSingleSchemaRule(ruleId1)).thenReturn(rule1);
    when(checker().ruleAccess.loadSingleSchemaRule(ruleId2)).thenReturn(rule2);
    add(inUse(new LabelTokenRecord(labelId)));
    add(inUse(new PropertyKeyTokenRecord(propertyKeyId)));
    // when
    check(record1);
    check(record2);
    SchemaRecordCheck obligationChecker = checker().forObligationChecking();
    check(obligationChecker, record1);
    ConsistencyReport.SchemaConsistencyReport report = check(obligationChecker, record2);
    // then
    verify(report).uniquenessConstraintNotReferencingBack(record1);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaRuleUtil.constraintIndexRule(org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) SchemaRuleUtil.uniquenessConstraintRule(org.neo4j.consistency.checking.SchemaRuleUtil.uniquenessConstraintRule) NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) LabelTokenRecord(org.neo4j.kernel.impl.store.record.LabelTokenRecord) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport) Test(org.junit.Test)

Example 20 with ConstraintRule

use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.

the class SchemaRecordCheckTest method shouldReportInvalidPropertyReferenceFromUniquenessConstraintRule.

@Test
public void shouldReportInvalidPropertyReferenceFromUniquenessConstraintRule() throws Exception {
    // given
    int schemaRuleId = 0;
    int indexRuleId = 1;
    DynamicRecord record = inUse(dynamicRecord(schemaRuleId));
    ConstraintRule rule = uniquenessConstraintRule(schemaRuleId, labelId, propertyKeyId, indexRuleId);
    when(checker().ruleAccess.loadSingleSchemaRule(schemaRuleId)).thenReturn(rule);
    add(inUse(new LabelTokenRecord(labelId)));
    PropertyKeyTokenRecord propertyKeyToken = add(notInUse(new PropertyKeyTokenRecord(propertyKeyId)));
    // when
    ConsistencyReport.SchemaConsistencyReport report = check(record);
    // then
    verify(report).propertyKeyNotInUse(propertyKeyToken);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) SchemaRuleUtil.uniquenessConstraintRule(org.neo4j.consistency.checking.SchemaRuleUtil.uniquenessConstraintRule) LabelTokenRecord(org.neo4j.kernel.impl.store.record.LabelTokenRecord) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport) Test(org.junit.Test)

Aggregations

ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)26 Test (org.junit.Test)20 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)16 SchemaRuleUtil.uniquenessConstraintRule (org.neo4j.consistency.checking.SchemaRuleUtil.uniquenessConstraintRule)8 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)8 BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)6 LabelTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand)6 PropertyKeyTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand)6 RelationshipTypeTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand)6 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)5 LabelTokenRecord (org.neo4j.kernel.impl.store.record.LabelTokenRecord)5 PropertyKeyTokenRecord (org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)5 SchemaRuleUtil.constraintIndexRule (org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule)3 SchemaRuleUtil.nodePropertyExistenceConstraintRule (org.neo4j.consistency.checking.SchemaRuleUtil.nodePropertyExistenceConstraintRule)3 SchemaRuleUtil.relPropertyExistenceConstraintRule (org.neo4j.consistency.checking.SchemaRuleUtil.relPropertyExistenceConstraintRule)3 ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)3 SchemaStore (org.neo4j.kernel.impl.store.SchemaStore)3 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)2 NodePropertyDescriptor (org.neo4j.kernel.api.schema.NodePropertyDescriptor)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2