use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.
the class ParallelNodeCursorTestBase method shouldScanAllNodesFromMultipleThreadWithBigSizeHints.
@Test
void shouldScanAllNodesFromMultipleThreadWithBigSizeHints() throws InterruptedException, ExecutionException {
// given
ExecutorService service = Executors.newFixedThreadPool(4);
Scan<NodeCursor> scan = read.allNodesScan();
CursorFactory cursors = testSupport.kernelToTest().cursors();
try {
// when
Supplier<NodeCursor> allocateNodeCursor = () -> cursors.allocateNodeCursor(NULL);
Future<LongList> future1 = service.submit(singleBatchWorker(scan, allocateNodeCursor, NODE_GET, 100));
Future<LongList> future2 = service.submit(singleBatchWorker(scan, allocateNodeCursor, NODE_GET, 100));
Future<LongList> future3 = service.submit(singleBatchWorker(scan, allocateNodeCursor, NODE_GET, 100));
Future<LongList> future4 = service.submit(singleBatchWorker(scan, allocateNodeCursor, NODE_GET, 100));
// 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.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.
the class ParallelNodeCursorTransactionStateTestBase method parallelTxStateScanStressTest.
@Test
void parallelTxStateScanStressTest() throws InvalidTransactionTypeKernelException, TransactionFailureException, InterruptedException {
LongSet existingNodes = createNodes(77);
int workers = Runtime.getRuntime().availableProcessors();
ExecutorService threadPool = Executors.newFixedThreadPool(workers);
CursorFactory cursors = testSupport.kernelToTest().cursors();
ThreadLocalRandom random = ThreadLocalRandom.current();
try {
for (int i = 0; i < 1000; i++) {
MutableLongSet allNodes = LongSets.mutable.withAll(existingNodes);
try (KernelTransaction tx = beginTransaction()) {
int nodeInTx = random.nextInt(100);
for (int j = 0; j < nodeInTx; j++) {
allNodes.add(tx.dataWrite().nodeCreate());
}
Scan<NodeCursor> scan = tx.dataRead().allNodesScan();
List<Future<LongList>> futures = new ArrayList<>(workers);
for (int j = 0; j < workers; j++) {
futures.add(threadPool.submit(randomBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NODE_GET)));
}
List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
TestUtils.assertDistinct(lists);
LongList concat = TestUtils.concat(lists);
assertEquals(allNodes, LongSets.immutable.withAll(concat), format("nodes=%d, seen=%d, all=%d", nodeInTx, concat.size(), allNodes.size()));
assertEquals(allNodes.size(), concat.size(), format("nodes=%d", nodeInTx));
tx.rollback();
}
}
} finally {
threadPool.shutdown();
threadPool.awaitTermination(1, TimeUnit.MINUTES);
}
}
use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.
the class ParallelNodeCursorTransactionStateTestBase method shouldScanAllNodesFromMultipleThreadWithBigSizeHints.
@Test
void shouldScanAllNodesFromMultipleThreadWithBigSizeHints() throws InterruptedException, ExecutionException, TransactionFailureException, InvalidTransactionTypeKernelException {
// given
ExecutorService service = Executors.newFixedThreadPool(4);
CursorFactory cursors = testSupport.kernelToTest().cursors();
int size = 128;
LongArrayList ids = new LongArrayList();
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
for (int i = 0; i < size; i++) {
ids.add(write.nodeCreate());
}
org.neo4j.internal.kernel.api.Read read = tx.dataRead();
Scan<NodeCursor> scan = read.allNodesScan();
// when
Supplier<NodeCursor> allocateCursor = () -> cursors.allocateNodeCursor(NULL);
Future<LongList> future1 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, 100));
Future<LongList> future2 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, 100));
Future<LongList> future3 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, 100));
Future<LongList> future4 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, 100));
// 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);
assertEquals(ids.toSortedList(), concat.toSortedList());
} finally {
service.shutdown();
service.awaitTermination(1, TimeUnit.MINUTES);
}
}
use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.
the class ParallelRelationshipCursorTestBase method shouldScanAllRelationshipsFromMultipleThreads.
@Test
void shouldScanAllRelationshipsFromMultipleThreads() throws InterruptedException, ExecutionException {
// given
ExecutorService service = Executors.newFixedThreadPool(4);
Scan<RelationshipScanCursor> scan = read.allRelationshipsScan();
CursorFactory cursors = testSupport.kernelToTest().cursors();
try {
// when
Future<LongList> future1 = service.submit(singleBatchWorker(scan, () -> cursors.allocateRelationshipScanCursor(NULL), REL_GET, 32));
Future<LongList> future2 = service.submit(singleBatchWorker(scan, () -> cursors.allocateRelationshipScanCursor(NULL), REL_GET, 32));
Future<LongList> future3 = service.submit(singleBatchWorker(scan, () -> cursors.allocateRelationshipScanCursor(NULL), REL_GET, 32));
Future<LongList> future4 = service.submit(singleBatchWorker(scan, () -> cursors.allocateRelationshipScanCursor(NULL), REL_GET, 32));
// 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);
}
}
use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.
the class ParallelNodeCursorTransactionStateTestBase method shouldScanAllNodesFromMultipleThreads.
@Test
void shouldScanAllNodesFromMultipleThreads() throws InterruptedException, ExecutionException, TransactionFailureException, InvalidTransactionTypeKernelException {
// given
ExecutorService service = Executors.newFixedThreadPool(4);
CursorFactory cursors = testSupport.kernelToTest().cursors();
int size = 128;
LongArrayList ids = new LongArrayList();
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
for (int i = 0; i < size; i++) {
ids.add(write.nodeCreate());
}
org.neo4j.internal.kernel.api.Read read = tx.dataRead();
Scan<NodeCursor> scan = read.allNodesScan();
// when
Future<LongList> future1 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, size / 4));
Future<LongList> future2 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, size / 4));
Future<LongList> future3 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, size / 4));
Future<LongList> future4 = service.submit(singleBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NodeCursor::nodeReference, size / 4));
// 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);
assertEquals(ids.toSortedList(), concat.toSortedList());
tx.rollback();
} finally {
service.shutdown();
service.awaitTermination(1, TimeUnit.MINUTES);
}
}
Aggregations