File tree Expand file tree Collapse file tree 6 files changed +10
-11
lines changed
spring-boot-2-demo-app/src/test/java/io/github/mfvanek/spring/boot2/test/service
spring-boot-3-demo-app/src
main/java/io/github/mfvanek/spring/boot3/test
test/java/io/github/mfvanek/spring/boot3/test Expand file tree Collapse file tree 6 files changed +10
-11
lines changed Original file line number Diff line number Diff line change 2626import static com .github .tomakehurst .wiremock .client .WireMock .aResponse ;
2727import static com .github .tomakehurst .wiremock .client .WireMock .get ;
2828import static com .github .tomakehurst .wiremock .client .WireMock .getRequestedFor ;
29+ import static com .github .tomakehurst .wiremock .client .WireMock .resetAllRequests ;
2930import static com .github .tomakehurst .wiremock .client .WireMock .stubFor ;
3031import static com .github .tomakehurst .wiremock .client .WireMock .urlPathMatching ;
3132import static com .github .tomakehurst .wiremock .client .WireMock .verify ;
@@ -64,6 +65,7 @@ void getZonedTimeSuccessfully(@Nonnull final CapturedOutput output) throws JsonP
6465
6566 @ Test
6667 void retriesOnceToGetZonedTime (@ Nonnull final CapturedOutput output ) throws JsonProcessingException {
68+ resetAllRequests ();
6769 final String zoneNames = TimeZone .getDefault ().getID ();
6870 final RuntimeException exception = new RuntimeException ("Retries exhausted" );
6971 stubFor (get (urlPathMatching ("/" + zoneNames ))
@@ -73,7 +75,7 @@ void retriesOnceToGetZonedTime(@Nonnull final CapturedOutput output) throws Json
7375 ));
7476
7577 final LocalDateTime result = publicApiService .getZonedTime ();
76- verify (getRequestedFor (urlPathMatching ("/" + zoneNames )));
78+ verify (2 , getRequestedFor (urlPathMatching ("/" + zoneNames )));
7779
7880 assertThat (result ).isNull ();
7981 assertThat (output ).contains ("Retrying request to " , "Retries exhausted" );
Original file line number Diff line number Diff line change 77
88package io .github .mfvanek .spring .boot3 .test .config ;
99
10- import io .micrometer .observation .ObservationRegistry ;
1110import org .springframework .beans .factory .annotation .Value ;
1211import org .springframework .context .annotation .Bean ;
1312import org .springframework .context .annotation .Configuration ;
@@ -20,10 +19,8 @@ public class WebClientConfig {
2019 private String external ;
2120
2221 @ Bean
23- public WebClient webClient (ObservationRegistry observationRegistry , WebClient .Builder builder ) {
24-
22+ public WebClient webClient (WebClient .Builder builder ) {
2523 return builder
26- .observationRegistry (observationRegistry )
2724 .baseUrl (external )
2825 .build ();
2926 }
Original file line number Diff line number Diff line change 1717import lombok .extern .slf4j .Slf4j ;
1818import org .springframework .web .bind .annotation .GetMapping ;
1919import org .springframework .web .bind .annotation .RestController ;
20- import reactor .core .publisher .Hooks ;
2120
2221import java .time .Clock ;
2322import java .time .LocalDateTime ;
@@ -48,7 +47,6 @@ public LocalDateTime getNow() {
4847 kafkaSendingService .sendNotification ("Current time = " + now )
4948 .thenRun (() -> log .info ("Awaiting acknowledgement from Kafka" ))
5049 .get ();
51- Hooks .disableAutomaticContextPropagation ();
5250 return now ;
5351 }
5452}
Original file line number Diff line number Diff line change 1919import org .springframework .retry .ExhaustedRetryException ;
2020import org .springframework .stereotype .Service ;
2121import org .springframework .web .reactive .function .client .WebClient ;
22- import reactor .core .publisher .Hooks ;
2322import reactor .core .publisher .Mono ;
2423import reactor .util .retry .Retry ;
2524
@@ -53,7 +52,6 @@ public LocalDateTime getZonedTime() {
5352 }
5453
5554 private CurrentTime getZonedTimeFromWorldTimeApi () throws JsonProcessingException {
56- Hooks .enableAutomaticContextPropagation ();
5755 final String zoneNames = TimeZone .getDefault ().getID ();
5856 final Mono <String > response = webClient .get ()
5957 .uri (String .join ("/" , zoneNames ))
Original file line number Diff line number Diff line change @@ -99,6 +99,8 @@ void spanShouldBeReportedInLogs(@Nonnull final CapturedOutput output) {
9999 .returnResult ();
100100 final String traceId = result .getResponseHeaders ().getFirst (TRACE_ID_HEADER_NAME );
101101 assertThat (traceId ).isNotBlank ();
102+ assertThat (result .getResponseBody ())
103+ .isBefore (LocalDateTime .now (clock ));
102104 assertThat (output .getAll ())
103105 .contains ("Called method getNow. TraceId = " + traceId )
104106 .contains ("Awaiting acknowledgement from Kafka" );
@@ -167,7 +169,7 @@ void mdcValuesShouldBeReportedInLogs(@Nonnull final CapturedOutput output) {
167169
168170 @ SneakyThrows
169171 @ Test
170- void observationValuesShouldBeReportedInRetryLogs (@ Nonnull final CapturedOutput output ) {
172+ void mdcValuesShouldBeReportedInRetryLogs (@ Nonnull final CapturedOutput output ) {
171173 final String zoneNames = TimeZone .getDefault ().getID ();
172174 final RuntimeException exception = new RuntimeException ("Retries exhausted" );
173175 stubFor (get (urlPathMatching ("/" + zoneNames ))
Original file line number Diff line number Diff line change 2626import static com .github .tomakehurst .wiremock .client .WireMock .aResponse ;
2727import static com .github .tomakehurst .wiremock .client .WireMock .get ;
2828import static com .github .tomakehurst .wiremock .client .WireMock .getRequestedFor ;
29+ import static com .github .tomakehurst .wiremock .client .WireMock .resetAllRequests ;
2930import static com .github .tomakehurst .wiremock .client .WireMock .stubFor ;
3031import static com .github .tomakehurst .wiremock .client .WireMock .urlPathMatching ;
3132import static com .github .tomakehurst .wiremock .client .WireMock .verify ;
@@ -64,6 +65,7 @@ void printTimeZoneSuccessfully(@Nonnull final CapturedOutput output) throws Json
6465
6566 @ Test
6667 void retriesOnceToGetZonedTime (@ Nonnull final CapturedOutput output ) throws JsonProcessingException {
68+ resetAllRequests ();
6769 final String zoneNames = TimeZone .getDefault ().getID ();
6870 final RuntimeException exception = new RuntimeException ("Retries exhausted" );
6971 stubFor (get (urlPathMatching ("/" + zoneNames ))
@@ -73,7 +75,7 @@ void retriesOnceToGetZonedTime(@Nonnull final CapturedOutput output) throws Json
7375 ));
7476
7577 final LocalDateTime result = publicApiService .getZonedTime ();
76- verify (getRequestedFor (urlPathMatching ("/" + zoneNames )));
78+ verify (2 , getRequestedFor (urlPathMatching ("/" + zoneNames )));
7779
7880 assertThat (result ).isNull ();
7981 assertThat (output ).contains ("Retrying request to " , "Retries exhausted" );
You can’t perform that action at this time.
0 commit comments