Search in sources :

Example 21 with ConstraintRule

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

the class FullCheckIntegrationTest method createNodePropertyExistenceConstraint.

private void createNodePropertyExistenceConstraint(int labelId, int propertyKeyId) {
    SchemaStore schemaStore = (SchemaStore) fixture.directStoreAccess().nativeStores().getSchemaStore();
    ConstraintRule rule = nodePropertyExistenceConstraintRule(schemaStore.nextId(), labelId, propertyKeyId);
    Collection<DynamicRecord> records = schemaStore.allocateFrom(rule);
    for (DynamicRecord record : records) {
        schemaStore.updateRecord(record);
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) SchemaRuleUtil.uniquenessConstraintRule(org.neo4j.consistency.checking.SchemaRuleUtil.uniquenessConstraintRule) SchemaRuleUtil.relPropertyExistenceConstraintRule(org.neo4j.consistency.checking.SchemaRuleUtil.relPropertyExistenceConstraintRule) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) SchemaRuleUtil.nodePropertyExistenceConstraintRule(org.neo4j.consistency.checking.SchemaRuleUtil.nodePropertyExistenceConstraintRule)

Example 22 with ConstraintRule

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

the class FullCheckIntegrationTest method shouldReportInvalidConstraintBackReferences.

@Test
public void shouldReportInvalidConstraintBackReferences() throws Exception {
    // given
    fixture.apply(new GraphStoreFixture.Transaction() {

        @Override
        protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
            int ruleId1 = (int) next.schema();
            int ruleId2 = (int) next.schema();
            int labelId = next.label();
            int propertyKeyId = next.propertyKey();
            DynamicRecord record1 = new DynamicRecord(ruleId1);
            DynamicRecord record2 = new DynamicRecord(ruleId2);
            DynamicRecord record1Before = record1.clone();
            DynamicRecord record2Before = record2.clone();
            IndexRule rule1 = constraintIndexRule(ruleId1, labelId, propertyKeyId, DESCRIPTOR, (long) ruleId2);
            ConstraintRule rule2 = uniquenessConstraintRule(ruleId2, labelId, propertyKeyId, ruleId2);
            Collection<DynamicRecord> records1 = serializeRule(rule1, record1);
            Collection<DynamicRecord> records2 = serializeRule(rule2, record2);
            assertEquals(asList(record1), records1);
            assertEquals(asList(record2), records2);
            tx.nodeLabel(labelId, "label");
            tx.propertyKey(propertyKeyId, "property");
            tx.createSchema(asList(record1Before), records1, rule1);
            tx.createSchema(asList(record2Before), records2, rule2);
        }
    });
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    on(stats).verify(RecordType.SCHEMA, 2).andThatsAllFolks();
}
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) TransactionDataBuilder(org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder) SchemaRuleUtil.uniquenessConstraintRule(org.neo4j.consistency.checking.SchemaRuleUtil.uniquenessConstraintRule) SchemaRuleUtil.relPropertyExistenceConstraintRule(org.neo4j.consistency.checking.SchemaRuleUtil.relPropertyExistenceConstraintRule) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) SchemaRuleUtil.nodePropertyExistenceConstraintRule(org.neo4j.consistency.checking.SchemaRuleUtil.nodePropertyExistenceConstraintRule) IdGenerator(org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator) Collection(java.util.Collection) GraphStoreFixture(org.neo4j.consistency.checking.GraphStoreFixture) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Test(org.junit.Test)

Example 23 with ConstraintRule

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

the class NeoStoreTransactionApplierTest method shouldApplyUpdateUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery.

@Test
public void shouldApplyUpdateUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplier(true);
    final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
    final Collection<DynamicRecord> recordsAfter = Arrays.asList(record);
    final ConstraintRule rule = uniquenessConstraintRule(0L, 1, 2, 3L);
    final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(Collections.<DynamicRecord>emptyList(), recordsAfter, rule);
    // when
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(schemaStore, times(1)).setHighestPossibleIdInUse(record.getId());
    verify(schemaStore, times(1)).updateRecord(record);
    verify(metaDataStore, times(1)).setLatestConstraintIntroducingTx(transactionId);
    verify(cacheAccess, times(1)).addSchemaRule(rule);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Example 24 with ConstraintRule

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

the class NeoStoreTransactionApplierTest method shouldApplyCreateUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery.

@Test
public void shouldApplyCreateUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplier(true);
    final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
    record.setCreated();
    final Collection<DynamicRecord> recordsAfter = Arrays.asList(record);
    final ConstraintRule rule = uniquenessConstraintRule(0L, 1, 2, 3L);
    final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(Collections.<DynamicRecord>emptyList(), recordsAfter, rule);
    // when
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(schemaStore, times(1)).setHighestPossibleIdInUse(record.getId());
    verify(schemaStore, times(1)).updateRecord(record);
    verify(metaDataStore, times(1)).setLatestConstraintIntroducingTx(transactionId);
    verify(cacheAccess, times(1)).addSchemaRule(rule);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Example 25 with ConstraintRule

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

the class SchemaRuleCommandTest method shouldSetLatestConstraintRule.

@Test
public void shouldSetLatestConstraintRule() throws Exception {
    // Given
    SchemaRecord beforeRecords = serialize(rule, id, true, true);
    SchemaRecord afterRecords = serialize(rule, id, true, false);
    when(neoStores.getSchemaStore()).thenReturn(schemaStore);
    when(neoStores.getMetaDataStore()).thenReturn(metaDataStore);
    ConstraintRule schemaRule = ConstraintRule.constraintRule(id, ConstraintDescriptorFactory.uniqueForLabel(labelId, propertyKey), 0);
    // WHEN
    visitSchemaRuleCommand(storeApplier, new SchemaRuleCommand(beforeRecords, afterRecords, schemaRule));
    // THEN
    verify(schemaStore).updateRecord(Iterables.first(afterRecords));
    verify(metaDataStore).setLatestConstraintIntroducingTx(txId);
}
Also used : SchemaRuleCommand(org.neo4j.kernel.impl.transaction.command.Command.SchemaRuleCommand) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) 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