Spring 与 Schedulers.elastic 的集成测试
Spring integration testing with Schedulers.elastic
我有以下 spring 反应器代码,它通过 Schedulers.elastic() 保存在数据库中。但是我看到弹性线程直到 60 秒(它的空闲时间)过去才结束/提交。所以我的集成测试失败了,除非我等到那个时候。有一个更好的方法吗 ?比如使用 Schedulers.immediate() 进行测试,使用 elastic 进行实际部署。
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
}
}
根据 Darren Forsythe 的建议,我必须包含 StepVerifier.withVirtualTime 才能通过测试
StepVerifier.withVirtualTime(() -> Mono.fromRunnable(() -> testClass.method())
.verifyComplete();
我有以下 spring 反应器代码,它通过 Schedulers.elastic() 保存在数据库中。但是我看到弹性线程直到 60 秒(它的空闲时间)过去才结束/提交。所以我的集成测试失败了,除非我等到那个时候。有一个更好的方法吗 ?比如使用 Schedulers.immediate() 进行测试,使用 elastic 进行实际部署。
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
}
}
根据 Darren Forsythe 的建议,我必须包含 StepVerifier.withVirtualTime 才能通过测试
StepVerifier.withVirtualTime(() -> Mono.fromRunnable(() -> testClass.method())
.verifyComplete();