From dfcd5b9ed9f429439980b5ffde17b2ee08593670 Mon Sep 17 00:00:00 2001 From: Sebastien Deleuze Date: Thu, 15 Dec 2016 13:08:36 +0100 Subject: [PATCH] Add a test to validate Reactor Netty automatic flushing Issue: SPR-14992 --- .../reactive/FlushingIntegrationTests.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/FlushingIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/FlushingIntegrationTests.java index d44e7cd6ad2..acafc93c3da 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/FlushingIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/FlushingIntegrationTests.java @@ -76,6 +76,19 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest .verify(Duration.ofSeconds(5L)); } + @Test // SPR-14992 + public void writeAndAutoFlushBeforeComplete() { + ClientRequest request = ClientRequest.GET("http://localhost:" + port + "/write-and-never-complete").build(); + Flux result = this.webClient + .exchange(request) + .flatMap(response -> response.bodyToFlux(String.class)); + + StepVerifier.create(result) + .expectNextMatches(s -> s.startsWith("0123456789")) + .thenCancel() + .verify(Duration.ofSeconds(5L)); + } + @Override protected HttpHandler createHttpHandler() { return new FlushingHandler(); @@ -95,13 +108,21 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest responseBody = responseBody.concatWith(Flux.never()); return response.writeAndFlushWith(responseBody); } - else if (path.endsWith("write-and-complete")){ + else if (path.endsWith("write-and-complete")) { Flux responseBody = Flux .just("0123456789") .repeat(20000) .map(value -> toDataBuffer(value, response.bufferFactory())); return response.writeWith(responseBody); } + else if (path.endsWith("write-and-never-complete")) { + Flux responseBody = Flux + .just("0123456789") + .repeat(20000) + .map(value -> toDataBuffer(value, response.bufferFactory())) + .mergeWith(Flux.never()); + return response.writeWith(responseBody); + } return response.writeWith(Flux.empty()); }