8000 Step 6: Adapters · blackbeltcoder/reactive-spring@aab5266 · GitHub
[go: up one dir, main page]

Skip to content

Commit aab5266

Browse files
committed
Step 6: Adapters
1 parent 1e0faed commit aab5266

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

reactor/pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@
3232
<artifactId>reactor-core</artifactId>
3333
</dependency>
3434

35+
<dependency>
36+
<groupId>io.reactivex</groupId>
37+
<artifactId>rxjava</artifactId>
38+
<version>1.3.0</version>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>io.reactivex</groupId>
43+
<artifactId>rxjava-reactive-streams</artifactId>
44+
<version>1.2.1</version>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>io.reactivex.rxjava2</groupId>
49+
<artifactId>rxjava</artifactId>
50+
<version>2.1.0</version>
51+
</dependency>
52+
3553
<dependency>
3654
<groupId>io.projectreactor.addons</groupId>
3755
<artifactId>reactor-test</artifactId>
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright 2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package workshop;
17+
18+
import io.reactivex.Flowable;
19+
import reactor.core.publisher.Flux;
20+
import reactor.core.publisher.Mono;
21+
import reactor.test.StepVerifier;
22+
import rx.Observable;
23+
import rx.Single;
24+
25+
import org.junit.Test;
26+
27+
/**
28+
* Using adapters to interop between reactive composition libraries.
29+
*
30+
* @author Mark Paluch
31+
*/
32+
public class Step6Adapters {
33+
34+
@Test
35+
public void adoptRxJava1ObservableToFlux() {
36+
37+
Observable<String> people = Observable.just("Jesse", "Hank");
38+
39+
// TODO: Use RxReactiveStreams to create a Flux from Observable.
40+
Flux<String> flux = Flux.empty();
41+
42+
StepVerifier.create(flux).expectNext("Jesse", "Hank").verifyComplete();
43+
}
44+
45+
@Test
46+
public void adoptRxJava1SingleToMono() {
47+
48+
Single<String> jesse = Single.just("Jesse");
49+
50+
// TODO: Use RxReactiveStreams to create a Flux from Observable.
51+
Mono<String> mono = Mono.empty();
52+
53+
StepVerifier.create(mono).expectNext("Jesse").verifyComplete();
54+
}
55+
56+
@Test
57+
public void adoptRxJava1EmptySingleToMono() {
58+
59+
Single<String> empty = Observable.<String> empty().toSingle();
60+
61+
// TODO: Use RxReactiveStreams to create a Flux from Observable.
62+
Mono<String> mono = Mono.empty();
63+
64+
// Expect a surprise here
65+
StepVerifier.create(mono).verifyComplete();
66+
}
67+
68+
@Test
69+
public void adoptRxJava2ObservableToFlux() {
70+
71+
io.reactivex.Observable<String> jesse = io.reactivex.Observable.just("Jesse");
72+
73+
// TODO: Use RxJava 2's Flowable to create a Flux
74+
Flux<String> flux = Flux.empty();
75+
76+
StepVerifier.create(flux).expectNext("Jesse").verifyComplete();
77+
}
78+
79+
@Test
80+
public void adoptFluxToRxJavaObservable() throws Exception {
81+
82+
Flux<String> people = Flux.just("Jesse", "Hank");
83+
84+
// TODO: Use RxReactiveStreams to create an Observable from Flux.
85+
Observable<String> observable = Observable.empty();
86+
87+
observable.test().awaitTerminalEvent().assertResult("Jesse", "Hank");
88+
}
89+
90+
@Test
91+
public void adoptFluxToRxJava2Flowable() throws Exception {
92+
93+
Flux<String> people = Flux.just("Jesse", "Hank");
94+
95+
// TODO: Use RxReactiveStreams to create an Flowable from Flux.
96+
Flowable<String> flowable = Flowable.empty();
97+
98+
flowable.test().await().assertResult("Jesse", "Hank").awaitTerminalEvent();
99+
}
100+
}

0 commit comments

Comments
 (0)
0