Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -613,13 +613,10 @@ private void executeAsync(Callable<Void> callable) throws UserCodeExecutionExcep
private static <T> void parseAndThrow(Future<T> future, ExecutionException e)
throws UserCodeExecutionException {
future.cancel(true);
if (e.getCause() == null) {
throw new UserCodeExecutionException(e);
Throwable cause = e.getCause();
if (cause instanceof UserCodeExecutionException) {
throw (UserCodeExecutionException) cause;
}
Throwable cause = checkStateNotNull(e.getCause());
if (cause instanceof UserCodeQuotaException) {
throw new UserCodeQuotaException(cause);
}
throw new UserCodeExecutionException(cause);
throw new UserCodeExecutionException(cause == null ? e : cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ public void givenCallerThrowsUserCodeExecutionException_emitsIntoFailurePCollect
pipeline.run();
}

@Test
public void givenCallerThrowsNonUserCodeException_emitsWrappedUserCodeExecutionException() {
Result<Response> result =
pipeline
.apply(Create.of(new Request("a")))
.apply(Call.of(new CallerThrowsRuntimeException(), NON_DETERMINISTIC_RESPONSE_CODER));

PCollection<ApiIOError> failures = result.getFailures();
PAssert.thatSingleton(countStackTracesOf(failures, UserCodeExecutionException.class))
.isEqualTo(1L);

pipeline.run();
}

@Test
public void givenCallerThrowsQuotaException_emitsIntoFailurePCollection() {
Result<Response> result =
Expand Down Expand Up @@ -142,22 +156,39 @@ public void givenCallerTimeout_emitsFailurePCollection() {
}

@Test
public void givenCallerThrowsTimeoutException_emitsFailurePCollection() {
public void givenCallerThrowsTimeoutException_thenPreservesExceptionType() {
Result<Response> result =
pipeline
.apply(Create.of(new Request("a")))
.apply(Call.of(new CallerThrowsTimeout(), NON_DETERMINISTIC_RESPONSE_CODER));

PCollection<ApiIOError> failures = result.getFailures();
PAssert.thatSingleton(countStackTracesOf(failures, UserCodeExecutionException.class))
.isEqualTo(1L);
.isEqualTo(0L);
PAssert.thatSingleton(countStackTracesOf(failures, UserCodeQuotaException.class)).isEqualTo(0L);
PAssert.thatSingleton(countStackTracesOf(failures, UserCodeTimeoutException.class))
.isEqualTo(1L);

pipeline.run();
}

@Test
public void givenCallerThrowsRemoteSystemException_thenPreservesExceptionType() {
Result<Response> result =
pipeline
.apply(Create.of(new Request("a")))
.apply(
Call.of(new CallerThrowsRemoteSystemException(), NON_DETERMINISTIC_RESPONSE_CODER));

PCollection<ApiIOError> failures = result.getFailures();
PAssert.thatSingleton(countStackTracesOf(failures, UserCodeRemoteSystemException.class))
.isEqualTo(1L);
PAssert.thatSingleton(countStackTracesOf(failures, UserCodeExecutionException.class))
.isEqualTo(0L);

pipeline.run();
}

@Test
public void givenSetupThrowsUserCodeExecutionException_throwsError() {
pipeline
Expand Down Expand Up @@ -376,6 +407,14 @@ public Response call(Request request) throws UserCodeExecutionException {
}
}

private static class CallerThrowsRuntimeException implements Caller<Request, Response> {

@Override
public Response call(Request request) {
throw new RuntimeException("unexpected error");
}
}

private static class CallerThrowsTimeout implements Caller<Request, Response> {

@Override
Expand All @@ -384,6 +423,14 @@ public Response call(Request request) throws UserCodeExecutionException {
}
}

private static class CallerThrowsRemoteSystemException implements Caller<Request, Response> {

@Override
public Response call(Request request) throws UserCodeExecutionException {
throw new UserCodeRemoteSystemException("");
}
}

private static class CallerInvokesQuotaException implements Caller<Request, Response> {

@Override
Expand Down
Loading