use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldPrepareRelevantRecords.
@Test
public void shouldPrepareRelevantRecords() throws Exception {
// GIVEN
PrepareTrackingRecordFormats format = new PrepareTrackingRecordFormats(Standard.LATEST_RECORD_FORMATS);
NeoStores neoStores = neoStoresRule.open(format, GraphDatabaseSettings.dense_node_threshold.name(), "1");
// WHEN
TransactionRecordState state = newTransactionRecordState(neoStores);
state.nodeCreate(0);
state.relCreate(0, 0, 0, 0);
state.relCreate(1, 0, 0, 0);
state.relCreate(2, 0, 0, 0);
List<StorageCommand> commands = new ArrayList<>();
state.extractCommands(commands);
// THEN
int nodes = 0, rels = 0, groups = 0;
for (StorageCommand command : commands) {
if (command instanceof NodeCommand) {
assertTrue(format.node().prepared(((NodeCommand) command).getAfter()));
nodes++;
} else if (command instanceof RelationshipCommand) {
assertTrue(format.relationship().prepared(((RelationshipCommand) command).getAfter()));
rels++;
} else if (command instanceof RelationshipGroupCommand) {
assertTrue(format.relationshipGroup().prepared(((RelationshipGroupCommand) command).getAfter()));
groups++;
}
}
assertEquals(1, nodes);
assertEquals(3, rels);
assertEquals(1, groups);
}
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());
}
}
}
}));
}
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));
}
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));
}
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));
}
Aggregations