Search in sources :

Example 1 with CheckedLongProcedure

use of org.eclipse.collections.impl.block.procedure.checked.primitive.CheckedLongProcedure in project neo4j by neo4j.

the class ParallelRelationshipCursorTransactionStateTestBase method scanShouldNotSeeDeletedRelationships.

@Test
void scanShouldNotSeeDeletedRelationships() throws Exception {
    int size = 100;
    MutableLongSet created = LongSets.mutable.empty();
    MutableLongSet deleted = LongSets.mutable.empty();
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        int type = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        for (int i = 0; i < size; i++) {
            created.add(write.relationshipCreate(write.nodeCreate(), type, write.nodeCreate()));
            deleted.add(write.relationshipCreate(write.nodeCreate(), type, write.nodeCreate()));
        }
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        deleted.each(new CheckedLongProcedure() {

            @Override
            public void safeValue(long item) throws Exception {
                tx.dataWrite().relationshipDelete(item);
            }
        });
        try (RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor(NULL)) {
            Scan<RelationshipScanCursor> scan = tx.dataRead().allRelationshipsScan();
            MutableLongSet seen = LongSets.mutable.empty();
            while (scan.reserveBatch(cursor, 17)) {
                while (cursor.next()) {
                    long relationshipId = cursor.relationshipReference();
                    assertTrue(seen.add(relationshipId));
                    assertTrue(created.remove(relationshipId));
                }
            }
            assertTrue(created.isEmpty());
        }
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) CheckedLongProcedure(org.eclipse.collections.impl.block.procedure.checked.primitive.CheckedLongProcedure) ExecutionException(java.util.concurrent.ExecutionException) KernelException(org.neo4j.exceptions.KernelException) TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException) Test(org.junit.jupiter.api.Test)

Example 2 with CheckedLongProcedure

use of org.eclipse.collections.impl.block.procedure.checked.primitive.CheckedLongProcedure in project neo4j by neo4j.

the class ParallelNodeCursorTransactionStateTestBase method scanShouldNotSeeDeletedNode.

@Test
void scanShouldNotSeeDeletedNode() throws Exception {
    int size = 100;
    MutableLongSet created = LongSets.mutable.empty();
    MutableLongSet deleted = LongSets.mutable.empty();
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        for (int i = 0; i < size; i++) {
            created.add(write.nodeCreate());
            deleted.add(write.nodeCreate());
        }
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        deleted.each(new CheckedLongProcedure() {

            @Override
            public void safeValue(long item) throws Exception {
                tx.dataWrite().nodeDelete(item);
            }
        });
        try (NodeCursor cursor = tx.cursors().allocateNodeCursor(NULL)) {
            Scan<NodeCursor> scan = tx.dataRead().allNodesScan();
            MutableLongSet seen = LongSets.mutable.empty();
            while (scan.reserveBatch(cursor, 17)) {
                while (cursor.next()) {
                    long nodeId = cursor.nodeReference();
                    assertTrue(seen.add(nodeId));
                    assertTrue(created.remove(nodeId));
                }
            }
            assertTrue(created.isEmpty());
        }
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) CheckedLongProcedure(org.eclipse.collections.impl.block.procedure.checked.primitive.CheckedLongProcedure) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) ExecutionException(java.util.concurrent.ExecutionException) TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException) Test(org.junit.jupiter.api.Test)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)2 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)2 CheckedLongProcedure (org.eclipse.collections.impl.block.procedure.checked.primitive.CheckedLongProcedure)2 Test (org.junit.jupiter.api.Test)2 Write (org.neo4j.internal.kernel.api.Write)2 TransactionFailureException (org.neo4j.internal.kernel.api.exceptions.TransactionFailureException)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2 KernelException (org.neo4j.exceptions.KernelException)1 NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)1 RelationshipScanCursor (org.neo4j.internal.kernel.api.RelationshipScanCursor)1 InvalidTransactionTypeKernelException (org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException)1