use of org.neo4j.kernel.api.index.NodeUpdates 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.api.index.NodeUpdates 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.api.index.NodeUpdates 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));
}
use of org.neo4j.kernel.api.index.NodeUpdates in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldConvertRemovedPropertyToNodePropertyUpdates.
@Test
public void shouldConvertRemovedPropertyToNodePropertyUpdates() throws Exception {
// GIVEN
NeoStores neoStores = neoStoresRule.open();
int nodeId = 0;
TransactionRecordState recordState = newTransactionRecordState(neoStores);
recordState.nodeCreate(nodeId);
addLabelsToNode(recordState, nodeId, oneLabelId);
DefinedProperty property1 = recordState.nodeAddProperty(nodeId, propertyId1, value1);
DefinedProperty property2 = recordState.nodeAddProperty(nodeId, propertyId2, value2);
apply(neoStores, transactionRepresentationOf(recordState));
// WHEN
recordState = newTransactionRecordState(neoStores);
recordState.nodeRemoveProperty(nodeId, property1.propertyKeyId());
recordState.nodeRemoveProperty(nodeId, property2.propertyKeyId());
Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
// THEN
NodeUpdates expected = NodeUpdates.forNode(nodeId, oneLabelId).removed(property1.propertyKeyId(), property1.value()).removed(property2.propertyKeyId(), property2.value()).build();
assertEquals(expected, Iterables.single(indexUpdates));
}
use of org.neo4j.kernel.api.index.NodeUpdates in project neo4j by neo4j.
the class NeoStoreIndexStoreViewTest method shouldLockNodesWhileReadingThem.
@Test
public void shouldLockNodesWhileReadingThem() throws Exception {
// given
@SuppressWarnings("unchecked") Visitor<NodeUpdates, Exception> visitor = mock(Visitor.class);
StoreScan<Exception> storeScan = storeView.visitNodes(new int[] { labelId }, (id) -> id == propertyKeyId, visitor, null, false);
// when
storeScan.run();
// then
assertEquals("allocated locks: " + lockMocks.keySet(), 2, lockMocks.size());
Lock lock0 = lockMocks.get(0L);
Lock lock1 = lockMocks.get(1L);
assertNotNull("Lock[node=0] never acquired", lock0);
assertNotNull("Lock[node=1] never acquired", lock1);
InOrder order = inOrder(locks, lock0, lock1);
order.verify(locks).acquireNodeLock(0, LockService.LockType.READ_LOCK);
order.verify(lock0).release();
order.verify(locks).acquireNodeLock(1, LockService.LockType.READ_LOCK);
order.verify(lock1).release();
order.verifyNoMoreInteractions();
}
Aggregations