Skip to content

Commit 1089d72

Browse files
authored
Add ParallelismValidation tests (#958)
1 parent fe9c7fa commit 1089d72

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

src/test/java/com/pivovarit/collectors/test/BasicParallelismTest.java

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,21 @@
11
package com.pivovarit.collectors.test;
22

3-
import com.pivovarit.collectors.ParallelCollectors;
43
import com.pivovarit.collectors.TestUtils;
54
import org.junit.jupiter.api.DynamicTest;
65
import org.junit.jupiter.api.TestFactory;
76

87
import java.time.Duration;
98
import java.util.List;
10-
import java.util.concurrent.CompletableFuture;
119
import java.util.function.Supplier;
1210
import java.util.stream.IntStream;
1311
import java.util.stream.Stream;
1412

15-
import static com.pivovarit.collectors.test.Factory.GenericCollector.limitedCollector;
16-
import static com.pivovarit.collectors.test.Factory.e;
17-
import static java.util.stream.Collectors.collectingAndThen;
18-
import static java.util.stream.Collectors.toList;
13+
import static com.pivovarit.collectors.test.Factory.allBounded;
1914
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
2015
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
2116

2217
class BasicParallelismTest {
2318

24-
private static Stream<Factory.GenericCollector<Factory.CollectorFactoryWithParallelism<Integer, Integer>>> allBounded() {
25-
return Stream.of(
26-
limitedCollector("parallel(e, p)", (f, p) -> collectingAndThen(ParallelCollectors.parallel(f, e(), p), c -> c.join().toList())),
27-
limitedCollector("parallel(toList(), e, p)", (f, p) -> collectingAndThen(ParallelCollectors.parallel(f, toList(), e(), p), CompletableFuture::join)),
28-
limitedCollector("parallel(toList(), e, p) [batching]", (f, p) -> collectingAndThen(ParallelCollectors.Batching.parallel(f, toList(), e(), p), CompletableFuture::join)),
29-
limitedCollector("parallelToStream(e, p)", (f, p) -> collectingAndThen(ParallelCollectors.parallelToStream(f, e(), p), Stream::toList)),
30-
limitedCollector("parallelToStream(e, p) [batching]", (f, p) -> collectingAndThen(ParallelCollectors.Batching.parallelToStream(f, e(), p), Stream::toList)),
31-
limitedCollector("parallelToOrderedStream(e, p)", (f, p) -> collectingAndThen(ParallelCollectors.parallelToOrderedStream(f, e(), p), Stream::toList)),
32-
limitedCollector("parallelToOrderedStream(e, p) [batching]", (f, p) -> collectingAndThen(ParallelCollectors.Batching.parallelToOrderedStream(f, e(), p), Stream::toList))
33-
);
34-
}
35-
3619
@TestFactory
3720
Stream<DynamicTest> shouldProcessEmptyWithMaxParallelism() {
3821
return Stream.of(1, 2, 4, 8, 16, 32, 64, 100)

src/test/java/com/pivovarit/collectors/test/Factory.java

+17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import static com.pivovarit.collectors.ParallelCollectors.Batching.parallel;
1414
import static com.pivovarit.collectors.test.Factory.GenericCollector.advancedCollector;
1515
import static com.pivovarit.collectors.test.Factory.GenericCollector.collector;
16+
import static com.pivovarit.collectors.test.Factory.GenericCollector.limitedCollector;
1617
import static java.util.stream.Collectors.collectingAndThen;
1718
import static java.util.stream.Collectors.toList;
1819

@@ -65,6 +66,22 @@ static Stream<Factory.GenericCollector<Factory.CollectorFactory<Integer, Integer
6566
);
6667
}
6768

69+
static Stream<Factory.GenericCollector<Factory.CollectorFactoryWithParallelism<Integer, Integer>>> allBounded() {
70+
return Stream.of(
71+
limitedCollector("parallel(p)", (f, p) -> collectingAndThen(ParallelCollectors.parallel(f, p), c -> c.join().toList())),
72+
limitedCollector("parallel(e, p)", (f, p) -> collectingAndThen(ParallelCollectors.parallel(f, e(), p), c -> c.join().toList())),
73+
limitedCollector("parallel(toList(), p)", (f, p) -> collectingAndThen(ParallelCollectors.parallel(f, toList(), p), CompletableFuture::join)),
74+
limitedCollector("parallel(toList(), e, p)", (f, p) -> collectingAndThen(ParallelCollectors.parallel(f, toList(), e(), p), CompletableFuture::join)),
75+
limitedCollector("parallel(toList(), e, p) [batching]", (f, p) -> collectingAndThen(ParallelCollectors.Batching.parallel(f, toList(), e(), p), CompletableFuture::join)),
76+
limitedCollector("parallelToStream(p)", (f, p) -> collectingAndThen(ParallelCollectors.parallelToStream(f, p), Stream::toList)),
77+
limitedCollector("parallelToStream(e, p)", (f, p) -> collectingAndThen(ParallelCollectors.parallelToStream(f, e(), p), Stream::toList)),
78+
limitedCollector("parallelToStream(e, p) [batching]", (f, p) -> collectingAndThen(ParallelCollectors.Batching.parallelToStream(f, e(), p), Stream::toList)),
79+
limitedCollector("parallelToOrderedStream(p)", (f, p) -> collectingAndThen(ParallelCollectors.parallelToOrderedStream(f, p), Stream::toList)),
80+
limitedCollector("parallelToOrderedStream(e, p)", (f, p) -> collectingAndThen(ParallelCollectors.parallelToOrderedStream(f, e(), p), Stream::toList)),
81+
limitedCollector("parallelToOrderedStream(e, p) [batching]", (f, p) -> collectingAndThen(ParallelCollectors.Batching.parallelToOrderedStream(f, e(), p), Stream::toList))
82+
);
83+
}
84+
6885
public static Stream<GenericCollector<CollectorFactoryWithParallelismAndExecutor<Integer, Integer>>> boundedCollectors() {
6986
return Stream.of(
7087
advancedCollector("parallel()", (f, e, p) -> ParallelCollectors.parallel(f, e, p)),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.pivovarit.collectors.test;
2+
3+
import org.junit.jupiter.api.DynamicTest;
4+
import org.junit.jupiter.api.TestFactory;
5+
6+
import java.util.stream.Stream;
7+
8+
import static com.pivovarit.collectors.test.Factory.allBounded;
9+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
10+
11+
class ParallelismValidationTest {
12+
13+
@TestFactory
14+
Stream<DynamicTest> shouldRejectInvalidRejectedExecutionHandlerFactory() {
15+
return allBounded()
16+
.map(c -> DynamicTest.dynamicTest(c.name(), () -> {
17+
assertThatThrownBy(() -> c.factory()
18+
.collector(i -> i, -1))
19+
.isInstanceOf(IllegalArgumentException.class);
20+
}));
21+
}
22+
}

0 commit comments

Comments
 (0)