├── .github
└── workflows
│ └── build.yml
├── .gitignore
├── README.md
├── flux-mono
├── .gitignore
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── mynotes
│ │ │ └── spring
│ │ │ └── fluxmono
│ │ │ └── FluxMonoApplication.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── mynotes
│ └── spring
│ ├── fluxmono
│ ├── BackPressureTest.java
│ ├── CombiningTest.java
│ ├── ErrorTest.java
│ ├── FilterTest.java
│ ├── FluxAndMonoFactoryMethods.java
│ ├── FluxMonoApplicationTest.java
│ ├── InfiniteStream.java
│ ├── MapTest.java
│ ├── TestUtils.java
│ └── VirtualTimeTest.java
│ └── reactor
│ └── ThreadLocalReactive.java
├── gateway
├── .gitignore
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── gateway
│ │ │ ├── GatewayApplication.java
│ │ │ └── configuration
│ │ │ └── SecurityConfiguration.java
│ └── resources
│ │ └── application.properties
│ └── test
│ ├── java
│ └── com
│ │ └── example
│ │ └── gateway
│ │ └── configuration
│ │ └── SecurityConfigurationIT.java
│ └── resources
│ └── application.yml
├── pom.xml
├── reactive-db-mongo
├── .gitignore
├── Readme.md
├── docker-compose.yml
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── djcodes
│ │ │ └── spring
│ │ │ └── reactivedb
│ │ │ ├── ReactiveDbApplication.java
│ │ │ ├── controller
│ │ │ └── ReservationController.java
│ │ │ ├── document
│ │ │ └── Reservation.java
│ │ │ └── repository
│ │ │ └── ReservationRepository.java
│ └── resources
│ │ └── application.yml
│ └── test
│ └── java
│ └── com
│ └── djcodes
│ └── spring
│ └── reactivedb
│ ├── ReactiveDbApplicationTests.java
│ ├── controller
│ └── ReservationControllerTest.java
│ └── repository
│ └── ReservationRepositoryTest.java
├── reactive-db-postgres
├── .gitignore
├── Readme.md
├── docker-compose.yml
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── djcodes
│ │ │ └── spring
│ │ │ └── reactivedb
│ │ │ ├── ReactiveDbApplication.java
│ │ │ └── postgres
│ │ │ ├── Reservation.java
│ │ │ ├── ReservationRepository.java
│ │ │ ├── ReservationService.java
│ │ │ └── SampleDataInitializer.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── djcodes
│ └── spring
│ └── reactivedb
│ └── ReactiveDbApplicationTests.java
├── reactive-producer-consumer
├── pom.xml
├── reactive-web-consumer
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── mynotes
│ │ │ │ └── spring
│ │ │ │ └── reactive
│ │ │ │ └── reactivewebapp
│ │ │ │ ├── Hobby.java
│ │ │ │ ├── Person.java
│ │ │ │ ├── ReactiveWebAppApplication.java
│ │ │ │ ├── calls
│ │ │ │ ├── CallPersonUsingRestTemplate.java
│ │ │ │ ├── CallPersonUsingWebClient_Step1.java
│ │ │ │ ├── CallPersonUsingWebClient_Step2.java
│ │ │ │ ├── CallPersonUsingWebClient_Step3.java
│ │ │ │ └── CallPersonUsingWebClient_Step4.java
│ │ │ │ ├── exception
│ │ │ │ └── ExceptionClient.java
│ │ │ │ └── steps
│ │ │ │ ├── Step1.java
│ │ │ │ ├── Step2a.java
│ │ │ │ ├── Step2a1.java
│ │ │ │ ├── Step2a2.java
│ │ │ │ ├── Step2b.java
│ │ │ │ ├── Step2c.java
│ │ │ │ ├── Step2d.java
│ │ │ │ ├── Step2e.java
│ │ │ │ └── Step3a.java
│ │ └── resources
│ │ │ ├── application.properties
│ │ │ └── logback.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── mynotes
│ │ └── spring
│ │ └── reactive
│ │ └── reactivewebapp
│ │ └── ReactiveWebAppApplicationTests.java
└── reactive-web-producer
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── mynotes
│ │ │ └── spring
│ │ │ └── reactive
│ │ │ ├── Application.java
│ │ │ ├── controller
│ │ │ ├── CalculateController.java
│ │ │ ├── ExceptionController.java
│ │ │ ├── FluxMonoController.java
│ │ │ ├── GreetReactiveController.java
│ │ │ ├── Greeting.java
│ │ │ ├── HttpBinController.java
│ │ │ ├── Person.java
│ │ │ └── PersonController.java
│ │ │ ├── dto
│ │ │ └── CalculateResponseDTO.java
│ │ │ ├── exception
│ │ │ └── ControllerExceptionHandler.java
│ │ │ ├── handler
│ │ │ └── HandlerFunctions.java
│ │ │ ├── router
│ │ │ └── RouterFunctionConfig.java
│ │ │ └── service
│ │ │ ├── CalculateService.java
│ │ │ └── HttpBinService.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── mynotes
│ └── spring
│ └── reactive
│ ├── controller
│ ├── CalculateControllerTest.java
│ ├── ExceptionControllerTest.java
│ ├── FluxMonoControllerTests.java
│ ├── HttpBinControllerMockWebServerTest.java
│ └── HttpBinControllerWireMockTest.java
│ ├── router
│ └── RouterTests.java
│ └── service
│ ├── HttpBinServiceMockServerNettyTest.java
│ ├── HttpBinServiceMockWebServerTest.java
│ └── HttpBinServiceWireMockTest.java
├── reactive-web
├── .gitignore
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── reactive
│ │ │ └── reactiveweb
│ │ │ ├── FunctionalJavaConfiguration.java
│ │ │ ├── Greeting.java
│ │ │ ├── GreetingsRestController.java
│ │ │ ├── ReactiveWebApplication.java
│ │ │ └── WebSocketConfiguration.java
│ └── resources
│ │ ├── application.properties
│ │ └── static
│ │ └── client.html
│ └── test
│ └── java
│ └── com
│ └── example
│ └── reactive
│ └── reactiveweb
│ └── ReactiveWebApplicationTests.java
└── webflux-in-servlet
├── .gitignore
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── mynotes
│ │ └── reactive
│ │ └── demo
│ │ └── webfluxinservlet
│ │ └── controller
│ │ ├── WebfluxInServletApplication.java
│ │ ├── controller
│ │ ├── ApiController.java
│ │ └── HttpBinController.java
│ │ └── exceptions
│ │ ├── AppExceptionHandler.java
│ │ ├── RestTemplateCustomException.java
│ │ ├── RestTemplateResponseErrorHandler.java
│ │ └── WebClientCustomException.java
└── resources
│ └── application.properties
└── test
└── java
└── com
└── mynotes
└── reactive
└── demo
└── webfluxinservlet
└── controller
├── ApiControllerIT.java
└── HttpBinControllerIT.java
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a Java project with Maven
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3 |
4 | name: Java CI with Maven
5 |
6 | on:
7 | push:
8 | branches:
9 | - master
10 | - main
11 | pull_request:
12 |
13 |
14 | jobs:
15 | build:
16 | runs-on: ubuntu-latest
17 | steps:
18 | - name: Checkout
19 | uses: actions/checkout@v3
20 |
21 | - name: Build
22 | uses: actions/setup-java@v3
23 | with:
24 | distribution: 'temurin'
25 | java-version: '17'
26 | cache: 'maven'
27 | - run: mvn -pl gateway clean install
28 |
29 |
30 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 | .mvn
4 | mvn*
5 | .DS_Store
6 | ### STS ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeansrequest.getHeader("X-
13 | .sts4-cache
14 | .
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /build/
25 | /nbbuild/
26 | /dist/
27 | /nbdist/
28 | /.nb-gradle/
29 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # spring-reactive
2 |
--------------------------------------------------------------------------------
/flux-mono/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 | !**/src/main/**/target/
5 | !**/src/test/**/target/
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /nbbuild/
25 | /dist/
26 | /nbdist/
27 | /.nb-gradle/
28 | build/
29 | !**/src/main/**/build/
30 | !**/src/test/**/build/
31 |
32 | ### VS Code ###
33 | .vscode/
34 |
--------------------------------------------------------------------------------
/flux-mono/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.7.8
9 |
10 |
11 | com.mynotes.spring
12 | flux-mono
13 | 0.0.1-SNAPSHOT
14 | flux-mono
15 | Demo project for Spring Boot
16 |
17 |
18 | 11
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-webflux
25 |
26 |
27 | org.apache.commons
28 | commons-lang3
29 |
30 |
31 | org.projectlombok
32 | lombok
33 | true
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-starter-test
38 | test
39 |
40 |
41 | org.junit.vintage
42 | junit-vintage-engine
43 |
44 |
45 |
46 |
47 | io.projectreactor
48 | reactor-test
49 | test
50 |
51 |
52 |
53 |
54 |
55 |
56 | org.springframework.boot
57 | spring-boot-maven-plugin
58 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/flux-mono/src/main/java/com/mynotes/spring/fluxmono/FluxMonoApplication.java:
--------------------------------------------------------------------------------
1 | package com.mynotes.spring.fluxmono;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class FluxMonoApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(FluxMonoApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/flux-mono/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/flux-mono/src/test/java/com/mynotes/spring/fluxmono/BackPressureTest.java:
--------------------------------------------------------------------------------
1 | package com.mynotes.spring.fluxmono;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import reactor.core.publisher.BaseSubscriber;
5 | import reactor.core.publisher.Flux;
6 | import reactor.test.StepVerifier;
7 |
8 | public class BackPressureTest {
9 |
10 | @Test
11 | public void backPressureTest(){
12 | Flux flux = Flux.range(1,10).log();
13 |
14 | StepVerifier.create(flux)
15 | .expectSubscription()
16 | .expectNext(1)
17 | .thenRequest(1)
18 | .expectNext(2)
19 | .thenRequest(1)
20 | .expectNext(3)
21 | .thenCancel()
22 | .verify();
23 |
24 | }
25 |
26 | @Test
27 | public void backPressureTest_subscribe(){
28 | Flux flux = Flux.range(1,10).log();
29 |
30 | flux.subscribe(
31 | element -> System.out.println("Element :: "+element),
32 | exception -> System.out.println("Error"),
33 | () -> System.out.println("Complete"),
34 | subscription -> subscription.request(2));
35 | }
36 |
37 | @Test
38 | public void backPressureTest_custom(){
39 | Flux flux = Flux.range(1,10).log();
40 |
41 | flux.subscribe(new BaseSubscriber() {
42 | @Override
43 | protected void hookOnNext(Integer value) {
44 | request(1);
45 | System.out.println("Value received = "+ value);
46 | if(value==4){
47 | cancel();
48 | }
49 | }
50 | });
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/flux-mono/src/test/java/com/mynotes/spring/fluxmono/CombiningTest.java:
--------------------------------------------------------------------------------
1 | package com.mynotes.spring.fluxmono;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import reactor.core.publisher.Flux;
5 | import reactor.test.StepVerifier;
6 |
7 | import java.time.Duration;
8 | import java.util.List;
9 |
10 | public class CombiningTest {
11 |
12 | @Test
13 | public void combineUsingMerge(){
14 |
15 | Flux flux1 = Flux.just("a","b","c");
16 | Flux flux2 = Flux.just("d","e","f");
17 |
18 |
19 | Flux finalFlux = Flux.merge(flux1,flux2).log();
20 |
21 | StepVerifier.create(finalFlux)
22 | .expectNext("a","b","c","d","e","f")
23 | .verifyComplete();
24 | }
25 |
26 | @Test
27 | public void combineUsingMerge_delay(){
28 |
29 | Flux flux1 = Flux.just("a","b","c").delayElements(Duration.ofSeconds(1));
30 | Flux flux2 = Flux.just("d","e","f").delayElements(Duration.ofSeconds(1));
31 |
32 |
33 | Flux finalFlux = Flux.merge(flux1,flux2).log();
34 |
35 | StepVerifier.create(finalFlux)
36 | .expectNextCount(6)
37 | .verifyComplete();
38 | }
39 |
40 | @Test
41 | public void combineUsingContact(){
42 |
43 | Flux flux1 = Flux.just("a","b","c").delayElements(Duration.ofSeconds(1));
44 | Flux flux2 = Flux.just("d","e","f").delayElements(Duration.ofSeconds(1));
45 |
46 |
47 | Flux finalFlux = Flux.concat(flux1,flux2).log();
48 |
49 | StepVerifier.create(finalFlux)
50 | .expectNext("a","b","c","d","e","f")
51 | .verifyComplete();
52 | }
53 |
54 | @Test
55 | public void combineUsingZip(){
56 |
57 | Flux flux1 = Flux.just("a","b","c").delayElements(Duration.ofSeconds(1));
58 | Flux flux2 = Flux.just("d","e","f").delayElements(Duration.ofSeconds(2));
59 |
60 |
61 | Flux finalFlux = Flux.zip(flux1,flux2, (t1, t2) -> {
62 | return t1.concat(t2);
63 | }).log();
64 |
65 | StepVerifier.create(finalFlux)
66 | .expectNext("ad","be","cf")
67 | .verifyComplete();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/flux-mono/src/test/java/com/mynotes/spring/fluxmono/ErrorTest.java:
--------------------------------------------------------------------------------
1 | package com.mynotes.spring.fluxmono;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import reactor.core.publisher.Flux;
5 | import reactor.test.StepVerifier;
6 | import reactor.util.retry.Retry;
7 |
8 | import java.time.Duration;
9 |
10 | public class ErrorTest {
11 | @Test
12 | public void fluxTestAndErrorTest() {
13 | Flux myFlux = Flux.just("a", "b", "c")
14 | .concatWith(Flux.error(new RuntimeException("Error123")))
15 | .concatWith(Flux.just("e")).log();
16 |
17 | StepVerifier.create(myFlux)
18 | .expectNext("a")
19 | .expectNext("b")
20 | .expectNext("c")
21 | //.expectError(RuntimeException.class) //Cannot have both together
22 | .expectErrorMessage("Error123")
23 | .verify();
24 |
25 | }
26 |
27 | @Test
28 | public void fluxError_onErrorResume() {
29 | Flux myFlux = Flux.just("a", "b", "c")
30 | .concatWith(Flux.error(new RuntimeException("Error123")))
31 | .concatWith(Flux.just("e"))
32 | .onErrorResume( e -> {
33 | System.out.println("Something broke"+ e.getMessage());
34 | return Flux.just("default");
35 | }).log();
36 |
37 | StepVerifier.create(myFlux)
38 | .expectNext("a")
39 | .expectNext("b")
40 | .expectNext("c")
41 | .expectNext("default")// <==
42 | .verifyComplete();
43 |
44 | }
45 |
46 | @Test
47 | public void fluxError_onErrorReturn() {
48 | Flux myFlux = Flux.just("a", "b", "c")
49 | .concatWith(Flux.error(new RuntimeException("Error123")))
50 | .concatWith(Flux.just("e"))
51 | .onErrorReturn("default").log();
52 |
53 | StepVerifier.create(myFlux)
54 | .expectNext("a")
55 | .expectNext("b")
56 | .expectNext("c")
57 | .expectNext("default")// <==
58 | .verifyComplete();
59 |
60 | }
61 |
62 | @Test
63 | public void fluxError_onErrorMap() {
64 | Flux myFlux = Flux.just("a", "b", "c")
65 | .concatWith(Flux.error(new RuntimeException("Error123")))
66 | .concatWith(Flux.just("e"))
67 | .onErrorMap(e -> new IllegalArgumentException("Check input"))
68 | .log();
69 |
70 | StepVerifier.create(myFlux)
71 | .expectNext("a")
72 | .expectNext("b")
73 | .expectNext("c")
74 | .expectError(IllegalArgumentException.class)
75 | .verify();
76 |
77 | }
78 |
79 | @Test
80 | public void fluxError_Retry() {
81 | Flux myFlux = Flux.just("a", "b", "c")
82 | .concatWith(Flux.error(new RuntimeException("Error123")))
83 | .concatWith(Flux.just("e"))
84 | .retry(1)
85 | .log();
86 |
87 | StepVerifier.create(myFlux)
88 | .expectNext("a", "b", "c")
89 | .expectNext("a", "b", "c")
90 | .expectError(RuntimeException.class)
91 | .verify();
92 |
93 | }
94 |
95 | @Test
96 | public void fluxError_RetryBackOff() {
97 | Flux myFlux = Flux.just("a", "b", "c")
98 | .concatWith(Flux.error(new RuntimeException("Error123")))
99 | .concatWith(Flux.just("e"))
100 | .retryWhen(Retry.backoff(1,Duration.ofSeconds(5)))
101 | .log();
102 |
103 | StepVerifier.create(myFlux)
104 | .expectNext("a", "b", "c")
105 | .expectNext("a", "b", "c")
106 | .expectError(RuntimeException.class)
107 | .verify();
108 |
109 | }
110 |
111 |
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/flux-mono/src/test/java/com/mynotes/spring/fluxmono/FilterTest.java:
--------------------------------------------------------------------------------
1 | package com.mynotes.spring.fluxmono;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import reactor.core.publisher.Flux;
5 | import reactor.test.StepVerifier;
6 |
7 | import java.util.List;
8 |
9 | public class FilterTest {
10 |
11 | @Test
12 | public void fluxFilterTest(){
13 | List myList = List.of("foo","bar","baz");
14 |
15 | Flux flux = Flux.fromIterable(myList)
16 | .filter(s -> s.startsWith("ba"))
17 | .log();
18 |
19 | StepVerifier.create(flux)
20 | .expectNext("bar", "baz")
21 | .verifyComplete();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/flux-mono/src/test/java/com/mynotes/spring/fluxmono/FluxAndMonoFactoryMethods.java:
--------------------------------------------------------------------------------
1 | package com.mynotes.spring.fluxmono;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import reactor.core.publisher.Flux;
5 | import reactor.core.publisher.Mono;
6 | import reactor.test.StepVerifier;
7 |
8 | import java.util.List;
9 | import java.util.function.Supplier;
10 | import java.util.stream.Stream;
11 |
12 | public class FluxAndMonoFactoryMethods {
13 |
14 | @Test
15 | public void fluxFromIterable(){
16 | List myList = List.of("a","b","c");
17 |
18 | Flux flux = Flux.fromIterable(myList).log();
19 |
20 | StepVerifier.create(flux)
21 | .expectNext("a","b","c")
22 | .verifyComplete();
23 |
24 | }
25 |
26 | @Test
27 | public void fluxFromArray(){
28 | String[] myArr = new String[]{"a","b","c"};
29 |
30 | Flux flux = Flux.fromArray(myArr).log();
31 |
32 | StepVerifier.create(flux)
33 | .expectNext("a","b","c")
34 | .verifyComplete();
35 |
36 | }
37 |
38 | @Test
39 | public void fluxFromStream(){
40 | Stream stream = List.of("a","b","c").stream();
41 |
42 | Flux flux = Flux.fromStream(stream).log();
43 |
44 | StepVerifier.create(flux)
45 | .expectNext("a","b","c")
46 | .verifyComplete();
47 |
48 | }
49 |
50 | @Test
51 | public void fluxFromRange(){
52 |
53 | Flux flux = Flux.range(1,10);
54 |
55 | StepVerifier.create(flux)
56 | .expectNextCount(10)
57 | .verifyComplete();
58 |
59 | }
60 |
61 | @Test
62 | public void monoFromJustOrEmpty(){
63 |
64 | Mono mono =Mono.justOrEmpty(null);
65 |
66 | StepVerifier.create(mono.log())
67 | .verifyComplete();
68 |
69 | }
70 |
71 | @Test
72 | public void monoFromSupplier(){
73 |
74 | Supplier supplier = () -> "a";
75 |
76 | Mono mono =Mono.fromSupplier(supplier);
77 |
78 | StepVerifier.create(mono.log())
79 | .expectNext("a")
80 | .verifyComplete();
81 |
82 | }
83 |
84 |
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/flux-mono/src/test/java/com/mynotes/spring/fluxmono/FluxMonoApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.mynotes.spring.fluxmono;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import reactor.core.publisher.ConnectableFlux;
5 | import reactor.core.publisher.Flux;
6 | import reactor.core.publisher.Mono;
7 | import reactor.test.StepVerifier;
8 |
9 | import java.time.Duration;
10 |
11 | class FluxMonoApplicationTest {
12 |
13 | @Test
14 | public void flux() {
15 | Flux myFlux = Flux.just("a", "b", "c");
16 |
17 | myFlux.subscribe(System.out::println);
18 |
19 | }
20 |
21 | @Test
22 | public void fluxTest() {
23 | Flux myFlux = Flux.just("a", "b", "c").log();
24 |
25 | StepVerifier.create(myFlux)
26 | .expectNext("a")
27 | .expectNext("b")
28 | .expectNext("c")
29 | .verifyComplete();
30 |
31 | StepVerifier.create(myFlux)
32 | .expectNext("a","b", "c")
33 | .verifyComplete();
34 |
35 | StepVerifier.create(myFlux)
36 | .expectNextCount(3)
37 | .verifyComplete();
38 | }
39 |
40 | @Test
41 | public void fluxTestOnComplete() {
42 | Flux myFlux = Flux.just("a", "b", "c");
43 |
44 | myFlux.subscribe(System.out::println,
45 | (e) -> System.err.println(e),
46 | () -> System.out.println("Completed"));
47 |
48 | }
49 |
50 | @Test
51 | public void fluxTestAndError() {
52 | Flux myFlux = Flux.just("a", "b", "c")
53 | .concatWith(Flux.error(new RuntimeException("Error123"))).log();
54 |
55 | myFlux.subscribe(System.out::println,
56 | (e) -> System.err.println(e));
57 |
58 | }
59 |
60 | @Test
61 | public void fluxTestAndErrorTest() {
62 | Flux myFlux = Flux.just("a", "b", "c")
63 | .concatWith(Flux.error(new RuntimeException("Error123"))).log();
64 |
65 | StepVerifier.create(myFlux)
66 | .expectNext("a")
67 | .expectNext("b")
68 | .expectNext("c")
69 | //.expectError(RuntimeException.class) //Cannot have both together
70 | .expectErrorMessage("Error123")
71 | .verify();
72 |
73 | }
74 |
75 | @Test
76 | public void fluxTestAndErrorAndFLux() {
77 | Flux myFlux = Flux.just("a", "b", "c")
78 | .concatWith(Flux.error(new RuntimeException("Error")))
79 | .concatWith(Flux.just("After Error"))
80 | .log();
81 |
82 | myFlux.subscribe(System.out::println,
83 | (e) -> System.err.println(e));
84 |
85 | }
86 |
87 | @Test
88 | public void monoTest(){
89 | Mono myMono = Mono.just("a").log();
90 |
91 | StepVerifier.create(myMono)
92 | .expectNext("a")
93 | .verifyComplete();
94 | }
95 |
96 | @Test
97 | public void monoErrorTest(){
98 |
99 | Mono