简体   繁体   中英

Reactor Flux with blockLast() Spring Boot integration test never spins up

I have a Kafka processing Spring Boot app that has a method that runs at application startup (using ApplicationRunner ) and spins up a Flux that leverages blockLast() , because I found that nothing would happen calling subscribe() , since it doesn't block the main thread, which I discovered can (and will) complete before the Flux emits any elements.

Now that I'm creating integration tests for this method the problem I'm running into is that the context/app never fully spins up, so my test code is never executed, the app startup just reaches a certain point and hangs forever. When I change blockLast() to subscribe() the test code runs (though I'm not sure if the Flux code it tests runs correctly this way, as so far I just have a trivial dummy test) and I can see that my primary method with the Flux code is executed. Anyone have any ideas for how I can create integration tests in this scenario?

I had a similar problem, and I circumvented it by dispatching the polling task to an executor service as:

@PostConstruct
public void init() {
    this.executorService.submit(() -> pollingTask());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM