如何解决如何使用StepVerifier.withVirtualTime准确计数项目?
我想验证一段时间内我的助焊剂排放了多少物品。假设我有一个简单的发布者,每秒发布1个项目。
var list = List.of("A","B","C","D","E");
Supplier<Flux<String>> supplier = () -> Flux.fromIterable(list).delayElements(Duration.ofSeconds(1));
我想使用StepVerifier将时钟向前移动几次,以确保以预期的速率发射物品。
StepVerifier.withVirtualTime(supplier)
.expectSubscription()
.thenAwait(Duration.ofSeconds(2))
.expectNextCount(1) // Doesn't fail,even though I advanced the clock 2 seconds
.thenAwait(Duration.ofSeconds(3))
.expectNextCount(4) // Doesn't fail,even though I only advanced 3 seconds
.expectComplete()
.verify();
据我所知,如果expectNextCount
太高,我将陷入僵局,而如果它太低,我将永远不会看到错误。可以将expectNextCount
与虚拟时间一起使用吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。