Search in sources :

Example 31 with RelationshipScanCursor

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

the class RelationshipTransactionStateTestBase method shouldSeeUpdatedPropertyFromExistingRelationshipWithPropertiesInTransaction.

@Test
void shouldSeeUpdatedPropertyFromExistingRelationshipWithPropertiesInTransaction() 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().relationshipSetProperty(relationshipId, propToken, stringValue("world")), stringValue("hello"));
        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 only find one property");
            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 32 with RelationshipScanCursor

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

the class RelationshipTransactionStateTestBase method hasPropertiesShouldSeeNewlyCreatedProperties.

@Test
void hasPropertiesShouldSeeNewlyCreatedProperties() throws Exception {
    // Given
    long relationship;
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        int token = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        relationship = write.relationshipCreate(write.nodeCreate(), token, write.nodeCreate());
        tx.commit();
    }
    // Then
    try (KernelTransaction tx = beginTransaction()) {
        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 33 with RelationshipScanCursor

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

the class RelationshipTransactionStateTestBase method shouldSeeAddedPropertyFromExistingRelationshipWithPropertiesInTransaction.

@Test
void shouldSeeAddedPropertyFromExistingRelationshipWithPropertiesInTransaction() throws Exception {
    // Given
    long relationshipId;
    String propKey1 = "prop1";
    String propKey2 = "prop2";
    int propToken1;
    int propToken2;
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        relationshipId = write.relationshipCreate(write.nodeCreate(), tx.tokenWrite().relationshipTypeGetOrCreateForName("R"), write.nodeCreate());
        propToken1 = tx.token().propertyKeyGetOrCreateForName(propKey1);
        assertEquals(write.relationshipSetProperty(relationshipId, propToken1, stringValue("hello")), NO_VALUE);
        tx.commit();
    }
    // When/Then
    try (KernelTransaction tx = beginTransaction()) {
        propToken2 = tx.token().propertyKeyGetOrCreateForName(propKey2);
        assertEquals(tx.dataWrite().relationshipSetProperty(relationshipId, propToken2, 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);
            while (property.next()) {
                if (// from disk
                property.propertyKey() == propToken1) {
                    assertEquals(property.propertyValue(), stringValue("hello"));
                } else if (// from tx state
                property.propertyKey() == propToken2) {
                    assertEquals(property.propertyValue(), stringValue("world"));
                } else {
                    fail(property.propertyKey() + " was not the property you were looking for");
                }
            }
            assertFalse(relationship.next(), "should only find one relationship");
        }
        tx.commit();
    }
    try (org.neo4j.graphdb.Transaction transaction = graphDb.beginTx()) {
        Relationship relationship = transaction.getRelationshipById(relationshipId);
        assertThat(relationship.getProperty(propKey1)).isEqualTo("hello");
        assertThat(relationship.getProperty(propKey2)).isEqualTo("world");
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) Relationship(org.neo4j.graphdb.Relationship) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 34 with RelationshipScanCursor

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

the class RelationshipTransactionStateTestBase method shouldNotSeeRemovedPropertyInTransaction.

@Test
void shouldNotSeeRemovedPropertyInTransaction() 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"));
        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);
            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()) {
        assertFalse(transaction.getRelationshipById(relationshipId).hasProperty(propKey));
    }
}
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 35 with RelationshipScanCursor

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

the class ParallelRelationshipCursorTestBase method shouldScanAllRelationshipsInBatches.

@Test
void shouldScanAllRelationshipsInBatches() {
    // given
    LongArrayList ids = new LongArrayList();
    try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
        // when
        Scan<RelationshipScanCursor> scan = read.allRelationshipsScan();
        while (scan.reserveBatch(relationships, 3)) {
            while (relationships.next()) {
                ids.add(relationships.relationshipReference());
            }
        }
    }
    // then
    assertEquals(RELATIONSHIPS, ids);
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) 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