-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPart06Request.java
67 lines (54 loc) · 2.39 KB
/
Part06Request.java
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
package io.pivotal.literx;
//generic imports to help with simpler IDEs (ie tech.io)
import java.util.*;
import java.util.function.*;
import java.time.*;
import io.pivotal.literx.domain.User;
import io.pivotal.literx.repository.ReactiveRepository;
import io.pivotal.literx.repository.ReactiveUserRepository;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;
/**
* Learn how to control the demand.
*
* @see <a href="https://tech.io/playgrounds/929/reactive-programming-with-reactor-3/Request">Request Question Desc</a>
*/
public class Part06Request {
ReactiveRepository<User> repository = new ReactiveUserRepository();
//========================================================================================
// TODO Create a StepVerifier that initially requests all values and expect 4 values to be received
StepVerifier requestAllExpectFour(Flux<User> flux) {
return StepVerifier
.create(flux)
.expectSubscription()
.thenRequest(Long.MAX_VALUE)
.expectNextCount(4)
.expectComplete();
}
//========================================================================================
// TODO Create a StepVerifier that initially requests 1 value and expects User.SKYLER then requests another value and expects User.JESSE then stops verifying by cancelling the source
StepVerifier requestOneExpectSkylerThenRequestOneExpectJesse(Flux<User> flux) {
return StepVerifier
.create(flux)
.expectSubscription()
.thenRequest(1L)
.expectNext(User.SKYLER)
.thenRequest(1L)
.expectNext(User.JESSE)
.thenCancel();
}
//========================================================================================
// TODO Return a Flux with all users stored in the repository that prints automatically logs for all Reactive Streams signals
Flux<User> fluxWithLog() {
return repository.findAll().log();
}
//========================================================================================
// TODO Return a Flux with all users stored in the repository that prints "Starring:" on subscribe, "firstname lastname" for all values and "The end!" on complete
Flux<User> fluxWithDoOnPrintln() {
return repository
.findAll()
.doOnSubscribe(s -> System.out.println("Starring:"))
.doOnNext(u -> System.out.println(u.getFirstname() + " " + u.getLastname()))
.doOnComplete(() -> System.out.println("The end!"));
}
}