Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无限期使用虚拟时间块的反应堆步进验证器_Java_Project Reactor - Fatal编程技术网

Java 无限期使用虚拟时间块的反应堆步进验证器

Java 无限期使用虚拟时间块的反应堆步进验证器,java,project-reactor,Java,Project Reactor,我试图使用Reactor的虚拟时间功能,但测试块会无限期(无超时)或抛出AssertionError(有超时): 例外情况是: java.lang.AssertionError: VerifySubscribertimed out on reactor.core.publisher.FluxConcatMap$ConcatMapImmediate@66d1af89 使用real time的同一示例与预期的效果相同: @Test public void test2() { StepVer

我试图使用Reactor的虚拟时间功能,但测试块会无限期(无超时)或抛出
AssertionError
(有超时):

例外情况是:

java.lang.AssertionError: VerifySubscribertimed out on reactor.core.publisher.FluxConcatMap$ConcatMapImmediate@66d1af89
使用real time的同一示例与预期的效果相同:

@Test
public void test2() {
    StepVerifier.create(Flux.just(1, 2, 3, 4).delayElements(Duration.ofSeconds(1)))
            .expectSubscription()
            .expectNextCount(4)
            .expectComplete()
            .verify(Duration.ofSeconds(10));
}
从参考资料中,我看不到我下面的第一个示例中有错误


怎么了

您需要使用
。然后等待(持续时间)
,否则(虚拟)时钟不会移动,延迟也不会发生。您还可以在
expectSubscription()
之后使用
.expectNoEvent(Duration)

例如:

@Test
public void test() {
  StepVerifier.withVirtualTime(() -> 
        Flux.just(1, 2, 3, 4).delayElements(Duration.ofSeconds(1)))
        .expectSubscription() //t == 0
//move the clock forward by 1s, and check nothing is emitted in the meantime
        .expectNoEvent(Duration.ofSeconds(1))
//so this effectively verifies the first value is delayed by 1s:
        .expectNext(1)
//and so on...
        .expectNoEvent(Duration.ofSeconds(1))
        .expectNext(2)
//or move the clock forward by 2s, allowing events to take place,
//and check last 2 values where delayed
        .thenAwait(Duration.ofSeconds(2))
        .expectNext(3, 4)
        .expectComplete()
//trigger the verification and check that in realtime it ran in under 200ms
        .verify(Duration.ofMillis(200));
}
@Test
public void test() {
  StepVerifier.withVirtualTime(() -> 
        Flux.just(1, 2, 3, 4).delayElements(Duration.ofSeconds(1)))
        .expectSubscription() //t == 0
//move the clock forward by 1s, and check nothing is emitted in the meantime
        .expectNoEvent(Duration.ofSeconds(1))
//so this effectively verifies the first value is delayed by 1s:
        .expectNext(1)
//and so on...
        .expectNoEvent(Duration.ofSeconds(1))
        .expectNext(2)
//or move the clock forward by 2s, allowing events to take place,
//and check last 2 values where delayed
        .thenAwait(Duration.ofSeconds(2))
        .expectNext(3, 4)
        .expectComplete()
//trigger the verification and check that in realtime it ran in under 200ms
        .verify(Duration.ofMillis(200));
}