Skip to content

Commit

Permalink
Logs/Fix for flaky push rich text repsonses to contentful error (#260)
Browse files Browse the repository at this point in the history
* Logs/Fix for flaky push rich text repsonses to contentful error

* Fix tests
  • Loading branch information
dominicwest authored Mar 22, 2024
1 parent 6b42c67 commit 1b7fc47
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ private void createRichTextQuestionsInContentful(final GrantAdvert advert, final
contentfulProperties.getSpaceId(), contentfulProperties.getEnvironmentId(),
contentfulAdvert.getId());

if (responses == null || responses.isEmpty()) {
log.error("createRichTextQuestionsInContentful failed on PATCH to {}, with message: No rich text responses found", contentfulUrl);
}

final Instant now = Instant.now();
webClientBuilder.build()
.patch()
Expand All @@ -434,13 +438,13 @@ private void createRichTextQuestionsInContentful(final GrantAdvert advert, final
})
.bodyValue(requestBody)
.retrieve()
.bodyToMono(void.class)
.bodyToMono(Void.class)
.doOnError(exception -> {
log.error("createRichTextQuestionsInContentful failed on PATCH to {}, with message: {}", contentfulUrl, exception.getMessage());
log.debug("Took {} seconds to try and update rich text questions in Contentful", Duration.between(now, Instant.now()).getSeconds());
log.info("Took {} seconds to try and update rich text questions in Contentful", Duration.between(now, Instant.now()).getSeconds());
})
.block();
log.debug("Took {} seconds to update rich text questions in Contentful", Duration.between(now, Instant.now()).getSeconds());
log.info("Took {} seconds to update rich text questions in Contentful", Duration.between(now, Instant.now()).getSeconds());
}

private List<GrantAdvertQuestionResponse> getRichTextResponses(final GrantAdvert advert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ void publishAdvert_successfullyPublishedAdvert() {
when(requestBodyUriSpec.headers(any())).thenReturn(requestBodyUriSpec);
when(requestBodyUriSpec.bodyValue(any())).thenReturn(requestHeadersSpec);
when(requestHeadersSpec.retrieve()).thenReturn(responseSpec);
when(responseSpec.bodyToMono(void.class)).thenReturn(Mono.empty());
when(responseSpec.bodyToMono(Void.class)).thenReturn(Mono.empty());

final ArgumentCaptor<CMAEntry> entryCaptor = ArgumentCaptor.forClass(CMAEntry.class);

Expand Down Expand Up @@ -867,7 +867,7 @@ void publishAdvert_successfullyPublishedAdvert() {
verify(requestBodyUriSpec).headers(any());
verify(requestBodyUriSpec).bodyValue(any());
verify(requestHeadersSpec).retrieve();
verify(responseSpec).bodyToMono(void.class);
verify(responseSpec).bodyToMono(Void.class);

// verify that we've refreshed the data after adding RTF data
verify(contentfulEntries).fetchOne(contentfulAdvertId);
Expand Down Expand Up @@ -912,7 +912,7 @@ void publishAdvert_updatesExistingAdvert_IfFirstPublishedDateHasBeenSet() {
when(requestBodyUriSpec.headers(any())).thenReturn(requestBodyUriSpec);
when(requestBodyUriSpec.bodyValue(any())).thenReturn(requestHeadersSpec);
when(requestHeadersSpec.retrieve()).thenReturn(responseSpec);
when(responseSpec.bodyToMono(void.class)).thenReturn(Mono.empty());
when(responseSpec.bodyToMono(Void.class)).thenReturn(Mono.empty());

final ArgumentCaptor<GrantAdvert> grantAdvertArgumentCaptor = ArgumentCaptor.forClass(GrantAdvert.class);

Expand All @@ -931,7 +931,7 @@ void publishAdvert_updatesExistingAdvert_IfFirstPublishedDateHasBeenSet() {
verify(requestBodyUriSpec).headers(any());
verify(requestBodyUriSpec).bodyValue(any());
verify(requestHeadersSpec).retrieve();
verify(responseSpec).bodyToMono(void.class);
verify(responseSpec).bodyToMono(Void.class);

verify(contentfulEntries).update(publishedContentfulAdvert);

Expand Down Expand Up @@ -962,7 +962,7 @@ void publishAdvertThroughLambda_successfullyPublishedAdvert() {
when(requestBodyUriSpec.headers(any())).thenReturn(requestBodyUriSpec);
when(requestBodyUriSpec.bodyValue(any())).thenReturn(requestHeadersSpec);
when(requestHeadersSpec.retrieve()).thenReturn(responseSpec);
when(responseSpec.bodyToMono(void.class)).thenReturn(Mono.empty());
when(responseSpec.bodyToMono(Void.class)).thenReturn(Mono.empty());
doReturn(mockGrantAdvert).when(grantAdvertService).save(any());

when(advertDefinition.getSections()).thenReturn(definition.getSections());
Expand Down Expand Up @@ -1015,7 +1015,7 @@ void publishAdvertThroughLambda_successfullyPublishedAdvert() {
verify(requestBodyUriSpec).headers(any());
verify(requestBodyUriSpec).bodyValue(any());
verify(requestHeadersSpec).retrieve();
verify(responseSpec).bodyToMono(void.class);
verify(responseSpec).bodyToMono(Void.class);

// verify that we've refreshed the data after adding RTF data
verify(contentfulEntries).fetchOne(contentfulAdvertId);
Expand Down

0 comments on commit 1b7fc47

Please sign in to comment.