gpt4 book ai didi

java - 使用 StepVerifier 测试 Mono.delay

转载 作者:行者123 更新时间:2023-11-30 02:42:07 31 4
gpt4 key购买 nike

我正在尝试使用 StepVerifier 测试 Mono.delay。我的代码如下:

Mono[Long] mono = Mono.delay(Duration.ofDays(5));

StepVerifier.withVirtualTime(() -> mono)
.thenAwait(Duration.ofDays(5))
.expectNextCount(1)
.expectComplete()
.verify();

我得到了以下堆栈跟踪

expectation "expectNextCount" failed (expected: count = 1; actual: counted = 0; signal: onError(reactor.core.Exceptions$BubblingException:
java.util.concurrent.RejectedExecutionException: Scheduler unavailable))
java.lang.AssertionError: expectation "expectNextCount" failed (expected: count = 1; actual: counted = 0; signal: onError(reactor.core.Exceptions$BubblingException: java.util.concurrent.RejectedExecutionException: Scheduler unavailable))
at reactor.test.DefaultStepVerifierBuilder.failPrefix(DefaultStepVerifierBuilder.java:1679)
at reactor.test.DefaultStepVerifierBuilder.fail(DefaultStepVerifierBuilder.java:1675)
at reactor.test.DefaultStepVerifierBuilder$DefaultVerifySubscriber.checkCountMismatch(DefaultStepVerifierBuilder.java:886)
at reactor.test.DefaultStepVerifierBuilder$DefaultVerifySubscriber.onSignalCount(DefaultStepVerifierBuilder.java:1112)
at reactor.test.DefaultStepVerifierBuilder$DefaultVerifySubscriber.onExpectation(DefaultStepVerifierBuilder.java:963)
at reactor.test.DefaultStepVerifierBuilder$DefaultVerifySubscriber.onError(DefaultStepVerifierBuilder.java:727)
at reactor.core.publisher.MonoDelay.subscribe(MonoDelay.java:59)
at reactor.test.DefaultStepVerifierBuilder$DefaultStepVerifier.verify(DefaultStepVerifierBuilder.java:532)
at reactor.test.DefaultStepVerifierBuilder$DefaultStepVerifier.verify(DefaultStepVerifierBuilder.java:508)

跟踪源代码后,执行器似乎在方法 Schedulers.setFactory 上关闭了

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

最佳答案

好的,我想我已经找到问题的根源了。

StepVerifier 需要 Supplier,在我的例子中,我提供了 Mono[Long] 以及现有的 Mono已创建。我应该执行以下操作

StepVerifier.withVirtualTime(() -> Mono.delay(Duration.ofDays(5)))
.thenAwait(Duration.ofDays(5))
.expectNextCount(1)
.expectComplete()
.verify();

这样提供的Mono就不会被首先创建,执行器也不会被关闭。

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

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