以下功能:
private Boolean canDoIt(Parameter param) {
return myService
.getMyObjectInReactiveWay(param)
.map(myObject -> myService.checkMyObjectInImperativeWay(myObject))
.block();
}
Run Code Online (Sandbox Code Playgroud)
在运行时工作正常,但是当使用它测试使用它的流程时,WebTestClient出现以下错误:
java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread parallel-1
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:83) ~[reactor-core-3.4.1.jar:3.4.1]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Assembly trace from producer [reactor.core.publisher.MonoFlatMap] :
reactor.core.publisher.Mono.flatMap
Run Code Online (Sandbox Code Playgroud)
我知道我不应该使用block(),但我别无选择:该函数必须返回 a Boolean(而不是 a Mono<Boolean>)。也许有另一种不使用block().
有没有办法让我WebTestClient不抛出该错误?
使用Reactor Core版本3.4.6。
java reactive-programming project-reactor spring-webflux webtestclient