Search in sources :

Example 41 with RelationshipScanCursor

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

the class RelationshipScanCursorTestBase method shouldNotAccessDeletedRelationship.

@Test
void shouldNotAccessDeletedRelationship() {
    // given
    try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
        // when
        read.singleRelationship(none, relationships);
        // then
        assertFalse(relationships.next(), "should not access deleted relationship");
    }
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) Test(org.junit.jupiter.api.Test)

Example 42 with RelationshipScanCursor

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

the class RelationshipTransactionStateTestBase method shouldNotSeeSingleRelationshipWhichWasDeletedInTransaction.

@Test
void shouldNotSeeSingleRelationshipWhichWasDeletedInTransaction() throws Exception {
    int label;
    long n1, n2, r;
    try (KernelTransaction tx = beginTransaction()) {
        n1 = tx.dataWrite().nodeCreate();
        n2 = tx.dataWrite().nodeCreate();
        label = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        long decoyNode = tx.dataWrite().nodeCreate();
        // to have >1 relationship in the db
        tx.dataWrite().relationshipCreate(n2, label, decoyNode);
        r = tx.dataWrite().relationshipCreate(n1, label, n2);
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        assertTrue(tx.dataWrite().relationshipDelete(r), "should delete relationship");
        try (RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor(NULL)) {
            tx.dataRead().singleRelationship(r, relationship);
            assertFalse(relationship.next(), "should not find relationship");
        }
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) Test(org.junit.jupiter.api.Test)

Example 43 with RelationshipScanCursor

use of org.neo4j.internal.kernel.api.RelationshipScanCursor 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 44 with RelationshipScanCursor

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

the class RelationshipTransactionStateTestBase method hasPropertiesShouldSeeNewlyCreatedPropertiesOnNewlyCreatedRelationship.

@Test
void hasPropertiesShouldSeeNewlyCreatedPropertiesOnNewlyCreatedRelationship() throws Exception {
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        int token = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        long relationship = write.relationshipCreate(write.nodeCreate(), token, write.nodeCreate());
        try (RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor(NULL)) {
            tx.dataRead().singleRelationship(relationship, cursor);
            assertTrue(cursor.next());
            assertFalse(hasProperties(cursor, tx));
            tx.dataWrite().relationshipSetProperty(relationship, tx.tokenWrite().propertyKeyGetOrCreateForName("prop"), stringValue("foo"));
            assertTrue(hasProperties(cursor, tx));
        }
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) Test(org.junit.jupiter.api.Test)

Example 45 with RelationshipScanCursor

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

the class DefaultPooledCursorsTestBase method shouldReuseRelationshipScanCursor.

@Test
void shouldReuseRelationshipScanCursor() {
    RelationshipScanCursor c1 = cursors.allocateRelationshipScanCursor(NULL);
    read.singleRelationship(relationship, c1);
    c1.close();
    RelationshipScanCursor c2 = cursors.allocateRelationshipScanCursor(NULL);
    assertThat(c1).isSameAs(c2);
    c2.close();
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) Test(org.junit.jupiter.api.Test)

Aggregations

RelationshipScanCursor (org.neo4j.internal.kernel.api.RelationshipScanCursor)53 Test (org.junit.jupiter.api.Test)40 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)28 PropertyCursor (org.neo4j.internal.kernel.api.PropertyCursor)16 Write (org.neo4j.internal.kernel.api.Write)16 CursorFactory (org.neo4j.internal.kernel.api.CursorFactory)8 ExecutorService (java.util.concurrent.ExecutorService)7 LongList (org.eclipse.collections.api.list.primitive.LongList)7 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 Read (org.neo4j.internal.kernel.api.Read)4 Future (java.util.concurrent.Future)3 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)3 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)3 TokenRead (org.neo4j.internal.kernel.api.TokenRead)3 KernelException (org.neo4j.exceptions.KernelException)2 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1