use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class ParallelNodeCursorTestBase method shouldScanAllNodesFromMultipleThreads.
@Test
void shouldScanAllNodesFromMultipleThreads() throws InterruptedException, ExecutionException {
// given
ExecutorService service = Executors.newFixedThreadPool(4);
Scan<NodeCursor> scan = read.allNodesScan();
CursorFactory cursors = testSupport.kernelToTest().cursors();
try {
// when
Future<LongList> future1 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, 32));
Future<LongList> future2 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, 32));
Future<LongList> future3 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, 32));
Future<LongList> future4 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, 32));
// then
LongList ids1 = future1.get();
LongList ids2 = future2.get();
LongList ids3 = future3.get();
LongList ids4 = future4.get();
TestUtils.assertDistinct(ids1, ids2, ids3, ids4);
LongList concat = TestUtils.concat(ids1, ids2, ids3, ids4).toSortedList();
assertEquals(NODE_IDS, concat);
} finally {
service.shutdown();
service.awaitTermination(1, TimeUnit.MINUTES);
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class ParallelNodeCursorTransactionStateTestBase method scanShouldSeeAddedNodes.
@Test
void scanShouldSeeAddedNodes() throws Exception {
int size = 100;
MutableLongSet existing = createNodes(size);
MutableLongSet added = LongSets.mutable.empty();
try (KernelTransaction tx = beginTransaction()) {
for (int i = 0; i < size; i++) {
added.add(tx.dataWrite().nodeCreate());
}
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(existing.remove(nodeId) || added.remove(nodeId));
}
}
// make sure we have seen all nodes
assertTrue(existing.isEmpty());
assertTrue(added.isEmpty());
}
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class KernelReadTracerTest method shouldTraceRelationshipTraversal.
@Test
void shouldTraceRelationshipTraversal() {
// given
TestKernelReadTracer tracer = new TestKernelReadTracer();
try (NodeCursor nodeCursor = cursors.allocateNodeCursor(NULL);
RelationshipTraversalCursor cursor = cursors.allocateRelationshipTraversalCursor(NULL)) {
// when
cursor.setTracer(tracer);
read.singleNode(foo, nodeCursor);
assertTrue(nodeCursor.next());
nodeCursor.relationships(cursor, ALL_RELATIONSHIPS);
assertTrue(cursor.next());
tracer.assertEvents(OnRelationship(cursor.relationshipReference()));
cursor.removeTracer();
assertTrue(cursor.next());
tracer.assertEvents();
cursor.setTracer(tracer);
assertTrue(cursor.next());
tracer.assertEvents(OnRelationship(cursor.relationshipReference()));
// skip last two
assertTrue(cursor.next());
assertTrue(cursor.next());
tracer.clear();
assertFalse(cursor.next());
tracer.assertEvents();
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class ManagedTestCursors method allocateFullAccessNodeCursor.
@Override
public NodeCursor allocateFullAccessNodeCursor(CursorContext cursorContext) {
NodeCursor n = cursors.allocateFullAccessNodeCursor(cursorContext);
allCursors.add(n);
return n;
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class ManagedTestCursors method allocateNodeCursor.
@Override
public NodeCursor allocateNodeCursor(CursorContext cursorContext) {
NodeCursor n = cursors.allocateNodeCursor(cursorContext);
allCursors.add(n);
return n;
}
Aggregations