I have Controller that returns Flux of Strings - basically returns stream of data (Strings containing current time), Strings are delayed 1 second using on .delayElements(Duration.ofSeconds(1)) on Flux
Controller:
@GetMapping(value = "/currentTimeReactiveFlux", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
@ResponseBody
public Flux<String> exampleOfFluxDeleyedResponse() {
return Flux.range(1, 1000)
.delayElements(Duration.ofSeconds(1))
.map(integer -> "Current time (1) is " + OffsetDateTime.now())
.doOnNext(s -> log.info("S: " + s + " -> " + LocalDateTime.now().getSecond()))
.doOnCancel(() -> log.info("Cancelled"));
}
Is it possible to speed up this in Integration tests with WebClientTest. This is working slowly ( delays):
Controller integration test:
@Autowired
WebTestClient webTestClient;
@Test
void testSpeedUpStreamsOfFlux() {
FluxExchangeResult<String> result = webTestClient.get().uri("/currentTimeReactiveFlux")
.accept(MediaType.TEXT_EVENT_STREAM)
.exchange()
.expectStatus().isOk()
.returnResult(String.class);
Flux<String> eventFlux = result.getResponseBody();
StepVerifier.withVirtualTime(()-> eventFlux)
.expectNextCount(10)
.thenAwait(Duration.ofSeconds(10))
.thenCancel()
.verify();
}