Skip to content

Commit

Permalink
Fix Error handling and add test coverage for Thrift2ProtoAdapter (#950)
Browse files Browse the repository at this point in the history
  • Loading branch information
natemort authored Nov 8, 2024
1 parent 96785e9 commit cc571fc
Show file tree
Hide file tree
Showing 3 changed files with 1,083 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
import io.grpc.StatusRuntimeException;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
import org.apache.thrift.TException;
Expand Down Expand Up @@ -203,7 +204,7 @@ public RestartWorkflowExecutionResponse RestartWorkflowExecution(
RestartWorkflowExecutionRequest restartRequest)
throws BadRequestError, ServiceBusyError, DomainNotActiveError, LimitExceededError,
EntityNotExistsError, ClientVersionNotSupportedError, TException {
throw new IllegalArgumentException("unimplemented");
throw new UnsupportedOperationException("unimplemented");
}

@Override
Expand Down Expand Up @@ -851,7 +852,7 @@ public void DeprecateDomain(
public void RestartWorkflowExecution(
RestartWorkflowExecutionRequest restartRequest, AsyncMethodCallback resultHandler)
throws TException {
throw new IllegalArgumentException("unimplemented");
throw new UnsupportedOperationException("unimplemented");
}

@Override
Expand Down Expand Up @@ -880,7 +881,7 @@ public void StartWorkflowExecutionAsync(
resultHandler.onComplete(
ResponseMapper.startWorkflowExecutionAsyncResponse(response));
} catch (Exception e) {
resultHandler.onError(e);
handleAsyncException(resultHandler, e);
}
},
ForkJoinPool.commonPool());
Expand Down Expand Up @@ -1003,7 +1004,7 @@ public void SignalWorkflowExecution(
com.uber.cadence.api.v1.SignalWorkflowExecutionResponse response = resultFuture.get();
resultHandler.onComplete(null);
} catch (Exception e) {
resultHandler.onError(e);
handleAsyncException(resultHandler, e);
}
},
ForkJoinPool.commonPool());
Expand All @@ -1025,7 +1026,7 @@ public void SignalWithStartWorkflowExecutionAsync(
SignalWithStartWorkflowExecutionAsyncRequest signalWithStartRequest,
AsyncMethodCallback resultHandler)
throws TException {
throw new IllegalArgumentException("unimplemented");
throw new UnsupportedOperationException("unimplemented");
}

@Override
Expand Down Expand Up @@ -1199,7 +1200,7 @@ public void StartWorkflowExecutionWithTimeout(
com.uber.cadence.api.v1.StartWorkflowExecutionResponse response = resultFuture.get();
resultHandler.onComplete(ResponseMapper.startWorkflowExecutionResponse(response));
} catch (Exception e) {
resultHandler.onError(e);
handleAsyncException(resultHandler, e);
}
},
ForkJoinPool.commonPool());
Expand Down Expand Up @@ -1230,7 +1231,7 @@ public void StartWorkflowExecutionAsyncWithTimeout(
resultHandler.onComplete(
ResponseMapper.startWorkflowExecutionAsyncResponse(response));
} catch (Exception e) {
resultHandler.onError(e);
handleAsyncException(resultHandler, e);
}
},
ForkJoinPool.commonPool());
Expand Down Expand Up @@ -1276,7 +1277,7 @@ public void GetWorkflowExecutionHistoryWithTimeout(
resultHandler.onComplete(
ResponseMapper.getWorkflowExecutionHistoryResponse(response));
} catch (Exception e) {
resultHandler.onError(e);
handleAsyncException(resultHandler, e);
}
},
ForkJoinPool.commonPool());
Expand All @@ -1293,4 +1294,13 @@ public void SignalWorkflowExecutionWithTimeout(
throws TException {
throw new UnsupportedOperationException("not implemented");
}

private void handleAsyncException(AsyncMethodCallback callback, Exception exception) {
if (exception instanceof ExecutionException
&& exception.getCause() instanceof StatusRuntimeException) {
callback.onError(ErrorMapper.Error(((StatusRuntimeException) exception.getCause())));
} else {
callback.onError(exception);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,65 @@ public final class ProtoObjects {
public static final UpdateDomainResponse UPDATE_DOMAIN_RESPONSE =
UpdateDomainResponse.newBuilder().setDomain(DOMAIN).build();

public static final GetSearchAttributesRequest GET_SEARCH_ATTRIBUTES_REQUEST =
GetSearchAttributesRequest.getDefaultInstance();

public static final RegisterDomainResponse REGISTER_DOMAIN_RESPONSE =
RegisterDomainResponse.getDefaultInstance();

public static final DeprecateDomainResponse DEPRECATE_DOMAIN_RESPONSE =
DeprecateDomainResponse.getDefaultInstance();

public static final SignalWorkflowExecutionResponse SIGNAL_WORKFLOW_EXECUTION_RESPONSE =
SignalWorkflowExecutionResponse.getDefaultInstance();

public static final RequestCancelWorkflowExecutionResponse
REQUEST_CANCEL_WORKFLOW_EXECUTION_RESPONSE =
RequestCancelWorkflowExecutionResponse.getDefaultInstance();

public static final TerminateWorkflowExecutionResponse TERMINATE_WORKFLOW_EXECUTION_RESPONSE =
TerminateWorkflowExecutionResponse.getDefaultInstance();

public static final GetClusterInfoRequest GET_CLUSTER_INFO_REQUEST =
GetClusterInfoRequest.getDefaultInstance();

public static final RespondDecisionTaskFailedResponse RESPOND_DECISION_TASK_FAILED_RESPONSE =
RespondDecisionTaskFailedResponse.getDefaultInstance();

public static final RespondActivityTaskCompletedResponse
RESPOND_ACTIVITY_TASK_COMPLETED_RESPONSE =
RespondActivityTaskCompletedResponse.getDefaultInstance();

public static final RespondActivityTaskCompletedByIDResponse
RESPOND_ACTIVITY_TASK_COMPLETED_BY_ID_RESPONSE =
RespondActivityTaskCompletedByIDResponse.getDefaultInstance();

public static final RespondActivityTaskFailedResponse RESPOND_ACTIVITY_TASK_FAILED_RESPONSE =
RespondActivityTaskFailedResponse.getDefaultInstance();

public static final RespondActivityTaskFailedByIDResponse
RESPOND_ACTIVITY_TASK_FAILED_BY_ID_RESPONSE =
RespondActivityTaskFailedByIDResponse.getDefaultInstance();

public static final RespondActivityTaskCanceledResponse RESPOND_ACTIVITY_TASK_CANCELED_RESPONSE =
RespondActivityTaskCanceledResponse.getDefaultInstance();

public static final RespondActivityTaskCanceledByIDResponse
RESPOND_ACTIVITY_TASK_CANCELED_BY_ID_RESPONSE =
RespondActivityTaskCanceledByIDResponse.getDefaultInstance();

public static final RespondQueryTaskCompletedResponse RESPOND_QUERY_TASK_COMPLETED_RESPONSE =
RespondQueryTaskCompletedResponse.getDefaultInstance();

public static final ResetStickyTaskListResponse RESET_STICKY_TASK_LIST_RESPONSE =
ResetStickyTaskListResponse.getDefaultInstance();

public static final RefreshWorkflowTasksRequest REFRESH_WORKFLOW_TASKS_REQUEST =
RefreshWorkflowTasksRequest.getDefaultInstance();

public static final RefreshWorkflowTasksResponse REFRESH_WORKFLOW_TASKS_RESPONSE =
RefreshWorkflowTasksResponse.getDefaultInstance();

private ProtoObjects() {}

private static Payload payload(String value) {
Expand Down
Loading

0 comments on commit cc571fc

Please sign in to comment.