如何使用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 (将#修改为@)