Repository navigation
Expand file tree
/
Copy pathFluxWithTimeTest.java
More file actions
70 lines (48 loc) · 1.72 KB
/
Copy pathFluxWithTimeTest.java
File metadata and controls
70 lines (48 loc) · 1.72 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
package flux;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;
import java.time.Duration;
public class FluxWithTimeTest {
@Test
public void infiniteSequence() throws InterruptedException {
Flux<Long> infiniteFlux = Flux.interval(Duration.ofMillis(100))
.log(); // starts from 0 --> ......
infiniteFlux
.subscribe((element) -> System.out.println("Value is : " + element));
Thread.sleep(3000);
}
@Test
public void infiniteSequenceTest() throws InterruptedException {
Flux<Long> finiteFlux = Flux.interval(Duration.ofMillis(100))
.take(3)
.log();
StepVerifier.create(finiteFlux)
.expectSubscription()
.expectNext(0L, 1L,2L)
.verifyComplete();
}
@Test
public void infiniteSequenceMap() throws InterruptedException {
Flux<Integer> finiteFlux = Flux.interval(Duration.ofMillis(100))
.map(l -> new Integer(l.intValue()))
.take(3)
.log();
StepVerifier.create(finiteFlux)
.expectSubscription()
.expectNext(0, 1,2)
.verifyComplete();
}
@Test
public void infiniteSequenceMap_withDelay() throws InterruptedException {
Flux<Integer> finiteFlux = Flux.interval(Duration.ofMillis(100))
.delayElements(Duration.ofSeconds(1))
.map(l -> new Integer(l.intValue()))
.take(3)
.log();
StepVerifier.create(finiteFlux)
.expectSubscription()
.expectNext(0, 1,2)
.verifyComplete();
}
}