Search in sources :

Example 21 with NodeItem

use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.

the class StorageLayerPropertyTest method should_get_all_node_properties.

@Test
public void should_get_all_node_properties() throws Exception {
    // GIVEN
    String longString = "AlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalong";
    Object[] properties = { longString, createNew(String.class), createNew(long.class), createNew(int.class), createNew(byte.class), createNew(short.class), createNew(boolean.class), createNew(char.class), createNew(float.class), createNew(double.class), array(0, String.class), array(0, long.class), array(0, int.class), array(0, byte.class), array(0, short.class), array(0, boolean.class), array(0, char.class), array(0, float.class), array(0, double.class), array(1, String.class), array(1, long.class), array(1, int.class), array(1, byte.class), array(1, short.class), array(1, boolean.class), array(1, char.class), array(1, float.class), array(1, double.class), array(256, String.class), array(256, long.class), array(256, int.class), array(256, byte.class), array(256, short.class), array(256, boolean.class), array(256, char.class), array(256, float.class), array(256, double.class) };
    int propKey = disk.propertyKeyGetOrCreateForName("prop");
    StorageStatement statement = state.getStoreStatement();
    for (Object value : properties) {
        // given
        long nodeId = createLabeledNode(db, singletonMap("prop", value), label1).getId();
        // when
        try (Cursor<NodeItem> node = statement.acquireSingleNodeCursor(nodeId)) {
            node.next();
            Lock lock = node.get().lock();
            try (Cursor<PropertyItem> props = statement.acquireSinglePropertyCursor(node.get().nextPropertyId(), propKey, lock)) {
                if (props.next()) {
                    Object propVal = props.get().value();
                    //then
                    assertTrue(propVal + ".valueEquals(" + value + ")", Property.property(propKey, propVal).valueEquals(value));
                } else {
                    fail();
                }
            }
        }
    }
}
Also used : NodeItem(org.neo4j.storageengine.api.NodeItem) StorageStatement(org.neo4j.storageengine.api.StorageStatement) PropertyItem(org.neo4j.storageengine.api.PropertyItem) Lock(org.neo4j.kernel.impl.locking.Lock) Test(org.junit.Test)

Example 22 with NodeItem

use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.

the class StateOperationsAutoIndexingTest method shouldSignalNodePropertyRemovedToAutoIndex.

@Test
public void shouldSignalNodePropertyRemovedToAutoIndex() throws Exception {
    // Given
    PropertyItem existingProperty = mock(PropertyItem.class);
    when(existingProperty.propertyKeyId()).thenReturn(1);
    when(existingProperty.value()).thenReturn("Goodbye!");
    int propertyKeyId = existingProperty.propertyKeyId();
    NodeItem node = mock(NodeItem.class);
    when(storeLayer.nodeGetProperty(eq(storeStmt), any(NodeItem.class), eq(propertyKeyId))).thenReturn(cursor(existingProperty));
    when(node.labels()).thenReturn(PrimitiveIntCollections.emptySet());
    when(storeStmt.acquireSingleNodeCursor(1337)).thenReturn(cursor(node));
    // When
    context.nodeRemoveProperty(stmt, 1337, propertyKeyId);
    // Then
    verify(nodeOps).propertyRemoved(writeOps, 1337L, propertyKeyId);
}
Also used : NodeItem(org.neo4j.storageengine.api.NodeItem) PropertyItem(org.neo4j.storageengine.api.PropertyItem) Test(org.junit.Test)

Example 23 with NodeItem

use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.

the class StateOperationsAutoIndexingTest method shouldSignalNodePropertyAddedToAutoIndex.

@Test
public void shouldSignalNodePropertyAddedToAutoIndex() throws Exception {
    // Given
    DefinedProperty property = property(1, "Hello!");
    NodeItem node = mock(NodeItem.class);
    when(node.labels()).thenReturn(PrimitiveIntCollections.emptySet());
    when(storeStmt.acquireSingleNodeCursor(1337)).thenReturn(cursor(node));
    when(storeLayer.nodeGetProperty(eq(storeStmt), any(NodeItem.class), eq(property.propertyKeyId()))).thenReturn(cursor());
    // When
    context.nodeSetProperty(stmt, 1337, property);
    // Then
    verify(nodeOps).propertyAdded(writeOps, 1337, property);
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NodeItem(org.neo4j.storageengine.api.NodeItem) Test(org.junit.Test)

Example 24 with NodeItem

use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.

the class NeoStoresTest method deleteRelationships.

private void deleteRelationships(long nodeId) throws Exception {
    try (KernelStatement statement = (KernelStatement) tx.acquireStatement();
        Cursor<NodeItem> nodeCursor = statement.getStoreStatement().acquireSingleNodeCursor(nodeId)) {
        assertTrue(nodeCursor.next());
        NodeItem nodeItem = nodeCursor.get();
        statement.getStoreStatement().acquireNodeRelationshipCursor(nodeItem.isDense(), nodeItem.id(), nodeItem.nextRelationshipId(), BOTH, ALWAYS_TRUE_INT).forAll(rel -> relDelete(rel.id()));
    }
}
Also used : NodeItem(org.neo4j.storageengine.api.NodeItem) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement)

Example 25 with NodeItem

use of org.neo4j.storageengine.api.NodeItem 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)

Aggregations

NodeItem (org.neo4j.storageengine.api.NodeItem)25 PropertyItem (org.neo4j.storageengine.api.PropertyItem)10 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)8 Test (org.junit.Test)6 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)6 RelationshipItem (org.neo4j.storageengine.api.RelationshipItem)6 Statement (org.neo4j.kernel.api.Statement)5 PrimitiveIntSet (org.neo4j.collection.primitive.PrimitiveIntSet)4 EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)4 DataWriteOperations (org.neo4j.kernel.api.DataWriteOperations)3 PropertyKeyIdNotFoundKernelException (org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)3 ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)3 NodeExistenceConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.NodeExistenceConstraintDescriptor)3 RelExistenceConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.RelExistenceConstraintDescriptor)3 UniquenessConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor)3 StorageStatement (org.neo4j.storageengine.api.StorageStatement)3 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2 Before (org.junit.Before)2 Cursor (org.neo4j.cursor.Cursor)2