Skip to content

Commit dfcd5b9

Browse files
committed
Add a test to validate Reactor Netty automatic flushing
Issue: SPR-14992
1 parent c201a14 commit dfcd5b9

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

spring-web/src/test/java/org/springframework/http/server/reactive/FlushingIntegrationTests.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ public void writeAndAutoFlushOnComplete() {
7676
.verify(Duration.ofSeconds(5L));
7777
}
7878

79+
@Test // SPR-14992
80+
public void writeAndAutoFlushBeforeComplete() {
81+
ClientRequest<Void> request = ClientRequest.GET("http://localhost:" + port + "/write-and-never-complete").build();
82+
Flux<String> result = this.webClient
83+
.exchange(request)
84+
.flatMap(response -> response.bodyToFlux(String.class));
85+
86+
StepVerifier.create(result)
87+
.expectNextMatches(s -> s.startsWith("0123456789"))
88+
.thenCancel()
89+
.verify(Duration.ofSeconds(5L));
90+
}
91+
7992
@Override
8093
protected HttpHandler createHttpHandler() {
8194
return new FlushingHandler();
@@ -95,13 +108,21 @@ public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response)
95108
responseBody = responseBody.concatWith(Flux.never());
96109
return response.writeAndFlushWith(responseBody);
97110
}
98-
else if (path.endsWith("write-and-complete")){
111+
else if (path.endsWith("write-and-complete")) {
99112
Flux<DataBuffer> responseBody = Flux
100113
.just("0123456789")
101114
.repeat(20000)
102115
.map(value -> toDataBuffer(value, response.bufferFactory()));
103116
return response.writeWith(responseBody);
104117
}
118+
else if (path.endsWith("write-and-never-complete")) {
119+
Flux<DataBuffer> responseBody = Flux
120+
.just("0123456789")
121+
.repeat(20000)
122+
.map(value -> toDataBuffer(value, response.bufferFactory()))
123+
.mergeWith(Flux.never());
124+
return response.writeWith(responseBody);
125+
}
105126
return response.writeWith(Flux.empty());
106127
}
107128

0 commit comments

Comments
 (0)