Search in sources :

Example 1 with CursorFactory

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

the class CachingExpandIntoTest method shouldComputeDegreeWithType.

@Test
void shouldComputeDegreeWithType() throws Exception {
    // GIVEN
    long node;
    int in, out, loop;
    try (KernelTransaction tx = transaction()) {
        Write write = tx.dataWrite();
        node = denseNode(tx);
        TokenWrite tokenWrite = tx.tokenWrite();
        out = tokenWrite.relationshipTypeGetOrCreateForName("OUT");
        in = tokenWrite.relationshipTypeGetOrCreateForName("IN");
        loop = tokenWrite.relationshipTypeGetOrCreateForName("LOOP");
        write.relationshipCreate(node, out, write.nodeCreate());
        write.relationshipCreate(node, out, write.nodeCreate());
        write.relationshipCreate(write.nodeCreate(), in, node);
        write.relationshipCreate(node, loop, node);
        tx.commit();
    }
    try (KernelTransaction tx = transaction()) {
        Read read = tx.dataRead();
        CursorFactory cursors = tx.cursors();
        try (NodeCursor nodes = cursors.allocateNodeCursor(tx.cursorContext())) {
            CachingExpandInto expand = new CachingExpandInto(tx.dataRead(), OUTGOING, MEMORY_TRACKER);
            read.singleNode(node, nodes);
            assertThat(nodes.next()).isEqualTo(true);
            assertThat(nodes.supportsFastDegreeLookup()).isEqualTo(true);
            Degrees degrees = nodes.degrees(ALL_RELATIONSHIPS);
            assertThat(degrees.outgoingDegree(out)).isEqualTo(2);
            assertThat(degrees.outgoingDegree(in)).isEqualTo(0);
            assertThat(degrees.outgoingDegree(loop)).isEqualTo(1);
            assertThat(degrees.incomingDegree(out)).isEqualTo(0);
            assertThat(degrees.incomingDegree(in)).isEqualTo(1);
            assertThat(degrees.incomingDegree(loop)).isEqualTo(1);
            assertThat(degrees.totalDegree(out)).isEqualTo(2);
            assertThat(degrees.totalDegree(in)).isEqualTo(1);
            assertThat(degrees.totalDegree(loop)).isEqualTo(1);
        }
    }
}
Also used : TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) Write(org.neo4j.internal.kernel.api.Write) Read(org.neo4j.internal.kernel.api.Read) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) Degrees(org.neo4j.storageengine.api.Degrees) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 2 with CursorFactory

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

the class ParallelNodeLabelScanTestBase method shouldScanAllNodesFromRandomlySizedWorkers.

@Test
void shouldScanAllNodesFromRandomlySizedWorkers() throws InterruptedException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(FOO_LABEL);
    CursorFactory cursors = testSupport.kernelToTest().cursors();
    try {
        // when
        List<Future<LongList>> futures = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            futures.add(service.submit(randomBatchWorker(scan, () -> cursors.allocateNodeLabelIndexCursor(NULL), NODE_GET)));
        }
        // then
        List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
        assertDistinct(lists);
        assertEquals(FOO_NODES, LongSets.immutable.withAll(concat(lists)));
    } finally {
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) LongList(org.eclipse.collections.api.list.primitive.LongList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) Test(org.junit.jupiter.api.Test)

Example 3 with CursorFactory

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

the class ParallelNodeLabelScanTransactionStateTestBase method shouldScanAllNodesFromMultipleThreads.

@Test
void shouldScanAllNodesFromMultipleThreads() throws InterruptedException, ExecutionException, KernelException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    CursorFactory cursors = testSupport.kernelToTest().cursors();
    int size = 1024;
    try (KernelTransaction tx = beginTransaction()) {
        int label = tx.tokenWrite().labelGetOrCreateForName("L");
        LongList ids = createNodesWithLabel(tx.dataWrite(), label, size);
        Read read = tx.dataRead();
        Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(label);
        // when
        Supplier<NodeLabelIndexCursor> allocateCursor = () -> cursors.allocateNodeLabelIndexCursor(tx.cursorContext());
        Future<LongList> future1 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, size / 4));
        Future<LongList> future2 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, size / 4));
        Future<LongList> future3 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, size / 4));
        Future<LongList> future4 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, size / 4));
        // then
        LongList ids1 = future1.get();
        LongList ids2 = future2.get();
        LongList ids3 = future3.get();
        LongList ids4 = future4.get();
        assertDistinct(ids1, ids2, ids3, ids4);
        LongList concat = concat(ids1, ids2, ids3, ids4);
        assertEquals(ids.toSortedList(), concat.toSortedList());
        tx.rollback();
    } finally {
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : Read(org.neo4j.internal.kernel.api.Read) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) ExecutorService(java.util.concurrent.ExecutorService) LongList(org.eclipse.collections.api.list.primitive.LongList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) Test(org.junit.jupiter.api.Test)

