Skip to content

Commit c494b11

Browse files
committed
Improve coverage
1 parent 434e451 commit c494b11

6 files changed

Lines changed: 191 additions & 60 deletions

File tree

config/checkstyle/checkstyle.xml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,24 @@
1010
-->
1111
<module name="Checker">
1212
<property name="severity" value="warning"/>
13+
<module name="SuppressionFilter">
14+
<property name="file" value="${project_loc}/config/checkstyle/suppressions.xml"/>
15+
<property name="optional" value="false"/>
16+
</module>
17+
<module name="BeforeExecutionExclusionFileFilter">
18+
<property name="fileNamePattern" value="module\-info\.java$"/>
19+
</module>
1320
<module name="TreeWalker">
14-
<module name="JavadocMethod"/>
1521
<module name="MissingJavadocMethod"/>
22+
<module name="JavadocMethod"/>
1623
<module name="RegexpSinglelineJava">
1724
<property name="severity" value="warning"/>
1825
<property name="format" value="^(?!\s+\* $).*?\s+$"/>
1926
<property name="message" value="Line has trailing spaces."/>
2027
</module>
2128
</module>
22-
<module name="SuppressionFilter">
23-
<property name="file" value="${checkstyle.suppressions.file}"/>
24-
</module>
2529
<module name="Header">
2630
<property name="fileExtensions" value="java"/>
27-
<property name="headerFile" value="${checkstyle.header.file}"/>
28-
</module>
29-
<module name="BeforeExecutionExclusionFileFilter">
30-
<property name="fileNamePattern" value="module\-info\.java$"/>
31+
<property name="headerFile" value="${project_loc}/config/license/HEADER_JAVA"/>
3132
</module>
3233
</module>

config/checkstyle/suppressions.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
<suppressions>
88

9-
<suppress checks="MissingJavadocMethod,JavadocMethod" files="src/main/java/io/reactivex/rxjava4/internal/.*\.java$"/>
10-
<suppress checks="MissingJavadocMethod,JavadocMethod" files="src/test/java/.*\.java$"/>
11-
<suppress checks="MissingJavadocMethod,JavadocMethod" files="src/jmh/java/.*\.java$"/>
9+
<suppress checks="MissingJavadocMethod,JavadocMethod" files=".*[\\/]src[\\/]main[\\/]java[\\/]io[\\/]reactivex[\\/]rxjava4[\\/]internal[\\/].*\.java$"/>
10+
<suppress checks="MissingJavadocMethod,JavadocMethod" files=".*[\\/]src[\\/]test[\\/]java[\\/].*\.java$"/>
11+
<suppress checks="MissingJavadocMethod,JavadocMethod" files=".*[\\/]src[\\/]jmh[\\/]java[\\/].*\.java$"/>
1212
<suppress checks="MissingJavadocMethod,JavadocMethod" files=".*Test\.java$"/>
1313
<suppress checks="MissingJavadocMethod,JavadocMethod" files=".*Perf\.java$"/>
1414

src/test/java/io/reactivex/rxjava4/internal/virtual/FlowableVirtualTransformExecutorTest.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/test/java/io/reactivex/rxjava4/internal/virtual/VirtualInteropTest.java renamed to src/test/java/io/reactivex/rxjava4/internal/virtual/VirtualCreateTest.java

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,19 @@
2929

3030
package io.reactivex.rxjava4.internal.virtual;
3131

32+
import static io.reactivex.rxjava4.testsupport.TestHelper.withVirtual;
3233
import static org.testng.Assert.assertTrue;
3334

35+
import java.io.IOException;
3436
import java.util.concurrent.*;
3537
import java.util.concurrent.atomic.AtomicReference;
3638

3739
import org.junit.Test;
3840

3941
import io.reactivex.rxjava4.core.Flowable;
40-
import io.reactivex.rxjava4.functions.Consumer;
42+
import io.reactivex.rxjava4.schedulers.Schedulers;
4143

