Skip to content

Commit

Permalink
add automatic validation test for runtime exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
skovati committed Nov 13, 2023
1 parent a993b7f commit cf9fc37
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,34 @@ void validationSuccess() throws IOException, InterruptedException {
final ActivityValidation activityValidation = activityValidations.get((long) activityId);
assertEquals(new ActivityValidation.Success(), activityValidation);
}

@Test
void exceptionDuringValidationHandled() throws IOException, InterruptedException {
final var exceptionActivityId = hasura.insertActivity(
planId,
"ExceptionActivity",
"1h",
Json.createObjectBuilder().add("throwException", true).build());

// sleep to make sure exception activity is picked up
Thread.sleep(1000); // TODO consider a while loop here

final var biteActivityId = hasura.insertActivity(
planId,
"BiteBanana",
"1h",
Json.createObjectBuilder().add("biteSize", 1).build());

Thread.sleep(1000); // TODO consider a while loop here

final var activityValidations = hasura.getActivityValidations(planId);

final ActivityValidation exceptionValidations = activityValidations.get((long) exceptionActivityId);
final ActivityValidation biteValidations = activityValidations.get((long) biteActivityId);

// then make sure the exception was caught and serialized, and didn't crash the worker thread
assertEquals(new ActivityValidation.RuntimeError("Throwing runtime exception during validation"), exceptionValidations);
// if the above is true, bite banana will have its validation still
assertEquals(new ActivityValidation.Success(), biteValidations);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ record Success() implements ActivityValidation {}
record InstantiationFailure(List<String> extraneousArguments, List<String> missingArguments, List<?> unconstructableArguments) implements ActivityValidation {}
record ValidationFailure(List<ValidationNotice> notices) implements ActivityValidation {}
record NoSuchActivityTypeFailure(String message, String activityType) implements ActivityValidation {}
record RuntimeError(String message) implements ActivityValidation {}

record ValidationNotice(List<String> subjects, String message) { }
record UnconstructableArgument(String name, String failure) { }
Expand Down Expand Up @@ -44,6 +45,7 @@ static ActivityValidation fromJSON(JsonObject obj) {
getStringArray($, "subjects"),
$.asJsonObject().getString("message"))));
case "NO_SUCH_ACTIVITY_TYPE" -> new NoSuchActivityTypeFailure(errors.getJsonObject("noSuchActivityError").getString("message"), errors.getJsonObject("noSuchActivityError").getString("activity_type"));
case "RUNTIME_EXCEPTION" -> new RuntimeError(errors.getString("runtimeException"));
default -> throw new RuntimeException("Unhandled error type: " + type);
};
}
Expand Down

0 comments on commit cf9fc37

Please sign in to comment.