Search in sources :

Example 86 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldWriteProperPropertyRecordsWhenOnlyChangingLinkage.

@Test
public void shouldWriteProperPropertyRecordsWhenOnlyChangingLinkage() throws Exception {
    /* There was an issue where GIVEN:
         *
         *   Legend: () = node, [] = property record
         *
         *   ()-->[0:block{size:1}]
         *
         * WHEN adding a new property record in front of if, not changing any data in that record i.e:
         *
         *   ()-->[1:block{size:4}]-->[0:block{size:1}]
         *
         * The state of property record 0 would be that it had loaded value records for that block,
         * but those value records weren't heavy, so writing that record to the log would fail
         * w/ an assertion data != null.
         */
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    int nodeId = 0;
    recordState.nodeCreate(nodeId);
    int index = 0;
    // will require a block of size 1
    recordState.nodeAddProperty(nodeId, index, string(70));
    apply(neoStores, recordState);
    // WHEN
    recordState = newTransactionRecordState(neoStores);
    int index2 = 1;
    // will require a block of size 4
    recordState.nodeAddProperty(nodeId, index2, string(40));
    // THEN
    PhysicalTransactionRepresentation representation = transactionRepresentationOf(recordState);
    representation.accept(command -> ((Command) command).handle(new CommandVisitor.Adapter() {

        @Override
        public boolean visitPropertyCommand(PropertyCommand command) throws IOException {
            verifyPropertyRecord(command.getBefore());
            verifyPropertyRecord(command.getAfter());
            return false;
        }

        private void verifyPropertyRecord(PropertyRecord record) {
            if (record.getPrevProp() != Record.NO_NEXT_PROPERTY.intValue()) {
                for (PropertyBlock block : record) {
                    assertTrue(block.isLight());
                }
            }
        }
    }));
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NeoStores(org.neo4j.kernel.impl.store.NeoStores) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) PropertyCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Example 87 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldConvertLabelAdditionToNodePropertyUpdates.

@Test
public void shouldConvertLabelAdditionToNodePropertyUpdates() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    long nodeId = 0;
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    Object value1 = LONG_STRING, value2 = LONG_STRING.getBytes();
    recordState.nodeCreate(nodeId);
    recordState.nodeAddProperty(nodeId, propertyId1, value1);
    recordState.nodeAddProperty(nodeId, propertyId2, value2);
    apply(neoStores, recordState);
    // WHEN
    recordState = newTransactionRecordState(neoStores);
    addLabelsToNode(recordState, nodeId, oneLabelId);
    Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
    // THEN
    NodeUpdates expected = NodeUpdates.forNode(nodeId, noLabels, oneLabelId).buildWithExistingProperties(Property.stringProperty(propertyId1, LONG_STRING), Property.byteArrayProperty(propertyId2, LONG_STRING.getBytes()));
    assertEquals(expected, Iterables.single(indexUpdates));
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 88 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldConvertMixedLabelRemovalAndRemovePropertyToNodePropertyUpdates.

@Test
public void shouldConvertMixedLabelRemovalAndRemovePropertyToNodePropertyUpdates() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    long nodeId = 0;
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    recordState.nodeCreate(nodeId);
    DefinedProperty property1 = recordState.nodeAddProperty(nodeId, propertyId1, value1);
    DefinedProperty property2 = recordState.nodeAddProperty(nodeId, propertyId2, value2);
    addLabelsToNode(recordState, nodeId, bothLabelIds);
    apply(neoStores, recordState);
    // WHEN
    recordState = newTransactionRecordState(neoStores);
    recordState.nodeRemoveProperty(nodeId, property1.propertyKeyId());
    removeLabelsFromNode(recordState, nodeId, secondLabelId);
    Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
    // THEN
    NodeUpdates expected = NodeUpdates.forNode(nodeId, bothLabelIds, oneLabelId).removed(property1.propertyKeyId(), property1.value()).buildWithExistingProperties(property2);
    assertEquals(expected, Iterables.single(indexUpdates));
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 89 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldConvertAddedPropertyToNodePropertyUpdates.

@Test
public void shouldConvertAddedPropertyToNodePropertyUpdates() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    long nodeId = 0;
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    // WHEN
    recordState.nodeCreate(nodeId);
    addLabelsToNode(recordState, nodeId, oneLabelId);
    recordState.nodeAddProperty(nodeId, propertyId1, value1);
    recordState.nodeAddProperty(nodeId, propertyId2, value2);
    Iterable<NodeUpdates> updates = indexUpdatesOf(neoStores, recordState);
    // THEN
    NodeUpdates expected = NodeUpdates.forNode(nodeId, noLabels, oneLabelId).added(propertyId1, value1).added(propertyId2, value2).build();
    assertEquals(expected, Iterables.single(updates));
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 90 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldConvertChangedPropertyToNodePropertyUpdates.

@Test
public void shouldConvertChangedPropertyToNodePropertyUpdates() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    int nodeId = 0;
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    recordState.nodeCreate(nodeId);
    DefinedProperty property1 = recordState.nodeAddProperty(nodeId, propertyId1, value1);
    DefinedProperty property2 = recordState.nodeAddProperty(nodeId, propertyId2, value2);
    apply(neoStores, transactionRepresentationOf(recordState));
    // WHEN
    String newValue1 = "new", newValue2 = "new 2";
    recordState = newTransactionRecordState(neoStores);
    recordState.nodeChangeProperty(nodeId, property1.propertyKeyId(), newValue1);
    recordState.nodeChangeProperty(nodeId, property2.propertyKeyId(), newValue2);
    Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
    // THEN
    NodeUpdates expected = NodeUpdates.forNode(nodeId).changed(property1.propertyKeyId(), property1.value(), newValue1).changed(property2.propertyKeyId(), property2.value(), newValue2).build();
    assertEquals(expected, Iterables.single(indexUpdates));
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Aggregations

NeoStores (org.neo4j.kernel.impl.store.NeoStores)122 Test (org.junit.Test)46 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)32 Test (org.junit.jupiter.api.Test)25 ArrayList (java.util.ArrayList)17 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)16 PageCache (org.neo4j.io.pagecache.PageCache)16 NodeStore (org.neo4j.kernel.impl.store.NodeStore)15 Transaction (org.neo4j.graphdb.Transaction)14 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)14 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)13 File (java.io.File)11 IOException (java.io.IOException)11 Node (org.neo4j.graphdb.Node)11 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)11 MetaDataStore (org.neo4j.kernel.impl.store.MetaDataStore)10 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)9 PropertyStore (org.neo4j.kernel.impl.store.PropertyStore)9