use of org.neo4j.internal.kernel.api.NodeLabelIndexCursor in project neo4j by neo4j.
the class ParallelNodeLabelScanTestBase method shouldFailForSizeHintZero.
@Test
void shouldFailForSizeHintZero() {
try (NodeLabelIndexCursor nodes = cursors.allocateNodeLabelIndexCursor(NULL)) {
// given
Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(FOO_LABEL);
// when
assertThrows(IllegalArgumentException.class, () -> scan.reserveBatch(nodes, 0));
}
}
use of org.neo4j.internal.kernel.api.NodeLabelIndexCursor in project neo4j by neo4j.
the class ParallelNodeLabelScanTestBase method shouldScanAllNodesFromMultipleThreads.
@Test
void shouldScanAllNodesFromMultipleThreads() throws InterruptedException, ExecutionException {
// given
ExecutorService service = Executors.newFixedThreadPool(4);
Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(BAR_LABEL);
CursorFactory cursors = testSupport.kernelToTest().cursors();
try {
// when
Supplier<NodeLabelIndexCursor> allocateCursor = () -> cursors.allocateNodeLabelIndexCursor(NULL);
Future<LongList> future1 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, NUMBER_OF_NODES));
Future<LongList> future2 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, NUMBER_OF_NODES));
Future<LongList> future3 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, NUMBER_OF_NODES));
Future<LongList> future4 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, NUMBER_OF_NODES));
// then
LongList ids1 = future1.get();
LongList ids2 = future2.get();
LongList ids3 = future3.get();
LongList ids4 = future4.get();
assertDistinct(ids1, ids2, ids3, ids4);
assertEquals(BAR_NODES, LongSets.immutable.withAll(concat(ids1, ids2, ids3, ids4)));
} finally {
service.shutdown();
service.awaitTermination(1, TimeUnit.MINUTES);
}
}
use of org.neo4j.internal.kernel.api.NodeLabelIndexCursor in project neo4j by neo4j.
the class ParallelNodeLabelScanTestBase method shouldScanAllNodesInBatches.
@Test
void shouldScanAllNodesInBatches() {
// given
try (NodeLabelIndexCursor nodes = cursors.allocateNodeLabelIndexCursor(NULL)) {
// when
Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(FOO_LABEL);
MutableLongList ids = LongLists.mutable.empty();
while (scan.reserveBatch(nodes, 3)) {
while (nodes.next()) {
ids.add(nodes.nodeReference());
}
}
// then
assertEquals(FOO_NODES.size(), ids.size());
assertTrue(FOO_NODES.containsAll(ids));
assertTrue(ids.noneSatisfy(f -> BAR_NODES.contains(f)));
}
}
use of org.neo4j.internal.kernel.api.NodeLabelIndexCursor in project neo4j by neo4j.
the class ParallelNodeLabelScanTransactionStateTestBase method shouldScanAllNodesFromRandomlySizedWorkers.
@Test
void shouldScanAllNodesFromRandomlySizedWorkers() throws InterruptedException, KernelException {
// given
ExecutorService service = Executors.newFixedThreadPool(4);
int size = 2000;
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);
CursorFactory cursors = testSupport.kernelToTest().cursors();
// when
List<Future<LongList>> futures = new ArrayList<>();
for (int i = 0; i < 10; i++) {
futures.add(service.submit(randomBatchWorker(scan, () -> cursors.allocateNodeLabelIndexCursor(tx.cursorContext()), NODE_GET)));
}
// then
List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
assertDistinct(lists);
assertEquals(ids.toSortedList(), concat(lists).toSortedList());
tx.rollback();
} finally {
service.shutdown();
service.awaitTermination(1, TimeUnit.MINUTES);
}
}
use of org.neo4j.internal.kernel.api.NodeLabelIndexCursor in project neo4j by neo4j.
the class ParallelNodeLabelScanTransactionStateTestBase method shouldReserveBatchFromTxState.
@Test
void shouldReserveBatchFromTxState() throws KernelException {
try (KernelTransaction tx = beginTransaction()) {
int label = tx.tokenWrite().labelGetOrCreateForName("L");
createNodesWithLabel(tx.dataWrite(), label, 11);
try (NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
Scan<NodeLabelIndexCursor> scan = tx.dataRead().nodeLabelScan(label);
assertTrue(scan.reserveBatch(cursor, 5));
assertEquals(5, count(cursor));
assertTrue(scan.reserveBatch(cursor, 4));
assertEquals(4, count(cursor));
assertTrue(scan.reserveBatch(cursor, 6));
assertEquals(2, count(cursor));
// now we should have fetched all nodes
while (scan.reserveBatch(cursor, 3)) {
assertFalse(cursor.next());
}
}
}
}
Aggregations