File tree Expand file tree Collapse file tree 2 files changed +28
-19
lines changed
src/test/java/hu/akarnokd/asyncenum Expand file tree Collapse file tree 2 files changed +28
-19
lines changed Original file line number Diff line number Diff line change 33import org .junit .Test ;
44
55import java .util .List ;
6- import java .util .concurrent .ForkJoinPool ;
6+ import java .util .concurrent .* ;
77
88import static org .junit .Assert .assertEquals ;
99import static org .junit .Assert .assertTrue ;
@@ -12,16 +12,20 @@ public class AsyncObserveOnTest {
1212
1313 @ Test
1414 public void simple () {
15- List <String > list = AsyncEnumerable .range (1 , 5 )
16- .observeOn (ForkJoinPool .commonPool ())
17- .map (v -> v + " " + Thread .currentThread ().getName ())
18- .toList ()
19- .blockingFirst ();
15+ ExecutorService exec = Executors .newSingleThreadExecutor (r -> new Thread (r , "CustomPool" ));
16+ try {
17+ List <String > list = AsyncEnumerable .range (1 , 5 )
18+ .observeOn (exec )
19+ .map (v -> v + " " + Thread .currentThread ().getName ())
20+ .toList ()
21+ .blockingFirst ();
2022
21- assertEquals (5 , list .size ());
22- for (String s : list ) {
23- assertTrue (s , s .contains ("ForkJoinPool" ));
23+ assertEquals (5 , list .size ());
24+ for (String s : list ) {
25+ assertTrue (s , s .contains ("CustomPool" ));
26+ }
27+ } finally {
28+ exec .shutdownNow ();
2429 }
25-
2630 }
2731}
Original file line number Diff line number Diff line change 33import org .junit .Test ;
44
55import java .util .List ;
6- import java .util .concurrent .ForkJoinPool ;
6+ import java .util .concurrent .* ;
77
88import static org .junit .Assert .assertEquals ;
99import static org .junit .Assert .assertTrue ;
@@ -12,15 +12,20 @@ public class AsyncSubscribeOnTest {
1212
1313 @ Test
1414 public void simple () {
15- List <String > list = AsyncEnumerable .range (1 , 5 )
16- .subscribeOn (ForkJoinPool .commonPool ())
17- .map (v -> v + " " + Thread .currentThread ().getName ())
18- .toList ()
19- .blockingFirst ();
15+ ExecutorService exec = Executors .newSingleThreadExecutor (r -> new Thread (r , "CustomPool" ));
16+ try {
17+ List <String > list = AsyncEnumerable .range (1 , 5 )
18+ .subscribeOn (exec )
19+ .map (v -> v + " " + Thread .currentThread ().getName ())
20+ .toList ()
21+ .blockingFirst ();
2022
21- assertEquals (5 , list .size ());
22- for (String s : list ) {
23- assertTrue (s , s .contains ("ForkJoinPool" ));
23+ assertEquals (5 , list .size ());
24+ for (String s : list ) {
25+ assertTrue (s , s .contains ("CustomPool" ));
26+ }
27+ } finally {
28+ exec .shutdownNow ();
2429 }
2530 }
2631}
You can’t perform that action at this time.
0 commit comments