jubins commented on code in PR #28226:
URL: https://github.com/apache/flink/pull/28226#discussion_r3314516081
##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/application/ApplicationExceptionsHandlerTest.java:
##########
@@ -143,6 +159,116 @@ void testExceptionWithJobId() throws Exception {
assertThat(exceptionInfo.getJobId()).isEqualTo(jobId);
}
+ @Test
+ void testMaxExceptionsLimitsHistorySize() throws Exception {
+ final List<ApplicationExceptionHistoryEntry> exceptionHistory = new
ArrayList<>();
+ for (int i = 0; i < 5; i++) {
+ exceptionHistory.add(
+ new ApplicationExceptionHistoryEntry(
+ new RuntimeException("exception #" + i),
+ System.currentTimeMillis(),
+ null));
+ }
+
+ final ArchivedApplication applicationWithExceptions =
+ new ArchivedApplication(
+ archivedApplication.getApplicationId(),
+ archivedApplication.getApplicationName(),
+ ApplicationState.FAILED,
+ new long[] {1L, 1L, 1L, 1L, 1L, 1L, 1L},
+ Collections.emptyMap(),
+ exceptionHistory);
+
+ testingRestfulGateway =
+ new TestingRestfulGateway.Builder()
+ .setRequestApplicationFunction(
+ applicationId ->
+ CompletableFuture.completedFuture(
+ applicationWithExceptions))
+ .build();
+
+ final HandlerRequest<EmptyRequestBody> limitedRequest =
+ createRequest(archivedApplication.getApplicationId(), 2);
+
+ final ApplicationExceptionsInfoWithHistory response =
+ handler.handleRequest(limitedRequest,
testingRestfulGateway).get();
+
+ assertThat(response.getExceptionHistory().getEntries()).hasSize(2);
+ }
+
+ @Test
+ void testDefaultCapAppliedWhenMaxExceptionsNotProvided() throws Exception {
+ final int totalExceptions =
ApplicationExceptionsHandler.MAX_NUMBER_EXCEPTION_TO_REPORT + 5;
+ final List<ApplicationExceptionHistoryEntry> exceptionHistory = new
ArrayList<>();
+ for (int i = 0; i < totalExceptions; i++) {
+ exceptionHistory.add(
+ new ApplicationExceptionHistoryEntry(
+ new RuntimeException("exception #" + i),
+ System.currentTimeMillis(),
+ null));
+ }
+
+ final ArchivedApplication applicationWithExceptions =
+ new ArchivedApplication(
+ archivedApplication.getApplicationId(),
+ archivedApplication.getApplicationName(),
+ ApplicationState.FAILED,
+ new long[] {1L, 1L, 1L, 1L, 1L, 1L, 1L},
+ Collections.emptyMap(),
+ exceptionHistory);
+
+ testingRestfulGateway =
+ new TestingRestfulGateway.Builder()
+ .setRequestApplicationFunction(
+ applicationId ->
+ CompletableFuture.completedFuture(
+ applicationWithExceptions))
+ .build();
+
+ final ApplicationExceptionsInfoWithHistory response =
+ handler.handleRequest(handlerRequest,
testingRestfulGateway).get();
+
+ assertThat(response.getExceptionHistory().getEntries())
+
.hasSize(ApplicationExceptionsHandler.MAX_NUMBER_EXCEPTION_TO_REPORT);
+ }
+
+ @Test
+ void testMaxExceptionsLargerThanHistorySizeReturnsAllEntries() throws
Exception {
+ final List<ApplicationExceptionHistoryEntry> exceptionHistory = new
ArrayList<>();
+ for (int i = 0; i < 3; i++) {
Review Comment:
good catch, extracted to `historySize`, and derived `oversizedMaxExceptions
= historySize + 7` so the intent is explicit in the loop bound and the
assertion. Applied the same treatment to `testMaxExceptionsLimitsHistorySize`
for consistency.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]