42-
public class VirtualInteropTest {
44+
public class VirtualCreateTest {
4345

4446
@Test
4547
public void checkIsInsideVirtualThread() {
@@ -77,9 +79,48 @@ public void plainVirtual() {
7779
assertTrue(result.get());
7880
}
7981

80-
static void withVirtual(Consumer<ExecutorService> call) throws Throwable {
81-
try (var exec = Executors.newThreadPerTaskExecutor(Thread.ofVirtual().factory())) {
82-
call.accept(exec);
83-
}
82+
@Test
83+
public void takeUntil() throws Throwable {
84+
withVirtual(exec -> {
85+
Flowable.<Integer>virtualCreate(e -> {
86+
for (int i = 1; i < 6; i++) {
87+
e.emit(i);
88+
}
89+
}, exec)
90+
.take(2)
91+
.test()
92+
.awaitDone(5, TimeUnit.SECONDS)
93+
.assertResult(1, 2);
94+
});
95+
}
96+
97+
@Test
98+
public void backpressure() throws Throwable {
99+
withVirtual(exec -> {
100+
Flowable.<Integer>virtualCreate(e -> {
101+
for (int i = 0; i < 10000; i++) {
102+
e.emit(i);
103+
}
104+
}, exec)
105+
.observeOn(Schedulers.single(), false, 2)
106+
.test()
107+
.awaitDone(5, TimeUnit.SECONDS)
108+
.assertValueCount(10000)
109+
;
110+
});
111+
}
112+
113+
@Test
114+
public void error() throws Throwable {
115+
withVirtual(exec -> {
116+
Flowable.<Integer>virtualCreate(_ -> {
117+
throw new IOException();
118+
}, exec)
119+
.observeOn(Schedulers.single(), false, 2)
120+
.test()
121+
.awaitDone(5, TimeUnit.SECONDS)
122+
.assertError(IOException.class)
123+
;
124+
});
84125
}
85126
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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.rxjava4.internal.virtual;
15+
16+
import static org.testng.Assert.assertTrue;
17+
18+
import java.io.IOException;
19+
import java.util.concurrent.*;
20+
import java.util.concurrent.atomic.AtomicBoolean;
21+
22+
import org.junit.Test;
23+
24+
import io.reactivex.rxjava4.core.Flowable;
25+
import io.reactivex.rxjava4.schedulers.Schedulers;
26+
import io.reactivex.rxjava4.testsupport.TestHelper;
27+
28+
public class VirtualTransformTest {
29+
30+
@Test
31+
public void checkIsInsideVirtualThread() {
32+
try (var scope = Executors.newVirtualThreadPerTaskExecutor()) {
33+
var cancelled = new AtomicBoolean();
34+
Flowable.range(1, 5)
35+
.doOnCancel(() -> cancelled.set(true))
36+
.virtualTransform((v, emitter) -> emitter.emit(v), scope)
37+
.take(1)
38+
.test()
39+
.awaitDone(5, TimeUnit.SECONDS)
40+
.assertResult(1);
41+
42+
assertTrue(cancelled.get());
43+
}
44+
}
45+
46+
@Test
47+
public void errorUpstream() throws Throwable {
48+
TestHelper.withVirtual(exec -> {
49+
Flowable.error(new IOException())
50+
.virtualTransform((v, e) -> e.emit(v), exec)
51+
.test()
52+
.awaitDone(5, TimeUnit.SECONDS)
53+
.assertError(IOException.class)
54+
;
55+
});
56+
}
57+
58+
@Test
59+
public void errorTransform() throws Throwable {
60+
TestHelper.withVirtual(exec -> {
61+
Flowable.range(1, 5)
62+
.virtualTransform((_, _) -> { throw new IOException(); }, exec)
63+
.test()
64+
.awaitDone(5, TimeUnit.SECONDS)
65+
.assertError(IOException.class)
66+
;
67+
});
68+
}
69+
70+
@Test
71+
public void take() throws Throwable {
72+
TestHelper.withVirtual(exec -> {
73+
Flowable.range(1, 5)
74+
.virtualTransform((v, e) -> e.emit(v), exec)
75+
.take(2)
76+
.test()
77+
.awaitDone(5, TimeUnit.SECONDS)
78+
.assertResult(1, 2)
79+
;
80+
});
81+
}
82+
83+
@Test
84+
public void observeOn() throws Throwable {
85+
TestHelper.withVirtual(exec -> {
86+
Flowable.range(1, 10000)
87+
.virtualTransform((v, e) -> e.emit(v), exec)
88+
.observeOn(Schedulers.single(), false, 2)
89+
.test()
90+
.awaitDone(5, TimeUnit.SECONDS)
91+
.assertNoErrors()
92+
.assertValueCount(10000);
93+
});
94+
}
95+
96+
@Test
97+
public void empty() throws Throwable {
98+
TestHelper.withVirtual(exec -> {
99+
Flowable.empty()
100+
.virtualTransform((v, e) -> e.emit(v), exec)
101+
.test()
102+
.awaitDone(5, TimeUnit.SECONDS)
103+
.assertResult()
104+
;
105+
});
106+
}
107+
108+
@Test
109+
public void emptyNever() throws Throwable {
110+
TestHelper.withVirtual(exec -> {
111+
Flowable.just(1).concatWith(Flowable.never())
112+
.virtualTransform((v, e) -> e.emit(v), exec)
113+
.test()
114+
.awaitDone(1, TimeUnit.SECONDS)
115+
.assertValues(1)
116+
;
117+
});
118+
}
119+
}

src/test/java/io/reactivex/rxjava4/testsupport/TestHelper.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3919,4 +3919,17 @@ public void cancel() {
39193919
upstream.cancel();
39203920
}
39213921
}
3922+
3923+
/**
3924+
* Execute a test body with the help of a virtual thread executor service.
3925+
* <p>
3926+
* Don't forget to {@link ExecutorService#submit(Callable)} your work!
3927+
* @param call the callback to give the VTE.
3928+
* @throws Throwable propagate exceptions
3929+
*/
3930+
public static void withVirtual(Consumer<ExecutorService> call) throws Throwable {
3931+
try (var exec = Executors.newThreadPerTaskExecutor(Thread.ofVirtual().factory())) {
3932+
call.accept(exec);
3933+
}
3934+
}
39223935
}

0 commit comments

Comments
 (0)