use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class ParallelRelationshipCursorTestBase method shouldFailForSizeHintZero.
@Test
void shouldFailForSizeHintZero() {
try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
// given
Scan<RelationshipScanCursor> scan = read.allRelationshipsScan();
// when
assertThrows(IllegalArgumentException.class, () -> scan.reserveBatch(relationships, 0));
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor 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);
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class ParallelRelationshipCursorTestBase method shouldScanASubsetOfRelationships.
@Test
void shouldScanASubsetOfRelationships() {
try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
// when
Scan<RelationshipScanCursor> scan = read.allRelationshipsScan();
assertTrue(scan.reserveBatch(relationships, 3));
assertTrue(relationships.next());
assertEquals(RELATIONSHIPS.get(0), relationships.relationshipReference());
assertTrue(relationships.next());
assertEquals(RELATIONSHIPS.get(1), relationships.relationshipReference());
assertTrue(relationships.next());
assertEquals(RELATIONSHIPS.get(2), relationships.relationshipReference());
assertFalse(relationships.next());
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class ParallelRelationshipCursorTestBase method shouldHandleSizeHintOverflow.
@Test
void shouldHandleSizeHintOverflow() {
try (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor(NULL)) {
// when
Scan<RelationshipScanCursor> scan = read.allRelationshipsScan();
assertTrue(scan.reserveBatch(relationships, NUMBER_OF_RELATIONSHIPS * 2));
LongArrayList ids = new LongArrayList();
while (relationships.next()) {
ids.add(relationships.relationshipReference());
}
assertEquals(RELATIONSHIPS, ids);
}
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor 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);
}
}
Aggregations