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));
}
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));
}
Aggregations