单元测试无限重复 Flux
Unit test indefinite repeat Flux
给定一个永远重复的 Flux,我们如何对其进行单元测试?
假设我想断言第一组元素 [1,2,3,4,5]
StepVerifier.
withVirtualTime(() -> Flux.just(1,2,3,4,5).repeatWhen(c -> c.delayElements(Duration.ofSeconds(1)).log()))
.thenAwait(Duration.ofSeconds(1))
.expectNext(1)
.thenAwait(Duration.ofSeconds(4))
.expectNext(2,3,4,5)
.thenConsumeWhile(x -> true) // what is the right behaviour to be added here ?
```
对于“无限”通量,您唯一的选择可能是 thenCancel().verify()
给定一个永远重复的 Flux,我们如何对其进行单元测试? 假设我想断言第一组元素 [1,2,3,4,5]
StepVerifier.
withVirtualTime(() -> Flux.just(1,2,3,4,5).repeatWhen(c -> c.delayElements(Duration.ofSeconds(1)).log()))
.thenAwait(Duration.ofSeconds(1))
.expectNext(1)
.thenAwait(Duration.ofSeconds(4))
.expectNext(2,3,4,5)
.thenConsumeWhile(x -> true) // what is the right behaviour to be added here ?
```
对于“无限”通量,您唯一的选择可能是 thenCancel().verify()