Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/jdk8/ParallelFlatMapStreamTest.java

raw
1 /*
2 * Copyright (c) 2016-present, RxJava Contributors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11 * the License for the specific language governing permissions and limitations under the License.
12 */
13
14 package io.reactivex.rxjava3.internal.jdk8;
15
16 import java.util.stream.Stream;
17
18 import org.junit.Test;
19
20 import io.reactivex.rxjava3.core.*;
21 import io.reactivex.rxjava3.parallel.ParallelFlowableTest;
22
23 public class ParallelFlatMapStreamTest extends RxJavaTest {
24
25 @Test
26 public void subscriberCount() {
27 ParallelFlowableTest.checkSubscriberCount(Flowable.range(1, 5).parallel()
28 .flatMapStream(v -> Stream.of(1, 2, 3)));
29 }
30
31 @Test
32 public void normal() {
33 for (int i = 1; i < 32; i++) {
34 Flowable.range(1, 1000)
35 .parallel(i)
36 .flatMapStream(v -> Stream.of(v, v + 1))
37 .sequential()
38 .test()
39 .withTag("Parallelism: " + i)
40 .assertValueCount(2000)
41 .assertNoErrors()
42 .assertComplete();
43 }
44 }
45
46 @Test
47 public void none() {
48 for (int i = 1; i < 32; i++) {
49 Flowable.range(1, 1000)
50 .parallel(i)
51 .flatMapStream(v -> Stream.of())
52 .sequential()
53 .test()
54 .withTag("Parallelism: " + i)
55 .assertResult();
56 }
57 }
58
59 @Test
60 public void mixed() {
61 for (int i = 1; i < 32; i++) {
62 Flowable.range(1, 1000)
63 .parallel(i)
64 .flatMapStream(v -> v % 2 == 0 ? Stream.of(v) : Stream.of())
65 .sequential()
66 .test()
67 .withTag("Parallelism: " + i)
68 .assertValueCount(500)
69 .assertNoErrors()
70 .assertComplete();
71 }
72 }
73 }