Example 4 with CursorFactory

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

the class ParallelRelationshipCursorTestBase method shouldScanAllRelationshipsFromRandomlySizedWorkers.

@Test
void shouldScanAllRelationshipsFromRandomlySizedWorkers() throws InterruptedException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    Scan<RelationshipScanCursor> scan = read.allRelationshipsScan();
    CursorFactory cursors = testSupport.kernelToTest().cursors();
    try {
        // when
        List<Future<LongList>> futures = new ArrayList<>();
        for (int i = 0; i < 11; i++) {
            futures.add(service.submit(randomBatchWorker(scan, () -> cursors.allocateRelationshipScanCursor(NULL), REL_GET)));
        }
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
        // then
        List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
        assertDistinct(lists);
        LongList concat = concat(lists).toSortedList();
        assertEquals(RELATIONSHIPS, concat);
    } finally {
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) Future(java.util.concurrent.Future) LongList(org.eclipse.collections.api.list.primitive.LongList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) Test(org.junit.jupiter.api.Test)

Example 5 with CursorFactory

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

the class ParallelRelationshipCursorTestBase method shouldScanAllRelationshipsFromMultipleThreadWithBigSizeHints.

@Test
void shouldScanAllRelationshipsFromMultipleThreadWithBigSizeHints() throws InterruptedException, ExecutionException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    Scan<RelationshipScanCursor> scan = read.allRelationshipsScan();
    CursorFactory cursors = testSupport.kernelToTest().cursors();
    try {
        // when
        Supplier<RelationshipScanCursor> allocateRelCursor = () -> cursors.allocateRelationshipScanCursor(NULL);
        Future<LongList> future1 = service.submit(singleBatchWorker(scan, allocateRelCursor, REL_GET, 100));
        Future<LongList> future2 = service.submit(singleBatchWorker(scan, allocateRelCursor, REL_GET, 100));
        Future<LongList> future3 = service.submit(singleBatchWorker(scan, allocateRelCursor, REL_GET, 100));
        Future<LongList> future4 = service.submit(singleBatchWorker(scan, allocateRelCursor, REL_GET, 100));
        // then
        LongList ids1 = future1.get();
        LongList ids2 = future2.get();
        LongList ids3 = future3.get();
        LongList ids4 = future4.get();
        assertDistinct(ids1, ids2, ids3, ids4);
        LongList concat = concat(ids1, ids2, ids3, ids4).toSortedList();
        assertEquals(RELATIONSHIPS, concat);
    } finally {
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) ExecutorService(java.util.concurrent.ExecutorService) LongList(org.eclipse.collections.api.list.primitive.LongList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) Test(org.junit.jupiter.api.Test)

Aggregations

CursorFactory (org.neo4j.internal.kernel.api.CursorFactory)22 Test (org.junit.jupiter.api.Test)21 ExecutorService (java.util.concurrent.ExecutorService)19 LongList (org.eclipse.collections.api.list.primitive.LongList)19 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)13 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)11 Read (org.neo4j.internal.kernel.api.Read)11 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)10 NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)10 ArrayList (java.util.ArrayList)9 Future (java.util.concurrent.Future)9 Write (org.neo4j.internal.kernel.api.Write)9 RelationshipScanCursor (org.neo4j.internal.kernel.api.RelationshipScanCursor)8 NodeLabelIndexCursor (org.neo4j.internal.kernel.api.NodeLabelIndexCursor)5 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)3 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)3 LongSet (org.eclipse.collections.api.set.primitive.LongSet)2 TokenWrite (org.neo4j.internal.kernel.api.TokenWrite)2 Degrees (org.neo4j.storageengine.api.Degrees)2 PropertyCursor (org.neo4j.internal.kernel.api.PropertyCursor)1