gpt4 book ai didi

java - 使用 StepVerifier 测试通量

转载 作者:行者123 更新时间:2023-11-30 06:19:30 28 4
gpt4 key购买 nike

我正在从该页面学习响应式编程:tutorial 。我想知道为什么在下面的示例中,当我期望 4 条记录时,stact Trace 会抛出实际一条记录的错误?

java.lang.AssertionError: expectation "expectNextCount(4)" failed (expected: count = 4; actual: counted = 1; signal: onComplete())

// TODO Create a StepVerifier that initially requests all values and expect 4 values to be received
StepVerifier requestAllExpectFour(Flux<User> flux) {
return StepVerifier.withVirtualTime(() -> Flux.just(flux))
.expectSubscription()
.thenRequest(4)
.expectNextCount(4)
.expectComplete();
}

我想知道我是否在这里遗漏了一些东西。

最佳答案

试试这个

StepVerifier requestAllExpectFour(Flux<User> flux) {
return StepVerifier.withVirtualTime(() -> flux)
.expectSubscription()
.thenRequest(Long.MAX_VALUE)
.expectNextCount(4)
.expectComplete();
}

或者像这样

StepVerifier requestAllExpectFour(Flux<User> flux) {
return StepVerifier.create(flux)
.expectSubscription()
.thenRequest(Long.MAX_VALUE)
.expectNextCount(4)
.expectComplete();
}

关于java - 使用 StepVerifier 测试通量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48485100/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com