Skip to content

Commit 970fe7c

Browse files
committed
simple web flux
1 parent f643309 commit 970fe7c

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

web-flux-and-mono/src/test/java/com/example/demo/FluxTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.example.demo;
22

3+
import org.junit.jupiter.api.Assertions;
34
import org.junit.jupiter.api.Test;
45
import reactor.core.publisher.Flux;
56

@@ -19,6 +20,44 @@ void flux() {
1920
fluxUsers.subscribe(System.out::println);
2021
}
2122

23+
// complete - не выводится так как было прокинуто исключение, которое мы обработали и вывели
24+
@Test
25+
void fluxError_WhenHandleError() {
26+
Flux<Integer> ints = Flux.range(1, 6)
27+
.map(i -> {
28+
if (i <= 3) return i;
29+
throw new RuntimeException("Got to 4");
30+
});
31+
ints.subscribe(
32+
i -> System.out.println(i),
33+
error -> System.err.println("Error: " + error),
34+
() -> System.out.println("complete")
35+
);
36+
}
37+
38+
@Test
39+
void fluxError_WhenNotHandleError() {
40+
Assertions.assertThrows(RuntimeException.class, () -> {
41+
Flux<Integer> ints = Flux.range(1, 6)
42+
.map(i -> {
43+
if (i <= 3) return i;
44+
throw new RuntimeException("Got to 4");
45+
});
46+
ints.subscribe(
47+
i -> System.out.println(i)
48+
);
49+
});
50+
}
51+
52+
@Test
53+
void fluxWithRequestCount() {
54+
Flux<Integer> ints = Flux.range(1, 4);
55+
ints.subscribe(i -> System.out.println(i),
56+
error -> System.err.println("Error " + error),
57+
() -> System.out.println("Done"),
58+
sub -> sub.request(2));
59+
}
60+
2261
@Test
2362
void fluxFilter() {
2463
Flux<User> userFlux = Flux.just(peter, lois, brain);

0 commit comments

Comments
 (0)