代码之家  ›  专栏  ›  技术社区  ›  DBS

弹性弹簧集成测试

  •  0
  • DBS  · 技术社区  · 6 年前

    我有下面的Spring reactor代码,它通过scheduler.slastic()在db中进行保存。然而,我看到弹性线程直到60秒(空闲时间)后才会结束/提交。所以我的集成测试失败了,除非我等待那个时间。有更好的方法吗?就像使用schedulers.immediate()进行测试和弹性部署一样。

    public void method() {
       Mono.just(student)
       .flatMap(student -> populateStudentDetails(student))
       .subscribeOn(Schedulers.elastic)
       .subscribe(studentRepository::save);
    }
    

    我正在进行下面的测试

    @SpringBootTest
    public class TestClass {
       @Test
       void testMethod() {
            testClass.method();
            //assertForDatainDB
            //fails if immediately asserted
            //succeeds if asserted after 60s
       }
    }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   DBS    6 年前

    正如DarrenForsyth所建议的,我必须包括StepVerifier.WithVirtualTime才能通过测试。

    StepVerifier.withVirtualTime(() -> Mono.fromRunnable(() -> testClass.method())
      .verifyComplete();