use of org.neo4j.storageengine.api.RelationshipItem in project neo4j by neo4j.
the class TwoPhaseNodeForRelationshipLockingTest method returnRelationships.
static void returnRelationships(EntityReadOperations ops, KernelStatement state, long nodeId, final boolean skipFirst, final RelationshipData... relIds) throws EntityNotFoundException {
NodeItem nodeItem = mock(NodeItem.class);
when(ops.nodeGetRelationships(state, nodeItem, Direction.BOTH)).thenAnswer(new Answer<Cursor<RelationshipItem>>() {
private boolean first = skipFirst;
@Override
public Cursor<RelationshipItem> answer(InvocationOnMock invocation) throws Throwable {
try {
return new Cursor<RelationshipItem>() {
private int i = first ? 1 : 0;
private RelationshipData relationshipData = null;
@Override
public boolean next() {
boolean next = i < relIds.length;
relationshipData = next ? relIds[i++] : null;
return next;
}
@Override
public RelationshipItem get() {
if (relationshipData == null) {
throw new NoSuchElementException();
}
return relationshipData.asRelationshipItem();
}
@Override
public void close() {
}
};
} finally {
first = false;
}
}
});
when(ops.nodeCursorById(state, nodeId)).thenAnswer(invocationOnMock -> {
Cursor<NodeItem> cursor = new Cursor<NodeItem>() {
private int i = 0;
@Override
public boolean next() {
return i++ == 0;
}
@Override
public NodeItem get() {
if (i != 1) {
throw new NoSuchElementException();
}
return nodeItem;
}
@Override
public void close() {
}
};
if (!cursor.next()) {
throw new EntityNotFoundException(EntityType.NODE, nodeId);
}
return cursor;
});
}
use of org.neo4j.storageengine.api.RelationshipItem in project neo4j by neo4j.
the class StateOperationsAutoIndexingTest method shouldSignalRelationshipPropertyAddedToAutoIndex.
@Test
public void shouldSignalRelationshipPropertyAddedToAutoIndex() throws Exception {
// Given
int propertyKeyId = 1;
DefinedProperty property = property(propertyKeyId, "Hello!");
RelationshipItem relationship = mock(RelationshipItem.class);
when(storeStmt.acquireSingleRelationshipCursor(1337)).thenReturn(cursor(relationship));
when(storeLayer.relationshipGetProperty(storeStmt, relationship, propertyKeyId)).thenReturn(empty());
// When
context.relationshipSetProperty(stmt, 1337, property);
// Then
verify(relOps).propertyAdded(writeOps, 1337, property);
}
use of org.neo4j.storageengine.api.RelationshipItem in project neo4j by neo4j.
the class StateOperationsAutoIndexingTest method shouldSignalRelationshipPropertyChangedToAutoIndex.
@Test
public void shouldSignalRelationshipPropertyChangedToAutoIndex() throws Exception {
// Given
int propertyKeyId = 1;
DefinedProperty property = property(propertyKeyId, "Hello!");
PropertyItem existingProperty = mock(PropertyItem.class);
when(existingProperty.propertyKeyId()).thenReturn(property.propertyKeyId());
when(existingProperty.value()).thenReturn("Goodbye!");
RelationshipItem relationship = mock(RelationshipItem.class);
when(storeStmt.acquireSingleRelationshipCursor(1337)).thenReturn(cursor(relationship));
when(storeLayer.relationshipGetProperty(storeStmt, relationship, propertyKeyId)).thenReturn(cursor(existingProperty));
// When
context.relationshipSetProperty(stmt, 1337, property);
// Then
verify(relOps).propertyChanged(eq(writeOps), eq(1337L), any(Property.class), eq(property));
}
use of org.neo4j.storageengine.api.RelationshipItem in project neo4j by neo4j.
the class NeoStoresTest method assertHasRelationships.
private void assertHasRelationships(long node) {
try (KernelStatement statement = (KernelStatement) tx.acquireStatement();
Cursor<NodeItem> nodeCursor = statement.getStoreStatement().acquireSingleNodeCursor(node)) {
nodeCursor.next();
NodeItem nodeItem = nodeCursor.get();
try (Cursor<RelationshipItem> relationships = statement.getStoreStatement().acquireNodeRelationshipCursor(nodeItem.isDense(), nodeItem.id(), nodeItem.nextRelationshipId(), BOTH, ALWAYS_TRUE_INT)) {
assertTrue(relationships.next());
}
}
}
use of org.neo4j.storageengine.api.RelationshipItem in project neo4j by neo4j.
the class NeoStoresTest method relAddProperty.
private DefinedProperty relAddProperty(long relationshipId, int key, Object value) {
DefinedProperty property = Property.property(key, value);
Property oldProperty = Property.noRelationshipProperty(relationshipId, key);
try (StorageStatement statement = storeLayer.newStatement();
Cursor<RelationshipItem> cursor = statement.acquireSingleRelationshipCursor(relationshipId)) {
if (cursor.next()) {
Property fetched = getProperty(key, statement, cursor.get().nextPropertyId());
if (fetched != null) {
oldProperty = fetched;
}
}
}
transaction.relationshipDoReplaceProperty(relationshipId, oldProperty, property);
return property;
}
Aggregations