Search in sources :

Example 16 with RelationshipItem

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;
    });
}
Also used : EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) Cursor(org.neo4j.cursor.Cursor) NodeItem(org.neo4j.storageengine.api.NodeItem) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem) NoSuchElementException(java.util.NoSuchElementException)

Example 17 with RelationshipItem

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);
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem) Test(org.junit.Test)

Example 18 with RelationshipItem

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));
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) PropertyItem(org.neo4j.storageengine.api.PropertyItem) Property(org.neo4j.kernel.api.properties.Property) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem) Test(org.junit.Test)

Example 19 with RelationshipItem

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());
        }
    }
}
Also used : NodeItem(org.neo4j.storageengine.api.NodeItem) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Example 20 with RelationshipItem

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;
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) StorageStatement(org.neo4j.storageengine.api.StorageStatement) Property(org.neo4j.kernel.api.properties.Property) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Aggregations

RelationshipItem (org.neo4j.storageengine.api.RelationshipItem)20 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)7 PropertyItem (org.neo4j.storageengine.api.PropertyItem)6 NodeItem (org.neo4j.storageengine.api.NodeItem)5 Test (org.junit.Test)4 Property (org.neo4j.kernel.api.properties.Property)4 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)3 StorageProperty (org.neo4j.storageengine.api.StorageProperty)3 NodeState (org.neo4j.storageengine.api.txstate.NodeState)3 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2 HashMap (java.util.HashMap)2 NoSuchElementException (java.util.NoSuchElementException)2 DataWriteOperations (org.neo4j.kernel.api.DataWriteOperations)2 EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)2 PropertyKeyIdNotFoundKernelException (org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Cursor (org.neo4j.cursor.Cursor)1 NotFoundException (org.neo4j.graphdb.NotFoundException)1 Relationship (org.neo4j.graphdb.Relationship)1