use of org.eclipse.collections.api.list.primitive.LongList in project eclipse-collections by eclipse.
the class Collectors2AdditionalTest method collectLongParallel.
@Test
public void collectLongParallel() {
LongList expected = LARGE_INTERVAL.collectLong(Integer::longValue, LongLists.mutable.empty());
LongList actual = this.bigData.parallelStream().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 TokenIndexAccessorTest method readerShouldFindManyWithOtherTokens.
@ParameterizedTest
@EnumSource(IndexOrder.class)
void readerShouldFindManyWithOtherTokens(IndexOrder indexOrder) throws Exception {
// Given
int tokenId = 1;
long[] entityIds = new long[] { 1, 2, 3, 64, 65, 1000, 2001 };
long[] otherEntityIds = new long[] { 1, 2, 4, 64, 66, 1000, 2000 };
addToIndex(tokenId, entityIds);
addToIndex(2, otherEntityIds);
LongList expectedIds = LongLists.immutable.of(entityIds);
// When
assertReaderFindsExpected(indexOrder, tokenId, expectedIds);
}
use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.
the class ParallelNodeLabelScanTestBase method shouldScanAllNodesFromRandomlySizedWorkers.
@Test
void shouldScanAllNodesFromRandomlySizedWorkers() throws InterruptedException {
// given
ExecutorService service = Executors.newFixedThreadPool(4);
Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(FOO_LABEL);
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.allocateNodeLabelIndexCursor(NULL), NODE_GET)));
}
// then
List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
assertDistinct(lists);
assertEquals(FOO_NODES, LongSets.immutable.withAll(concat(lists)));
} finally {
service.shutdown();
service.awaitTermination(1, TimeUnit.MINUTES);
}
}
use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.
the class ParallelNodeLabelScanTransactionStateTestBase method createNodesWithLabel.
private LongList createNodesWithLabel(int label, int size) throws KernelException {
LongList ids;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
ids = createNodesWithLabel(write, label, size);
tx.commit();
}
return ids;
}
use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.
the class ParallelNodeLabelScanTransactionStateTestBase method shouldScanAllNodesFromMultipleThreads.
@Test
void shouldScanAllNodesFromMultipleThreads() throws InterruptedException, ExecutionException, KernelException {
// given
ExecutorService service = Executors.newFixedThreadPool(4);
CursorFactory cursors = testSupport.kernelToTest().cursors();
int size = 1024;
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);
// when
Supplier<NodeLabelIndexCursor> allocateCursor = () -> cursors.allocateNodeLabelIndexCursor(tx.cursorContext());
Future<LongList> future1 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, size / 4));
Future<LongList> future2 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, size / 4));
Future<LongList> future3 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, size / 4));
Future<LongList> future4 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, size / 4));
// 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);
assertEquals(ids.toSortedList(), concat.toSortedList());
tx.rollback();
} finally {
service.shutdown();
service.awaitTermination(1, TimeUnit.MINUTES);
}
}
Aggregations