File tree Expand file tree Collapse file tree
main/java/com/baeldung/reactive/controller
test/java/com/baeldung/reactive Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88import org .springframework .web .bind .annotation .PathVariable ;
99import org .springframework .web .bind .annotation .RestController ;
1010
11- import reactor .core .publisher .ConnectableFlux ;
1211import reactor .core .publisher .Flux ;
1312import reactor .core .publisher .Mono ;
1413
15- @ RestController ( "/foos" )
14+ @ RestController
1615public class FooReactiveController {
1716
18- @ GetMapping ("/{id}" )
17+ @ GetMapping ("/foos/ {id}" )
1918 public Mono <Foo > getFoo (@ PathVariable ("id" ) long id ) {
2019 return Mono .just (new Foo (id , randomAlphabetic (6 )));
2120 }
2221
23- @ GetMapping ("/" )
22+ @ GetMapping ("/foos " )
2423 public Flux <Foo > getAllFoos () {
25- final ConnectableFlux <Foo > flux = Flux .<Foo > create (fluxSink -> {
24+ final Flux <Foo > flux = Flux .<Foo > create (fluxSink -> {
2625 while (true ) {
2726 fluxSink .next (new Foo (System .currentTimeMillis (), randomAlphabetic (6 )));
2827 }
29- }).sample (Duration .ofSeconds (1 )).publish ();
28+ }).sample (Duration .ofSeconds (1 )).log ();
3029
3130 return flux ;
3231 }
Original file line number Diff line number Diff line change 1+ package com .baeldung .reactive ;
2+
3+ import static org .apache .commons .lang3 .RandomStringUtils .randomAlphabetic ;
4+ import static org .junit .Assert .assertNotNull ;
5+
6+ import java .time .Duration ;
7+
8+ import org .junit .jupiter .api .Test ;
9+
10+ import com .baeldung .reactive .controller .Foo ;
11+
12+ import reactor .core .publisher .Flux ;
13+
14+ public class FluxUnitTest {
15+
16+ @ Test
17+ public void whenFluxIsConstructed_thenCorrect () {
18+ final Flux <Foo > flux = Flux .<Foo > create (fluxSink -> {
19+ while (true ) {
20+ fluxSink .next (new Foo (System .currentTimeMillis (), randomAlphabetic (6 )));
21+ }
22+ }).sample (Duration .ofSeconds (1 )).log ();
23+
24+ flux .subscribe ();
25+
26+ assertNotNull (flux );
27+ }
28+
29+ }
You can’t perform that action at this time.
0 commit comments