use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.
the class ParallelRelationshipCursorTransactionStateTestBase method parallelTxStateScanStressTest.
@Test
void parallelTxStateScanStressTest() throws InterruptedException, KernelException {
LongSet existingRelationships = createRelationships(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 allRels = LongSets.mutable.withAll(existingRelationships);
try (KernelTransaction tx = beginTransaction()) {
int relationshipsInTx = random.nextInt(100);
Write write = tx.dataWrite();
int type = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
for (int j = 0; j < relationshipsInTx; j++) {
allRels.add(write.relationshipCreate(write.nodeCreate(), type, write.nodeCreate()));
}
Scan<RelationshipScanCursor> scan = tx.dataRead().allRelationshipsScan();
List<Future<LongList>> futures = new ArrayList<>(workers);
for (int j = 0; j < workers; j++) {
futures.add(threadPool.submit(randomBatchWorker(scan, () -> cursors.allocateRelationshipScanCursor(NULL), REL_GET)));
}
List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
TestUtils.assertDistinct(lists);
LongList concat = TestUtils.concat(lists);
assertEquals(allRels, LongSets.immutable.withAll(concat), format("relationships=%d, seen=%d, all=%d", relationshipsInTx, concat.size(), allRels.size()));
assertEquals(allRels.size(), concat.size(), format("relationships=%d", relationshipsInTx));
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 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.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.
the class GBPTreeConsistencyCheckerTestBase method shouldDetectChildPointerPointingToChildOwnedByOtherNode.
@Test
void shouldDetectChildPointerPointingToChildOwnedByOtherNode() throws IOException {
try (GBPTree<KEY, VALUE> index = index().build()) {
treeWithHeight(index, 2);
GBPTreeInspection<KEY, VALUE> inspection = inspect(index);
LongList internalNodesWithSiblings = inspection.getNodesPerLevel().get(1);
long targetInternalNode = randomAmong(internalNodesWithSiblings);
long otherInternalNode = randomFromExcluding(internalNodesWithSiblings, targetInternalNode);
int otherChildPos = randomChildPos(inspection, otherInternalNode);
int targetChildPos = randomChildPos(inspection, targetInternalNode);
GBPTreeCorruption.IndexCorruption<KEY, VALUE> corruption = GBPTreeCorruption.copyChildPointerFromOther(targetInternalNode, otherInternalNode, targetChildPos, otherChildPos);
index.unsafe(corruption, NULL);
assertReportAnyStructuralInconsistency(index);
}
}
use of org.eclipse.collections.api.list.primitive.LongList in project eclipse-collections by eclipse.
the class Collectors2AdditionalTest method collectLong.
@Test
public void collectLong() {
LongList expected = SMALL_INTERVAL.collectLong(Integer::longValue, LongLists.mutable.empty());
LongList actual = this.smallData.stream().collect(Collectors2.collectLong(each -> (long) each, LongLists.mutable::empty));
Assert.assertEquals(expected, actual);
}
use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.
the class ParallelNodeCursorTestBase method shouldScanAllNodesFromRandomlySizedWorkers.
@Test
void shouldScanAllNodesFromRandomlySizedWorkers() throws InterruptedException, ExecutionException {
// given
ExecutorService service = Executors.newFixedThreadPool(4);
Scan<NodeCursor> scan = read.allNodesScan();
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.allocateNodeCursor(NULL), NODE_GET)));
}
service.shutdown();
service.awaitTermination(1, TimeUnit.MINUTES);
// then
List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
TestUtils.assertDistinct(lists);
LongList concat = TestUtils.concat(lists).toSortedList();
assertEquals(NODE_IDS, concat);
} finally {
service.shutdown();
service.awaitTermination(1, TimeUnit.MINUTES);
}
}
Aggregations