Skip to content

Commit

Permalink
feat: add input message to error logs (#475)
Browse files Browse the repository at this point in the history
Co-authored-by: Yalz <[email protected]>
  • Loading branch information
Tomvbe and Yalz authored Feb 5, 2024
1 parent 0a9327a commit 8888f25
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ protected void processInput(LdiAdapter.Content content) {
try {
adapter.apply(content).forEach(this::processModel);
} catch (Exception e) {
log.atError().log(ObserveConfiguration.ERROR_TEMPLATE, this.pipelineName + ":processInput", e.getMessage());
final var errorLocation = this.pipelineName + ":processInput";
log.atError().log(ObserveConfiguration.ERROR_TEMPLATE, errorLocation, e.getMessage());
log.atError().log(ObserveConfiguration.ERROR_TEMPLATE, errorLocation,
"Processing below message.%n%n###mime###%n%s%n###content###%n%s".formatted(content.mimeType(), content.content()));
throw e;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public HttpInputPoller(String pipelineName, ComponentExecutor executor, LdiAdapt
this.requests = endpoints.stream().map(endpoint -> new GetRequest(endpoint, RequestHeaders.empty())).toList();
this.continueOnFail = continueOnFail;
this.scheduler = new ThreadPoolTaskScheduler();
this.scheduler.setWaitForTasksToCompleteOnShutdown(false);
this.scheduler.setErrorHandler(t -> log.error(t.getMessage()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.stream.Stream;

import static com.github.tomakehurst.wiremock.client.CountMatchingStrategy.GREATER_THAN_OR_EQUAL;
import static com.github.tomakehurst.wiremock.client.WireMock.reset;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -91,7 +92,7 @@ void whenPeriodicPolling_thenReturnTwoTimesTheSameResponse(PollingInterval polli
httpInputPoller.schedulePoller(pollingInterval);

Mockito.verify(adapter, timeout(4000).times(2)).apply(LdiAdapter.Content.of(CONTENT, CONTENT_TYPE));
WireMock.verify(2, getRequestedFor(urlEqualTo(ENDPOINT)));
WireMock.verify(new CountMatchingStrategy(GREATER_THAN_OR_EQUAL, 2), getRequestedFor(urlEqualTo(ENDPOINT)));
}

@Test
Expand Down Expand Up @@ -121,8 +122,8 @@ void whenPeriodicPollingMultipleEndpoints_thenReturnTwoTimesTheSameResponse(Poll
httpInputPoller.schedulePoller(pollingInterval);

Mockito.verify(adapter, timeout(6000).times(4)).apply(LdiAdapter.Content.of(CONTENT, CONTENT_TYPE));
WireMock.verify(2, getRequestedFor(urlEqualTo(endpoint)));
WireMock.verify(2, getRequestedFor(urlEqualTo(otherEndpoint)));
WireMock.verify(new CountMatchingStrategy(GREATER_THAN_OR_EQUAL, 2), getRequestedFor(urlEqualTo(endpoint)));
WireMock.verify(new CountMatchingStrategy(GREATER_THAN_OR_EQUAL, 2), getRequestedFor(urlEqualTo(otherEndpoint)));
}

@ParameterizedTest
Expand All @@ -133,7 +134,7 @@ void when_OnContinueIsTrueAndPeriodPollingReturnsNot2xx_thenKeepPolling(PollingI
httpInputPoller.schedulePoller(pollingInterval);

Mockito.verify(adapter, after(4000).never()).apply(any());
WireMock.verify(new CountMatchingStrategy(CountMatchingStrategy.GREATER_THAN_OR_EQUAL, 2),
WireMock.verify(new CountMatchingStrategy(GREATER_THAN_OR_EQUAL, 2),
getRequestedFor(urlEqualTo(ENDPOINT)));

}
Expand All @@ -147,7 +148,7 @@ void when_OnContinueIsFalseAndPeriodPollingReturnsNot2xx_thenStopPolling(Polling
httpInputPoller.schedulePoller(pollingInterval);

Mockito.verify(adapter, after(2000).never()).apply(any());
WireMock.verify(1, getRequestedFor(urlEqualTo(ENDPOINT)));
WireMock.verify(new CountMatchingStrategy(GREATER_THAN_OR_EQUAL, 1), getRequestedFor(urlEqualTo(ENDPOINT)));
}

@ParameterizedTest
Expand All @@ -159,7 +160,7 @@ void when_OnContinueIsFalseAndPeriodPollingReturnsNot2xx_thenStopPolling_Cron(Po
httpInputPoller.schedulePoller(pollingInterval);

Mockito.verify(adapter, after(2000).never()).apply(any());
WireMock.verify(1, getRequestedFor(urlEqualTo(ENDPOINT)));
WireMock.verify(new CountMatchingStrategy(GREATER_THAN_OR_EQUAL, 1), getRequestedFor(urlEqualTo(ENDPOINT)));
}

@Test
Expand Down

0 comments on commit 8888f25

Please sign in to comment.