简体   繁体   English

Reactor Flux with blockLast() Spring 引导集成测试永远不会启动

[英]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.我有一个 Kafka 处理 Spring 启动应用程序,它有一个在应用程序启动时运行的方法(使用ApplicationRunner )并启动一个利用blockLast()的 Flux ,因为我发现调用subscribe()不会发生任何事情,因为它不会阻塞主线程,我发现它可以(并且将会)在 Flux 发出任何元素之前完成。

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.当我将blockLast()更改为subscribe()时,测试代码运行(尽管我不确定它测试的 Flux 代码是否以这种方式正确运行,到目前为止我只有一个微不足道的虚拟测试),我可以看到我的主要执行带有 Flux 代码的方法。 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());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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