32
32
import org .springframework .http .server .reactive .HttpHandler ;
33
33
import org .springframework .http .server .reactive .ServerHttpRequest ;
34
34
import org .springframework .http .server .reactive .ServerHttpResponse ;
35
- import org .springframework .web .reactive .function .BodyExtractors ;
36
35
import org .springframework .web .reactive .function .client .WebClient ;
37
36
38
37
import static org .junit .Assert .assertTrue ;
@@ -57,8 +56,8 @@ public void setup() throws Exception {
57
56
public void writeAndFlushWith () throws Exception {
58
57
Mono <String > result = this .webClient .get ()
59
58
.uri ("/write-and-flush" )
60
- .exchange ()
61
- .flatMapMany ( response -> response . body ( BodyExtractors . toFlux ( String .class )) )
59
+ .retrieve ()
60
+ .bodyToFlux ( String .class )
62
61
.takeUntil (s -> s .endsWith ("data1" ))
63
62
.reduce ((s1 , s2 ) -> s1 + s2 );
64
63
@@ -72,13 +71,13 @@ public void writeAndFlushWith() throws Exception {
72
71
public void writeAndAutoFlushOnComplete () {
73
72
Mono <String > result = this .webClient .get ()
74
73
.uri ("/write-and-complete" )
75
- .exchange ()
76
- .flatMapMany ( response -> response . bodyToFlux (String .class ) )
74
+ .retrieve ()
75
+ .bodyToFlux (String .class )
77
76
.reduce ((s1 , s2 ) -> s1 + s2 );
78
77
79
78
try {
80
79
StepVerifier .create (result )
81
- .consumeNextWith (value -> assertTrue (value .length () == 200000 ))
80
+ .consumeNextWith (value -> assertTrue (value .length () == 20000 * "0123456789" . length () ))
82
81
.expectComplete ()
83
82
.verify (Duration .ofSeconds (5L ));
84
83
}
@@ -95,14 +94,15 @@ public void writeAndAutoFlushOnComplete() {
95
94
96
95
@ Test // SPR-14992
97
96
public void writeAndAutoFlushBeforeComplete () {
98
- Flux <String > result = this .webClient .get ()
97
+ Mono <String > result = this .webClient .get ()
99
98
.uri ("/write-and-never-complete" )
100
- .exchange ()
101
- .flatMapMany (response -> response .bodyToFlux (String .class ));
99
+ .retrieve ()
100
+ .bodyToFlux (String .class )
101
+ .next ();
102
102
103
103
StepVerifier .create (result )
104
104
.expectNextMatches (s -> s .startsWith ("0123456789" ))
105
- .thenCancel ()
105
+ .expectComplete ()
106
106
.verify (Duration .ofSeconds (5L ));
107
107
}
108
108
0 commit comments