-
[WebFlux] StepVerifier and How to use it 해답 코드 - techio웹 개발/WebFlux 2019. 10. 29. 23:56
techio reactor StepVerifier 학습 사이트
techio에서 배울 수 있는 Reactor StepVerifier 학습 success코드
operator 참고 사이트
해답 코드
Verify Simple flux
// TODO Use StepVerifier to check that the flux parameter emits "foo" and "bar" elements then completes successfully. void expectFooBarComplete(Flux flux) { StepVerifier.create(flux) .expectNext("foo") .expectNext("bar") .verifyComplete(); }
Verify an error
// TODO Use StepVerifier to check that the flux parameter emits "foo" and "bar" elements then a RuntimeException error. void expectFooBarError(Flux flux) { StepVerifier.create(flux) .expectNext("foo") .expectNext("bar") .verifyError(RuntimeException.class); }
Lambda and assertion
// TODO Use StepVerifier to check that the flux parameter emits a User with "swhite"username // and another one with "jpinkman" then completes successfully. void expectSkylerJesseComplete(Flux flux) { StepVerifier.create(flux) .assertNext( user -> {assertThat(user.getUsername()).isEqualTo("swhite");}) .assertNext( user -> {assertThat(user.getUsername()).isEqualTo("jpinkman");}) .verifyComplete(); }
Wait some time
// TODO Expect 10 elements then complete and notice how long the test takes. void expect10Elements(Flux flux) { StepVerifier.create(flux) .expectNextCount(10) .verifyComplete(); }
Virtual time
// TODO Expect 3600 elements at intervals of 1 second, and verify quicker than 3600s // by manipulating virtual time thanks to StepVerifier#withVirtualTime, notice how long the test takes void expect3600Elements(Supplier<Flux> supplier) { StepVerifier.withVirtualTime(supplier) .thenAwait(Duration.ofHours(1)) .expectNextCount(3600) .verifyComplete(); }
'웹 개발 > WebFlux' 카테고리의 다른 글
[WebClient] Content type 'application/octet-stream' not supported for bodyType='' 에러 (0) 2023.03.15 [WebFlux] publisher(발행) - subscriber(구독) 패턴에 대해서 (0) 2020.01.24 [WebFlux] query string에 담긴 String 파라미터를 localDate로 캐스팅하고 매핑하기 (0) 2019.12.23 [WebFlux] Learn how to create Mono instances 해답 코드 - techio (0) 2019.10.22 [WebFlux] Learn how to create Flux instances 해답 코드 - techio (0) 2019.10.21