Repository navigation
Expand file tree
/
Copy pathFluxCombineTest.java
More file actions
93 lines (65 loc) · 2.61 KB
/
Copy pathFluxCombineTest.java
File metadata and controls
93 lines (65 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package flux;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;
import reactor.test.scheduler.VirtualTimeScheduler;
import java.time.Duration;
public class FluxCombineTest {
@Test
public void combineUsingMerge(){
Flux<String> flux1 = Flux.just("A","B","C");
Flux<String> flux2 = Flux.just("D","E","F");
Flux<String> mergedFlux = Flux.merge(flux1,flux2);
StepVerifier.create(mergedFlux.log())
.expectSubscription()
.expectNext("A","B","C","D","E","F")
.verifyComplete();
}
@Test
public void combineUsingMerge_withDelay(){
// merge with delay does not maintain order
Flux<String> flux1 = Flux.just("A","B","C").delayElements(Duration.ofSeconds(1));
Flux<String> flux2 = Flux.just("D","E","F").delayElements(Duration.ofSeconds(1));;
Flux<String> mergedFlux = Flux.merge(flux1,flux2);
StepVerifier.create(mergedFlux.log())
.expectSubscription()
.expectNextCount(6)
//.expectNext("A","B","C","D","E","F")
.verifyComplete();
}
@Test
public void combineUsingConcat(){
Flux<String> flux1 = Flux.just("A","B","C");
Flux<String> flux2 = Flux.just("D","E","F");
Flux<String> mergedFlux = Flux.concat(flux1,flux2);
StepVerifier.create(mergedFlux.log())
.expectSubscription()
.expectNext("A","B","C","D","E","F")
.verifyComplete();
}
@Test
public void combineUsingConcat_withDelay(){
VirtualTimeScheduler.getOrSet();
Flux<String> flux1 = Flux.just("A","B","C").delayElements(Duration.ofSeconds(1));
Flux<String> flux2 = Flux.just("D","E","F").delayElements(Duration.ofSeconds(1));
Flux<String> mergedFlux = Flux.concat(flux1,flux2);
StepVerifier.withVirtualTime(()->mergedFlux.log())
.expectSubscription()
.thenAwait(Duration.ofSeconds(6))
//.expectNextCount(6)
.expectNext("A","B","C","D","E","F")
.verifyComplete();
}
@Test
public void combineUsingZip(){
Flux<String> flux1 = Flux.just("A","B","C");
Flux<String> flux2 = Flux.just("D","E","F");
Flux<String> mergedFlux = Flux.zip(flux1,flux2, (t1,t2) -> {
return t1.concat(t2); // AD, BE, CF
});
StepVerifier.create(mergedFlux.log())
.expectSubscription()
.expectNext("AD", "BE", "CF")
.verifyComplete();
}
}