Search in sources :

Example 21 with RelationshipScanCursor

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

the class RelationshipScanCursorTestBase method shouldNotAccessNegativeReferences.

// This is functionality which is only required for the hacky db.schema not to leak real data
@Test
void shouldNotAccessNegativeReferences() {
    // given
    try (RelationshipScanCursor relationship = cursors.allocateRelationshipScanCursor(NULL)) {
        // when
        read.singleRelationship(-2L, relationship);
        // then
        assertFalse(relationship.next(), "should not access negative reference relationship");
    }
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) Test(org.junit.jupiter.api.Test)

Example 22 with RelationshipScanCursor

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

the class RelationshipScanCursorTestBase method shouldAccessNodes.

@Test
void shouldAccessNodes() {
    // given
    try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
        // when
        read.singleRelationship(one, relationships);
        // then
        assertTrue(relationships.next());
        assertEquals(c, relationships.sourceNodeReference());
        assertEquals(d, relationships.targetNodeReference());
        assertFalse(relationships.next());
        // when
        read.singleRelationship(loop, relationships);
        // then
        assertTrue(relationships.next());
        assertEquals(relationships.sourceNodeReference(), relationships.targetNodeReference());
        assertFalse(relationships.next());
    }
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) Test(org.junit.jupiter.api.Test)

Example 23 with RelationshipScanCursor

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

the class RelationshipTransactionStateTestBase method shouldSeeAddedPropertyFromExistingRelationshipWithoutPropertiesInTransaction.

@Test
void shouldSeeAddedPropertyFromExistingRelationshipWithoutPropertiesInTransaction() throws Exception {
    // Given
    long relationshipId;
    String propKey = "prop1";
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        relationshipId = write.relationshipCreate(write.nodeCreate(), tx.tokenWrite().relationshipTypeGetOrCreateForName("R"), write.nodeCreate());
        tx.commit();
    }
    // When/Then
    try (KernelTransaction tx = beginTransaction()) {
        int propToken = tx.token().propertyKeyGetOrCreateForName(propKey);
        assertEquals(tx.dataWrite().relationshipSetProperty(relationshipId, propToken, stringValue("hello")), 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("hello"));
            assertFalse(property.next(), "should only find one 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("hello");
    }
}
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 24 with RelationshipScanCursor

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

the class RelationshipTransactionStateTestBase method propertyTypeShouldBeTxStateAware.

@Test
void propertyTypeShouldBeTxStateAware() 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 relationships = tx.cursors().allocateRelationshipScanCursor(NULL);
            PropertyCursor properties = tx.cursors().allocatePropertyCursor(NULL, INSTANCE)) {
            tx.dataRead().singleRelationship(relationship, relationships);
            assertTrue(relationships.next());
            assertFalse(hasProperties(relationships, tx));
            int prop = tx.tokenWrite().propertyKeyGetOrCreateForName("prop");
            tx.dataWrite().relationshipSetProperty(relationship, prop, stringValue("foo"));
            relationships.properties(properties);
            assertTrue(properties.next());
            assertThat(properties.propertyType()).isEqualTo(ValueGroup.TEXT);
        }
    }
}
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 25 with RelationshipScanCursor

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

the class RelationshipTransactionStateTestBase method shouldNotScanRelationshipWhichWasDeletedInTransaction.

@Test
void shouldNotScanRelationshipWhichWasDeletedInTransaction() throws Exception {
    final int nRelationshipsInStore = 5 + 1 + 5;
    int type;
    long n1, n2, r;
    try (KernelTransaction tx = beginTransaction()) {
        n1 = tx.dataWrite().nodeCreate();
        n2 = tx.dataWrite().nodeCreate();
        type = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        relateNTimes(5, type, n1, n2, tx);
        r = tx.dataWrite().relationshipCreate(n1, type, n2);
        relateNTimes(5, type, n1, n2, tx);
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        assertTrue(tx.dataWrite().relationshipDelete(r), "should delete relationship");
        try (RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor(NULL)) {
            tx.dataRead().allRelationshipsScan(relationship);
            assertCountRelationships(relationship, nRelationshipsInStore - 1, n1, type, n2);
        }
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) 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