Search in sources :

Example 21 with IndexRule

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

the class SchemaRecordCheckTest method shouldReportConstraintIndexNotReferencingBack.

@Test
public void shouldReportConstraintIndexNotReferencingBack() 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) ruleId1);
    ConstraintRule rule2 = uniquenessConstraintRule(ruleId2, labelId, propertyKeyId, ruleId1);
    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();
    ConsistencyReport.SchemaConsistencyReport report = check(obligationChecker, record1);
    check(obligationChecker, record2);
    // then
    verify(report).constraintIndexRuleNotReferencingBack(record2);
}
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 22 with IndexRule

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

the class SchemaRecordCheckTest method shouldNotReportConstraintIndexRuleWithoutBackReference.

@Test
public void shouldNotReportConstraintIndexRuleWithoutBackReference() throws Exception {
    // given
    int ruleId = 1;
    DynamicRecord record = inUse(dynamicRecord(ruleId));
    SchemaIndexProvider.Descriptor providerDescriptor = new SchemaIndexProvider.Descriptor("in-memory", "1.0");
    IndexRule rule = constraintIndexRule(ruleId, labelId, propertyKeyId, providerDescriptor);
    when(checker().ruleAccess.loadSingleSchemaRule(ruleId)).thenReturn(rule);
    add(inUse(new LabelTokenRecord(labelId)));
    add(inUse(new PropertyKeyTokenRecord(propertyKeyId)));
    // when
    check(record);
    SchemaRecordCheck obligationChecker = checker().forObligationChecking();
    ConsistencyReport.SchemaConsistencyReport report = check(obligationChecker, record);
    // then
    verifyZeroInteractions(report);
}
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) 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 23 with IndexRule

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

the class SchemaStorageTest method shouldReturnIndexRuleForLabelAndVeryManyPropertiesComposite.

@Test
public void shouldReturnIndexRuleForLabelAndVeryManyPropertiesComposite() throws Exception {
    String[] props = "abcdefghijklmnopqrstuvwxyzABCDEFGHJILKMNOPQRSTUVWXYZ".split("\\B");
    createSchema(db -> {
        IndexCreator indexCreator = db.schema().indexFor(Label.label(LABEL1));
        for (String prop : props) {
            indexCreator = indexCreator.on(prop);
        }
        indexCreator.create();
    });
    IndexRule rule = storage.indexGetForSchema(NewIndexDescriptorFactory.forLabel(labelId(LABEL1), Arrays.stream(props).mapToInt(this::propId).toArray()));
    assertNotNull(rule);
    assertTrue(SchemaDescriptorPredicates.hasLabel(rule, labelId(LABEL1)));
    for (String prop : props) {
        assertTrue(SchemaDescriptorPredicates.hasProperty(rule, propId(prop)));
    }
    assertEquals(NewIndexDescriptor.Type.GENERAL, rule.getIndexDescriptor().type());
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) IndexCreator(org.neo4j.graphdb.schema.IndexCreator) Test(org.junit.Test)

Example 24 with IndexRule

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

the class SchemaStorageTest method shouldReturnIndexRuleForLabelAndProperty.

@Test
public void shouldReturnIndexRuleForLabelAndProperty() {
    // Given
    createSchema(index(LABEL1, PROP1), index(LABEL1, PROP2), index(LABEL2, PROP1));
    // When
    IndexRule rule = storage.indexGetForSchema(indexDescriptor(LABEL1, PROP2));
    // Then
    assertNotNull(rule);
    assertRule(rule, LABEL1, PROP2, NewIndexDescriptor.Type.GENERAL);
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) Test(org.junit.Test)

Example 25 with IndexRule

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

the class SchemaStorageTest method shouldReturnIndexRuleForLabelAndPropertyComposite.

@Test
public void shouldReturnIndexRuleForLabelAndPropertyComposite() throws Exception {
    String a = "a", b = "b", c = "c", d = "d", e = "e", f = "f";
    createSchema(db -> {
        db.schema().indexFor(Label.label(LABEL1)).on(a).on(b).on(c).on(d).on(e).on(f).create();
    });
    IndexRule rule = storage.indexGetForSchema(NewIndexDescriptorFactory.forLabel(labelId(LABEL1), propId(a), propId(b), propId(c), propId(d), propId(e), propId(f)));
    assertNotNull(rule);
    assertTrue(SchemaDescriptorPredicates.hasLabel(rule, labelId(LABEL1)));
    assertTrue(SchemaDescriptorPredicates.hasProperty(rule, propId(a)));
    assertTrue(SchemaDescriptorPredicates.hasProperty(rule, propId(b)));
    assertTrue(SchemaDescriptorPredicates.hasProperty(rule, propId(c)));
    assertTrue(SchemaDescriptorPredicates.hasProperty(rule, propId(d)));
    assertTrue(SchemaDescriptorPredicates.hasProperty(rule, propId(e)));
    assertTrue(SchemaDescriptorPredicates.hasProperty(rule, propId(f)));
    assertEquals(NewIndexDescriptor.Type.GENERAL, rule.getIndexDescriptor().type());
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) Test(org.junit.Test)

Aggregations

IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)60 Test (org.junit.Test)42 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)24 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)22 SchemaRuleUtil.constraintIndexRule (org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule)14 NodePropertyDescriptor (org.neo4j.kernel.api.schema.NodePropertyDescriptor)9 ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)9 LabelTokenRecord (org.neo4j.kernel.impl.store.record.LabelTokenRecord)9 PropertyKeyTokenRecord (org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)9 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)8 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)8 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)8 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)7 BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)7 SchemaStorage (org.neo4j.kernel.impl.store.SchemaStorage)7 LabelTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand)7 PropertyKeyTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand)7 RelationshipTypeTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand)7 ArrayList (java.util.ArrayList)6 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)6