Search in sources :

Example 26 with PropertyCursor

use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.

the class PropertyCursorTestBase method shouldNotAccessNonExistentNodeProperties.

@Test
void shouldNotAccessNonExistentNodeProperties() {
    // given
    try (NodeCursor node = cursors.allocateNodeCursor(NULL);
        PropertyCursor props = cursors.allocatePropertyCursor(NULL, INSTANCE)) {
        // when
        read.singleNode(bareNodeId, node);
        assertTrue(node.next(), "node by reference");
        assertFalse(hasProperties(node, props), "no properties");
        node.properties(props);
        assertFalse(props.next(), "no properties by direct method");
        read.nodeProperties(node.nodeReference(), node.propertiesReference(), props);
        assertFalse(props.next(), "no properties via property ref");
        assertFalse(node.next(), "only one node");
    }
}
Also used : NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 27 with PropertyCursor

use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.

the class PropertyCursorTestBase method shouldAccessAllRelationshipProperties.

@Test
void shouldAccessAllRelationshipProperties() {
    // given
    try (RelationshipScanCursor relationship = cursors.allocateRelationshipScanCursor(NULL);
        PropertyCursor props = cursors.allocatePropertyCursor(NULL, INSTANCE)) {
        // when
        read.singleRelationship(allPropsRelId, relationship);
        assertTrue(relationship.next(), "relationship by reference");
        assertTrue(hasProperties(relationship, props), "has properties");
        relationship.properties(props);
        Set<Object> values = new HashSet<>();
        while (props.next()) {
            values.add(props.propertyValue().asObject());
        }
        assertTrue(values.contains((byte) 13), BYTE_PROP);
        assertTrue(values.contains((short) 13), SHORT_PROP);
        assertTrue(values.contains(13), INT_PROP);
        assertTrue(values.contains(13L), INLINE_LONG_PROP);
        assertTrue(values.contains(Long.MAX_VALUE), LONG_PROP);
        assertTrue(values.contains(13.0f), FLOAT_PROP);
        assertTrue(values.contains(13.0), DOUBLE_PROP);
        assertTrue(values.contains(true), TRUE_PROP);
        assertTrue(values.contains(false), FALSE_PROP);
        assertTrue(values.contains('x'), CHAR_PROP);
        assertTrue(values.contains(""), EMPTY_STRING_PROP);
        assertTrue(values.contains("hello"), SHORT_STRING_PROP);
        assertTrue(values.contains(chinese), UTF_8_PROP);
        if (supportsBigProperties()) {
            assertTrue(values.contains(LONG_STRING), LONG_STRING_PROP);
            assertThat(values).as(SMALL_ARRAY_PROP).contains(new int[] { 1, 2, 3, 4 });
            assertThat(values).as(BIG_ARRAY_PROP).contains(LONG_STRING);
        }
        assertTrue(values.contains(pointValue), POINT_PROP);
        assertTrue(values.contains(dateValue.asObject()), DATE_PROP);
        int expected = supportsBigProperties() ? 18 : 15;
        assertEquals(expected, values.size(), "number of values");
    }
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 28 with PropertyCursor

use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.

the class PropertyCursorTestBase method shouldNotAccessNonExistentRelationshipProperties.

@Test
void shouldNotAccessNonExistentRelationshipProperties() {
    try (RelationshipScanCursor relationship = cursors.allocateRelationshipScanCursor(NULL);
        PropertyCursor props = cursors.allocatePropertyCursor(NULL, INSTANCE)) {
        // when
        read.singleRelationship(bareRelId, relationship);
        assertTrue(relationship.next(), "relationship by reference");
        assertFalse(hasProperties(relationship, props), "no properties");
        relationship.properties(props);
        assertFalse(props.next(), "no properties by direct method");
        read.relationshipProperties(relationship.relationshipReference(), relationship.propertiesReference(), props);
        assertFalse(props.next(), "no properties via property ref");
        assertFalse(relationship.next(), "only one node");
    }
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 29 with PropertyCursor

use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.

the class RelationshipTransactionStateTestBase method shouldSeeRemovedThenAddedPropertyInTransaction.

@Test
void shouldSeeRemovedThenAddedPropertyInTransaction() throws Exception {
    // Given
    long relationshipId;
    String propKey = "prop1";
    int propToken;
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        relationshipId = write.relationshipCreate(write.nodeCreate(), tx.tokenWrite().relationshipTypeGetOrCreateForName("R"), write.nodeCreate());
        propToken = tx.token().propertyKeyGetOrCreateForName(propKey);
        assertEquals(write.relationshipSetProperty(relationshipId, propToken, stringValue("hello")), NO_VALUE);
        tx.commit();
    }
    // When/Then
    try (KernelTransaction tx = beginTransaction()) {
        assertEquals(tx.dataWrite().relationshipRemoveProperty(relationshipId, propToken), stringValue("hello"));
        assertEquals(tx.dataWrite().relationshipSetProperty(relationshipId, propToken, stringValue("world")), NO_VALUE);
        try (RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor(NULL);
            PropertyCursor property = tx.cursors().allocatePropertyCursor(NULL, INSTANCE)) {
            tx.dataRead().singleRelationship(relationshipId, relationship);
            assertTrue(relationship.next(), "should access relationship");
            relationship.properties(property);
            assertTrue(property.next());
            assertEquals(propToken, property.propertyKey());
            assertEquals(property.propertyValue(), stringValue("world"));
            assertFalse(property.next(), "should not find any properties");
            assertFalse(relationship.next(), "should only find one relationship");
        }
        tx.commit();
    }
    try (org.neo4j.graphdb.Transaction transaction = graphDb.beginTx()) {
        assertThat(transaction.getRelationshipById(relationshipId).getProperty(propKey)).isEqualTo("world");
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 30 with PropertyCursor

use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.

the class LabelsAcceptanceTest method shouldAllowManyLabelsAndPropertyCursor.

@Test
void shouldAllowManyLabelsAndPropertyCursor() {
    int propertyCount = 10;
    int labelCount = 15;
    Node node;
    try (Transaction tx = db.beginTx()) {
        node = tx.createNode();
        for (int i = 0; i < propertyCount; i++) {
            node.setProperty("foo" + i, "bar");
        }
        for (int i = 0; i < labelCount; i++) {
            node.addLabel(label("label" + i));
        }
        tx.commit();
    }
    Set<Integer> seenProperties = new HashSet<>();
    Set<Integer> seenLabels = new HashSet<>();
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        try (NodeCursor nodes = ktx.cursors().allocateNodeCursor(CursorContext.NULL);
            PropertyCursor propertyCursor = ktx.cursors().allocatePropertyCursor(CursorContext.NULL, INSTANCE)) {
            ktx.dataRead().singleNode(node.getId(), nodes);
            while (nodes.next()) {
                nodes.properties(propertyCursor);
                while (propertyCursor.next()) {
                    seenProperties.add(propertyCursor.propertyKey());
                }
                TokenSet labels = nodes.labels();
                for (int i = 0; i < labels.numberOfTokens(); i++) {
                    seenLabels.add(labels.token(i));
                }
            }
        }
        tx.commit();
    }
    assertEquals(propertyCount, seenProperties.size());
    assertEquals(labelCount, seenLabels.size());
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TokenSet(org.neo4j.internal.kernel.api.TokenSet) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

PropertyCursor (org.neo4j.internal.kernel.api.PropertyCursor)48 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)33 NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)30 Test (org.junit.jupiter.api.Test)29 RelationshipScanCursor (org.neo4j.internal.kernel.api.RelationshipScanCursor)16 Write (org.neo4j.internal.kernel.api.Write)7 TokenRead (org.neo4j.internal.kernel.api.TokenRead)4 Value (org.neo4j.values.storable.Value)4 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 MutableIntSet (org.eclipse.collections.api.set.primitive.MutableIntSet)2 IntHashSet (org.eclipse.collections.impl.set.mutable.primitive.IntHashSet)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2 RelationshipTraversalCursor (org.neo4j.internal.kernel.api.RelationshipTraversalCursor)2 EntityNotFoundException (org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException)2 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)2 Values.stringValue (org.neo4j.values.storable.Values.stringValue)2 Node (org.neo4j.graphdb.Node)1 Relationship (org.neo4j.graphdb.Relationship)1