Search in sources :

Example 1 with TransactionDataBuilder

use of org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder in project neo4j by neo4j.

the class FullCheckIntegrationTest method shouldReportCircularPropertyRecordChain.

private void shouldReportCircularPropertyRecordChain(RecordType expectedInconsistentRecordType, EntityCreator entityCreator) throws Exception {
    // Given
    fixture.apply(new GraphStoreFixture.Transaction() {

        @Override
        protected void transactionData(TransactionDataBuilder tx, IdGenerator next) {
            // Create property chain A --> B --> C --> D
            // ↑           │
            // └───────────┘
            long a = next.property();
            long b = next.property();
            long c = next.property();
            long d = next.property();
            tx.create(propertyRecordWithSingleIntProperty(a, next.propertyKey(), -1, b));
            tx.create(propertyRecordWithSingleIntProperty(b, next.propertyKey(), a, c));
            tx.create(propertyRecordWithSingleIntProperty(c, next.propertyKey(), b, d));
            tx.create(propertyRecordWithSingleIntProperty(d, next.propertyKey(), c, b));
            entityCreator.create(tx, next, a);
        }

        private PropertyRecord propertyRecordWithSingleIntProperty(long id, int propertyKeyId, long prev, long next) {
            PropertyRecord record = new PropertyRecord(id).initialize(true, prev, next);
            PropertyBlock block = new PropertyBlock();
            PropertyStore.encodeValue(block, propertyKeyId, Values.intValue(10), null, null, false, NULL, INSTANCE);
            record.addPropertyBlock(block);
            return record;
        }
    });
    // When
    ConsistencySummaryStatistics stats = check();
    // Then report will be filed on Node inconsistent with the Property completing the circle
    on(stats).verify(expectedInconsistentRecordType, 1);
}
Also used : TransactionDataBuilder(org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) IdGenerator(org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator) GraphStoreFixture(org.neo4j.consistency.checking.GraphStoreFixture) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics)

Example 2 with TransactionDataBuilder

use of org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder in project neo4j by neo4j.

the class FullCheckIntegrationTest method shouldManageUnusedRecordsWithWeirdDataIn.

@Test
void shouldManageUnusedRecordsWithWeirdDataIn() throws Exception {
    // Given
    final AtomicLong id = new AtomicLong();
    fixture.apply(new GraphStoreFixture.Transaction() {

        @Override
        protected void transactionData(TransactionDataBuilder tx, IdGenerator next) {
            id.set(next.relationship());
            RelationshipRecord relationship = new RelationshipRecord(id.get());
            relationship.setFirstNode(-1);
            relationship.setSecondNode(-1);
            relationship.setInUse(true);
            tx.create(relationship);
        }
    });
    fixture.apply(new GraphStoreFixture.Transaction() {

        @Override
        protected void transactionData(TransactionDataBuilder tx, IdGenerator next) {
            RelationshipRecord relationship = new RelationshipRecord(id.get());
            tx.delete(relationship);
        }
    });
    // When
    ConsistencySummaryStatistics stats = check();
    // Then
    assertTrue(stats.isConsistent());
}
Also used : TransactionDataBuilder(org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder) AtomicLong(java.util.concurrent.atomic.AtomicLong) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) IdGenerator(org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator) GraphStoreFixture(org.neo4j.consistency.checking.GraphStoreFixture) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 3 with TransactionDataBuilder

use of org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder in project neo4j by neo4j.

the class FullCheckIntegrationTest method shouldDetectCutOffRelationshipGroupChains.

@Test
void shouldDetectCutOffRelationshipGroupChains() throws Exception {
    fixture.apply(new GraphStoreFixture.Transaction() {

        @Override
        protected void transactionData(TransactionDataBuilder tx, IdGenerator next) {
            // node -> group1 -> group2 -X-> group3 -> group4
            // ^
            // | chain cut off
            long nodeId = next.node();
            long group1Id = next.relationshipGroup();
            long group2Id = next.relationshipGroup();
            long group3Id = next.relationshipGroup();
            long group4Id = next.relationshipGroup();
            int type1 = next.relationshipType();
            int type2 = next.relationshipType();
            int type3 = next.relationshipType();
            int type4 = next.relationshipType();
            NodeRecord node = new NodeRecord(nodeId).initialize(true, NULL_REFERENCE.longValue(), true, group1Id, NO_LABELS_FIELD.longValue());
            RelationshipGroupRecord group1 = new RelationshipGroupRecord(group1Id).initialize(true, type1, NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), nodeId, group2Id);
            RelationshipGroupRecord group2 = new RelationshipGroupRecord(group2Id).initialize(true, type2, NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), nodeId, // cut-off point
            NULL_REFERENCE.longValue());
            RelationshipGroupRecord group3 = new RelationshipGroupRecord(group3Id).initialize(true, type3, NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), nodeId, group4Id);
            RelationshipGroupRecord group4 = new RelationshipGroupRecord(group3Id).initialize(true, type4, NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), nodeId, // correct end of chain
            NULL_REFERENCE.longValue());
            tx.create(node);
            tx.relationshipType(type1, "T1", false);
            tx.relationshipType(type2, "T2", false);
            tx.relationshipType(type3, "T3", false);
            tx.relationshipType(type4, "T4", false);
            tx.create(group1);
            tx.create(group2);
            tx.create(group3);
            tx.create(group4);
        }
    });
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    assertFalse(stats.isConsistent());
    on(stats).verify(RecordType.RELATIONSHIP_GROUP, 1).andThatsAllFolks();
}
Also used : TransactionDataBuilder(org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) IdGenerator(org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator) GraphStoreFixture(org.neo4j.consistency.checking.GraphStoreFixture) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)3 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)3 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)3 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)3 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)1 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)1 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)1 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)1 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)1