use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldConvertMixedLabelAdditionAndSetPropertyToNodePropertyUpdates.
@Test
public void shouldConvertMixedLabelAdditionAndSetPropertyToNodePropertyUpdates() throws Exception {
// GIVEN
NeoStores neoStores = neoStoresRule.open();
long nodeId = 0;
TransactionRecordState recordState = newTransactionRecordState(neoStores);
recordState.nodeCreate(nodeId);
recordState.nodeAddProperty(nodeId, propertyId1, value1);
addLabelsToNode(recordState, nodeId, oneLabelId);
apply(neoStores, recordState);
// WHEN
recordState = newTransactionRecordState(neoStores);
recordState.nodeAddProperty(nodeId, propertyId2, value2);
addLabelsToNode(recordState, nodeId, secondLabelId);
Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
// THEN
NodeUpdates expected = NodeUpdates.forNode(nodeId, oneLabelId, bothLabelIds).added(propertyId2, value2).buildWithExistingProperties(Property.stringProperty(propertyId1, value1));
assertEquals(expected, Iterables.single(indexUpdates));
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldConvertLabelRemovalToNodePropertyUpdates.
@Test
public void shouldConvertLabelRemovalToNodePropertyUpdates() throws Exception {
// GIVEN
NeoStores neoStores = neoStoresRule.open();
long nodeId = 0;
TransactionRecordState recordState = newTransactionRecordState(neoStores);
recordState.nodeCreate(nodeId);
recordState.nodeAddProperty(nodeId, propertyId1, value1);
recordState.nodeAddProperty(nodeId, propertyId2, value2);
addLabelsToNode(recordState, nodeId, oneLabelId);
apply(neoStores, recordState);
// WHEN
recordState = newTransactionRecordState(neoStores);
removeLabelsFromNode(recordState, nodeId, oneLabelId);
Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
// THEN
NodeUpdates expected = NodeUpdates.forNode(nodeId, oneLabelId, noLabels).buildWithExistingProperties(Property.stringProperty(propertyId1, value1), Property.intProperty(propertyId2, value2));
assertEquals(expected, Iterables.single(indexUpdates));
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldLockUpdatedNodes.
@Test
public void shouldLockUpdatedNodes() throws Exception {
// given
LockService locks = mock(LockService.class, new Answer<Object>() {
@Override
public synchronized Object answer(final InvocationOnMock invocation) throws Throwable {
// This is necessary because finalize() will also be called
String name = invocation.getMethod().getName();
if (name.equals("acquireNodeLock") || name.equals("acquireRelationshipLock")) {
return mock(Lock.class, (Answer) invocationOnMock -> null);
}
return null;
}
});
NeoStores neoStores = neoStoresRule.open();
NodeStore nodeStore = neoStores.getNodeStore();
long[] nodes = { // allocate ids
nodeStore.nextId(), nodeStore.nextId(), nodeStore.nextId(), nodeStore.nextId(), nodeStore.nextId(), nodeStore.nextId(), nodeStore.nextId() };
{
// create the node records that we will modify in our main tx.
TransactionRecordState tx = newTransactionRecordState(neoStores);
for (int i = 1; i < nodes.length - 1; i++) {
tx.nodeCreate(nodes[i]);
}
tx.nodeAddProperty(nodes[3], 0, "old");
tx.nodeAddProperty(nodes[4], 0, "old");
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), locks);
apply(applier, transaction(tx));
}
reset(locks);
// These are the changes we want to assert locking on
TransactionRecordState tx = newTransactionRecordState(neoStores);
tx.nodeCreate(nodes[0]);
tx.addLabelToNode(0, nodes[1]);
tx.nodeAddProperty(nodes[2], 0, "value");
tx.nodeChangeProperty(nodes[3], 0, "value");
tx.nodeRemoveProperty(nodes[4], 0);
tx.nodeDelete(nodes[5]);
tx.nodeCreate(nodes[6]);
tx.addLabelToNode(0, nodes[6]);
tx.nodeAddProperty(nodes[6], 0, "value");
//commit( tx );
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), locks);
apply(applier, transaction(tx));
// then
// create node, NodeCommand == 1 update
verify(locks, times(1)).acquireNodeLock(nodes[0], LockService.LockType.WRITE_LOCK);
// add label, NodeCommand == 1 update
verify(locks, times(1)).acquireNodeLock(nodes[1], LockService.LockType.WRITE_LOCK);
// add property, NodeCommand and PropertyCommand == 2 updates
verify(locks, times(2)).acquireNodeLock(nodes[2], LockService.LockType.WRITE_LOCK);
// update property, in place, PropertyCommand == 1 update
verify(locks, times(1)).acquireNodeLock(nodes[3], LockService.LockType.WRITE_LOCK);
// remove property, updates the Node and the Property == 2 updates
verify(locks, times(2)).acquireNodeLock(nodes[4], LockService.LockType.WRITE_LOCK);
// delete node, single NodeCommand == 1 update
verify(locks, times(1)).acquireNodeLock(nodes[5], LockService.LockType.WRITE_LOCK);
// create and add-label goes into the NodeCommand, add property is a PropertyCommand == 2 updates
verify(locks, times(2)).acquireNodeLock(nodes[6], LockService.LockType.WRITE_LOCK);
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithTheSameTypeDifferentDirection.
@Test
public void shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithTheSameTypeDifferentDirection() throws Exception {
// GIVEN a node with a total of denseNodeThreshold-1 relationships
NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "49");
TransactionRecordState tx = newTransactionRecordState(neoStores);
long nodeId = neoStores.getNodeStore().nextId();
int typeA = 0;
tx.nodeCreate(nodeId);
tx.createRelationshipTypeToken("A", typeA);
createRelationships(neoStores, tx, nodeId, typeA, OUTGOING, 24);
createRelationships(neoStores, tx, nodeId, typeA, INCOMING, 25);
// here we're at the edge
assertFalse(recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData().isDense());
// WHEN creating the relationship that pushes us over the threshold
createRelationships(neoStores, tx, nodeId, typeA, INCOMING, 1);
// THEN the node should have been converted into a dense node
assertTrue(recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData().isDense());
assertDenseRelationshipCounts(recordChangeSet, nodeId, typeA, 24, 26);
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldExtractUpdateCommandsInCorrectOrder.
@Test
public void shouldExtractUpdateCommandsInCorrectOrder() throws Throwable {
// GIVEN
NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "1");
TransactionRecordState recordState = newTransactionRecordState(neoStores);
long nodeId = 0, relId1 = 1, relId2 = 2, relId3 = 3;
recordState.nodeCreate(nodeId);
recordState.relCreate(relId1, 0, nodeId, nodeId);
recordState.relCreate(relId2, 0, nodeId, nodeId);
recordState.nodeAddProperty(nodeId, 0, 101);
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
apply(applier, transaction(recordState));
recordState = newTransactionRecordState(neoStores);
recordState.nodeChangeProperty(nodeId, 0, 102);
recordState.relCreate(relId3, 0, nodeId, nodeId);
recordState.relAddProperty(relId1, 0, 123);
// WHEN
Collection<StorageCommand> commands = new ArrayList<>();
recordState.extractCommands(commands);
// THEN
Iterator<StorageCommand> commandIterator = commands.iterator();
// added rel property
assertCommand(commandIterator.next(), PropertyCommand.class);
// created relationship relId3
assertCommand(commandIterator.next(), RelationshipCommand.class);
// rest is updates...
assertCommand(commandIterator.next(), PropertyCommand.class);
assertCommand(commandIterator.next(), RelationshipCommand.class);
assertCommand(commandIterator.next(), RelationshipCommand.class);
assertCommand(commandIterator.next(), Command.RelationshipGroupCommand.class);
assertCommand(commandIterator.next(), NodeCommand.class);
assertFalse(commandIterator.hasNext());
}
Aggregations