From d1313138e8a30a897241cac6b1f6d00ac927f0f1 Mon Sep 17 00:00:00 2001 From: Shijie Sheng Date: Tue, 22 Apr 2025 16:03:48 -0700 Subject: [PATCH] WIP --- .../common/WorkflowExecutionUtils.java | 11 + .../internal/testservice/ActivityId.java | 17 +- .../testservice/DecisionTaskToken.java | 11 +- .../internal/testservice/ExecutionId.java | 18 +- .../internal/testservice/RequestContext.java | 16 +- .../internal/testservice/RetryState.java | 48 +- .../internal/testservice/StateMachine.java | 19 +- .../internal/testservice/StateMachines.java | 122 +- .../testservice/TestWorkflowMutableState.java | 130 +- .../TestWorkflowMutableStateAttrUtil.java | 69 +- .../TestWorkflowMutableStateImpl.java | 352 ++-- .../testservice/TestWorkflowService.java | 1579 +++++------------ .../testservice/TestWorkflowStore.java | 20 +- .../testservice/TestWorkflowStoreImpl.java | 123 +- .../serviceclient/IWorkflowServiceV4.java | 15 +- .../serviceclient/WorkflowServiceGrpc.java | 758 ++++---- .../exceptions/BadRequestException.java | 28 + .../exceptions/EntityNotExistsException.java | 23 + .../exceptions/InternalServiceException.java | 4 + .../exceptions/QueryFailedException.java | 25 + .../exceptions/ServiceClientException.java | 4 + ...Util_validateScheduleActivityTaskTest.java | 41 +- ...validateStartChildExecutionAttributes.java | 28 +- 23 files changed, 1392 insertions(+), 2069 deletions(-) create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/BadRequestException.java create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/QueryFailedException.java diff --git a/src/main/java/com/uber/cadence/internal/common/WorkflowExecutionUtils.java b/src/main/java/com/uber/cadence/internal/common/WorkflowExecutionUtils.java index 5d9add40c..0e865998f 100644 --- a/src/main/java/com/uber/cadence/internal/common/WorkflowExecutionUtils.java +++ b/src/main/java/com/uber/cadence/internal/common/WorkflowExecutionUtils.java @@ -372,6 +372,17 @@ public static boolean isWorkflowExecutionCompletedEvent(HistoryEvent event) { || event.getEventType() == EventType.WorkflowExecutionTerminated)); } + public static boolean isWorkflowExecutionCompletedEvent( + com.uber.cadence.api.v1.HistoryEvent event) { + return ((event != null) + && (event.hasWorkflowExecutionCompletedEventAttributes() + || event.hasWorkflowExecutionCanceledEventAttributes() + || event.hasWorkflowExecutionFailedEventAttributes() + || event.hasWorkflowExecutionTimedOutEventAttributes() + || event.hasWorkflowExecutionContinuedAsNewEventAttributes() + || event.hasWorkflowExecutionTerminatedEventAttributes())); + } + public static boolean isWorkflowExecutionCompleteDecision(Decision decision) { return ((decision != null) && (decision.getDecisionType() == DecisionType.CompleteWorkflowExecution diff --git a/src/main/java/com/uber/cadence/internal/testservice/ActivityId.java b/src/main/java/com/uber/cadence/internal/testservice/ActivityId.java index 7986a52f7..27b13c25f 100644 --- a/src/main/java/com/uber/cadence/internal/testservice/ActivityId.java +++ b/src/main/java/com/uber/cadence/internal/testservice/ActivityId.java @@ -18,8 +18,8 @@ package com.uber.cadence.internal.testservice; import com.google.common.base.Throwables; -import com.uber.cadence.InternalServiceError; -import com.uber.cadence.WorkflowExecution; +import com.uber.cadence.api.v1.WorkflowExecution; +import com.uber.cadence.serviceclient.exceptions.InternalServiceException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; @@ -39,7 +39,10 @@ final class ActivityId { } ActivityId(String domain, String workflowId, String runId, String id) { - this(domain, new WorkflowExecution().setWorkflowId(workflowId).setRunId(runId), id); + this( + domain, + WorkflowExecution.newBuilder().setWorkflowId(workflowId).setRunId(runId).build(), + id); } public ActivityId(ExecutionId executionId, String id) { @@ -85,7 +88,7 @@ public String toString() { } /** Used for task tokens. */ - public byte[] toBytes() throws InternalServiceError { + public byte[] toBytes() throws InternalServiceException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bout); try { @@ -96,11 +99,11 @@ public byte[] toBytes() throws InternalServiceError { out.writeUTF(id); return bout.toByteArray(); } catch (IOException e) { - throw new InternalServiceError(Throwables.getStackTraceAsString(e)); + throw new InternalServiceException(e); } } - static ActivityId fromBytes(byte[] serialized) throws InternalServiceError { + static ActivityId fromBytes(byte[] serialized) throws InternalServiceException { ByteArrayInputStream bin = new ByteArrayInputStream(serialized); DataInputStream in = new DataInputStream(bin); try { @@ -110,7 +113,7 @@ static ActivityId fromBytes(byte[] serialized) throws InternalServiceError { String id = in.readUTF(); return new ActivityId(domain, workflowId, runId, id); } catch (IOException e) { - throw new InternalServiceError(Throwables.getStackTraceAsString(e)); + throw new InternalServiceException(Throwables.getStackTraceAsString(e)); } } diff --git a/src/main/java/com/uber/cadence/internal/testservice/DecisionTaskToken.java b/src/main/java/com/uber/cadence/internal/testservice/DecisionTaskToken.java index 9daadc03b..ae5709802 100644 --- a/src/main/java/com/uber/cadence/internal/testservice/DecisionTaskToken.java +++ b/src/main/java/com/uber/cadence/internal/testservice/DecisionTaskToken.java @@ -17,8 +17,7 @@ package com.uber.cadence.internal.testservice; -import com.google.common.base.Throwables; -import com.uber.cadence.InternalServiceError; +import com.uber.cadence.serviceclient.exceptions.InternalServiceException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; @@ -45,13 +44,13 @@ int getHistorySize() { } /** Used for task tokens. */ - byte[] toBytes() throws InternalServiceError { + byte[] toBytes() throws InternalServiceException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bout); try { addBytes(out); } catch (IOException e) { - throw new InternalServiceError(Throwables.getStackTraceAsString(e)); + throw new InternalServiceException(e); } return bout.toByteArray(); } @@ -61,7 +60,7 @@ private void addBytes(DataOutputStream out) throws IOException { out.writeInt(historySize); } - static DecisionTaskToken fromBytes(byte[] serialized) throws InternalServiceError { + static DecisionTaskToken fromBytes(byte[] serialized) throws InternalServiceException { ByteArrayInputStream bin = new ByteArrayInputStream(serialized); DataInputStream in = new DataInputStream(bin); try { @@ -69,7 +68,7 @@ static DecisionTaskToken fromBytes(byte[] serialized) throws InternalServiceErro int historySize = in.readInt(); return new DecisionTaskToken(executionId, historySize); } catch (IOException e) { - throw new InternalServiceError(Throwables.getStackTraceAsString(e)); + throw new InternalServiceException(e); } } } diff --git a/src/main/java/com/uber/cadence/internal/testservice/ExecutionId.java b/src/main/java/com/uber/cadence/internal/testservice/ExecutionId.java index 2c05070f4..330678c90 100644 --- a/src/main/java/com/uber/cadence/internal/testservice/ExecutionId.java +++ b/src/main/java/com/uber/cadence/internal/testservice/ExecutionId.java @@ -17,9 +17,8 @@ package com.uber.cadence.internal.testservice; -import com.google.common.base.Throwables; -import com.uber.cadence.InternalServiceError; -import com.uber.cadence.WorkflowExecution; +import com.uber.cadence.api.v1.WorkflowExecution; +import com.uber.cadence.serviceclient.exceptions.InternalServiceException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; @@ -40,7 +39,10 @@ final class ExecutionId { ExecutionId(String domain, String workflowId, String runId) { this( domain, - new WorkflowExecution().setWorkflowId(Objects.requireNonNull(workflowId)).setRunId(runId)); + WorkflowExecution.newBuilder() + .setWorkflowId(Objects.requireNonNull(workflowId)) + .setRunId(runId) + .build()); } public String getDomain() { @@ -81,13 +83,13 @@ public String toString() { } /** Used for task tokens. */ - byte[] toBytes() throws InternalServiceError { + byte[] toBytes() throws InternalServiceException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bout); try { addBytes(out); } catch (IOException e) { - throw new InternalServiceError(Throwables.getStackTraceAsString(e)); + throw new InternalServiceException(e); } return bout.toByteArray(); } @@ -100,13 +102,13 @@ void addBytes(DataOutputStream out) throws IOException { } } - static ExecutionId fromBytes(byte[] serialized) throws InternalServiceError { + static ExecutionId fromBytes(byte[] serialized) throws InternalServiceException { ByteArrayInputStream bin = new ByteArrayInputStream(serialized); DataInputStream in = new DataInputStream(bin); try { return readFromBytes(in); } catch (IOException e) { - throw new InternalServiceError(Throwables.getStackTraceAsString(e)); + throw new InternalServiceException(e); } } diff --git a/src/main/java/com/uber/cadence/internal/testservice/RequestContext.java b/src/main/java/com/uber/cadence/internal/testservice/RequestContext.java index 44e0c283b..c85db81d7 100644 --- a/src/main/java/com/uber/cadence/internal/testservice/RequestContext.java +++ b/src/main/java/com/uber/cadence/internal/testservice/RequestContext.java @@ -17,14 +17,14 @@ package com.uber.cadence.internal.testservice; -import com.uber.cadence.BadRequestError; -import com.uber.cadence.EntityNotExistsError; -import com.uber.cadence.HistoryEvent; -import com.uber.cadence.InternalServiceError; -import com.uber.cadence.WorkflowExecution; +import com.uber.cadence.api.v1.HistoryEvent; +import com.uber.cadence.api.v1.WorkflowExecution; import com.uber.cadence.internal.common.WorkflowExecutionUtils; import com.uber.cadence.internal.testservice.TestWorkflowStore.ActivityTask; import com.uber.cadence.internal.testservice.TestWorkflowStore.DecisionTask; +import com.uber.cadence.serviceclient.exceptions.BadRequestException; +import com.uber.cadence.serviceclient.exceptions.EntityNotExistsException; +import com.uber.cadence.serviceclient.exceptions.InternalServiceException; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -36,7 +36,7 @@ final class RequestContext { @FunctionalInterface interface CommitCallback { - void apply(int historySize) throws InternalServiceError, BadRequestError; + void apply(int historySize) throws InternalServiceException, BadRequestException; } static final class Timer { @@ -206,12 +206,12 @@ void onCommit(CommitCallback callback) { /** @return nextEventId */ long commitChanges(TestWorkflowStore store) - throws InternalServiceError, EntityNotExistsError, BadRequestError { + throws InternalServiceException, EntityNotExistsException, BadRequestException { return store.save(this); } /** Called by {@link TestWorkflowStore#save(RequestContext)} */ - void fireCallbacks(int historySize) throws InternalServiceError, BadRequestError { + void fireCallbacks(int historySize) throws InternalServiceException, BadRequestException { for (CommitCallback callback : commitCallbacks) { callback.apply(historySize); } diff --git a/src/main/java/com/uber/cadence/internal/testservice/RetryState.java b/src/main/java/com/uber/cadence/internal/testservice/RetryState.java index 085eac0e0..efadb96ae 100644 --- a/src/main/java/com/uber/cadence/internal/testservice/RetryState.java +++ b/src/main/java/com/uber/cadence/internal/testservice/RetryState.java @@ -17,8 +17,8 @@ package com.uber.cadence.internal.testservice; -import com.uber.cadence.BadRequestError; -import com.uber.cadence.RetryPolicy; +import com.uber.cadence.api.v1.RetryPolicy; +import com.uber.cadence.serviceclient.exceptions.BadRequestException; import java.util.List; import java.util.concurrent.TimeUnit; @@ -28,14 +28,14 @@ final class RetryState { private final long expirationTime; private final int attempt; - RetryState(RetryPolicy retryPolicy, long expirationTime) throws BadRequestError { + RetryState(RetryPolicy retryPolicy, long expirationTime) throws BadRequestException { this(validateRetryPolicy(retryPolicy), expirationTime, 0); } private RetryState(RetryPolicy retryPolicy, long expirationTime, int attempt) { this.retryPolicy = retryPolicy; this.expirationTime = - retryPolicy.getExpirationIntervalInSeconds() == 0 ? Long.MAX_VALUE : expirationTime; + retryPolicy.getExpirationInterval().getSeconds() == 0 ? Long.MAX_VALUE : expirationTime; this.attempt = attempt; } @@ -68,10 +68,10 @@ && getAttempt() >= retryPolicy.getMaximumAttempts() - 1) { // MaximumAttempts is the total attempts, including initial (non-retry) attempt. return 0; } - long initInterval = TimeUnit.SECONDS.toMillis(retryPolicy.getInitialIntervalInSeconds()); + long initInterval = TimeUnit.SECONDS.toMillis(retryPolicy.getInitialInterval().getSeconds()); long nextInterval = (long) (initInterval * Math.pow(retryPolicy.getBackoffCoefficient(), getAttempt())); - long maxInterval = TimeUnit.SECONDS.toMillis(retryPolicy.getMaximumIntervalInSeconds()); + long maxInterval = TimeUnit.SECONDS.toMillis(retryPolicy.getMaximumInterval().getSeconds()); if (nextInterval <= 0) { // math.Pow() could overflow if (maxInterval > 0) { @@ -93,37 +93,37 @@ && getAttempt() >= retryPolicy.getMaximumAttempts() - 1) { } // check if error is non-retriable - List nonRetriableErrorReasons = retryPolicy.getNonRetriableErrorReasons(); - if (nonRetriableErrorReasons != null) { - for (String err : nonRetriableErrorReasons) { - if (errReason.equals(err)) { - return 0; - } + List nonRetriableErrorReasons = retryPolicy.getNonRetryableErrorReasonsList(); + for (String err : nonRetriableErrorReasons) { + if (errReason.equals(err)) { + return 0; } } return (int) TimeUnit.MILLISECONDS.toSeconds((long) Math.ceil((double) backoffInterval)); } - static RetryPolicy validateRetryPolicy(RetryPolicy policy) throws BadRequestError { - if (policy.getInitialIntervalInSeconds() <= 0) { - throw new BadRequestError("InitialIntervalInSeconds must be greater than 0 on retry policy."); + static RetryPolicy validateRetryPolicy(RetryPolicy policy) throws BadRequestException { + if (policy.getInitialInterval().getSeconds() <= 0) { + throw new BadRequestException( + "InitialIntervalInSeconds must be greater than 0 on retry policy."); } if (policy.getBackoffCoefficient() < 1) { - throw new BadRequestError("BackoffCoefficient cannot be less than 1 on retry policy."); + throw new BadRequestException("BackoffCoefficient cannot be less than 1 on retry policy."); } - if (policy.getMaximumIntervalInSeconds() < 0) { - throw new BadRequestError("MaximumIntervalInSeconds cannot be less than 0 on retry policy."); + if (policy.getMaximumInterval().getSeconds() < 0) { + throw new BadRequestException( + "MaximumIntervalInSeconds cannot be less than 0 on retry policy."); } - if (policy.getMaximumIntervalInSeconds() > 0 - && policy.getMaximumIntervalInSeconds() < policy.getInitialIntervalInSeconds()) { - throw new BadRequestError( + if (policy.getMaximumInterval().getSeconds() > 0 + && policy.getMaximumInterval().getSeconds() < policy.getInitialInterval().getSeconds()) { + throw new BadRequestException( "MaximumIntervalInSeconds cannot be less than InitialIntervalInSeconds on retry policy."); } if (policy.getMaximumAttempts() < 0) { - throw new BadRequestError("MaximumAttempts cannot be less than 0 on retry policy."); + throw new BadRequestException("MaximumAttempts cannot be less than 0 on retry policy."); } - if (policy.getMaximumAttempts() == 0 && policy.getExpirationIntervalInSeconds() == 0) { - throw new BadRequestError( + if (policy.getMaximumAttempts() == 0 && policy.getExpirationInterval().getSeconds() == 0) { + throw new BadRequestException( "MaximumAttempts and ExpirationIntervalInSeconds are both 0. At least one of them must be specified."); } return policy; diff --git a/src/main/java/com/uber/cadence/internal/testservice/StateMachine.java b/src/main/java/com/uber/cadence/internal/testservice/StateMachine.java index 844f1bee8..e326ca869 100644 --- a/src/main/java/com/uber/cadence/internal/testservice/StateMachine.java +++ b/src/main/java/com/uber/cadence/internal/testservice/StateMachine.java @@ -17,10 +17,10 @@ package com.uber.cadence.internal.testservice; -import com.uber.cadence.BadRequestError; -import com.uber.cadence.InternalServiceError; import com.uber.cadence.internal.testservice.StateMachines.Action; import com.uber.cadence.internal.testservice.StateMachines.State; +import com.uber.cadence.serviceclient.exceptions.BadRequestException; +import com.uber.cadence.serviceclient.exceptions.InternalServiceException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -45,7 +45,7 @@ final class StateMachine { interface Callback { void apply(RequestContext ctx, D data, R request, long referenceId) - throws InternalServiceError, BadRequestError; + throws InternalServiceException, BadRequestException; } /** @@ -57,7 +57,7 @@ interface DynamicCallback { /** @return state after the action */ State apply(RequestContext ctx, D data, R request, long referenceId) - throws InternalServiceError, BadRequestError; + throws InternalServiceException, BadRequestException; } private static class Transition { @@ -110,7 +110,7 @@ public String toString() { private interface TransitionDestination { State apply(RequestContext ctx, Data data, R request, long referenceId) - throws InternalServiceError, BadRequestError; + throws InternalServiceException, BadRequestException; } private static class FixedTransitionDestination @@ -132,7 +132,7 @@ public String toString() { @Override public State apply(RequestContext ctx, Data data, R request, long referenceId) - throws InternalServiceError, BadRequestError { + throws InternalServiceException, BadRequestException { callback.apply(ctx, data, request, referenceId); return state; } @@ -158,7 +158,7 @@ public String toString() { @Override public State apply(RequestContext ctx, Data data, R request, long referenceId) - throws InternalServiceError, BadRequestError { + throws InternalServiceException, BadRequestException { state = callback.apply(ctx, data, request, referenceId); for (State s : expectedStates) { if (s == state) { @@ -221,13 +221,14 @@ StateMachine add( } void action(Action action, RequestContext context, R request, long referenceId) - throws InternalServiceError, BadRequestError { + throws InternalServiceException, BadRequestException { Transition transition = new Transition(state, action); @SuppressWarnings("unchecked") TransitionDestination destination = (TransitionDestination) transitions.get(transition); if (destination == null) { - throw new InternalServiceError("Invalid " + transition + ", history: " + transitionHistory); + throw new InternalServiceException( + "Invalid " + transition + ", history: " + transitionHistory); } state = destination.apply(context, data, request, referenceId); transitionHistory.add(transition); diff --git a/src/main/java/com/uber/cadence/internal/testservice/StateMachines.java b/src/main/java/com/uber/cadence/internal/testservice/StateMachines.java index d0667112d..42dd4e655 100644 --- a/src/main/java/com/uber/cadence/internal/testservice/StateMachines.java +++ b/src/main/java/com/uber/cadence/internal/testservice/StateMachines.java @@ -36,78 +36,13 @@ import static com.uber.cadence.internal.testservice.StateMachines.State.STARTED; import static com.uber.cadence.internal.testservice.StateMachines.State.TIMED_OUT; -import com.uber.cadence.ActivityTaskCancelRequestedEventAttributes; -import com.uber.cadence.ActivityTaskCanceledEventAttributes; -import com.uber.cadence.ActivityTaskCompletedEventAttributes; -import com.uber.cadence.ActivityTaskFailedEventAttributes; -import com.uber.cadence.ActivityTaskScheduledEventAttributes; -import com.uber.cadence.ActivityTaskStartedEventAttributes; -import com.uber.cadence.ActivityTaskTimedOutEventAttributes; -import com.uber.cadence.BadRequestError; -import com.uber.cadence.CancelTimerDecisionAttributes; -import com.uber.cadence.CancelWorkflowExecutionDecisionAttributes; -import com.uber.cadence.ChildWorkflowExecutionCanceledEventAttributes; -import com.uber.cadence.ChildWorkflowExecutionCompletedEventAttributes; -import com.uber.cadence.ChildWorkflowExecutionFailedCause; -import com.uber.cadence.ChildWorkflowExecutionFailedEventAttributes; -import com.uber.cadence.ChildWorkflowExecutionStartedEventAttributes; -import com.uber.cadence.ChildWorkflowExecutionTimedOutEventAttributes; -import com.uber.cadence.CompleteWorkflowExecutionDecisionAttributes; -import com.uber.cadence.ContinueAsNewWorkflowExecutionDecisionAttributes; -import com.uber.cadence.DecisionTaskCompletedEventAttributes; -import com.uber.cadence.DecisionTaskFailedEventAttributes; -import com.uber.cadence.DecisionTaskScheduledEventAttributes; -import com.uber.cadence.DecisionTaskStartedEventAttributes; -import com.uber.cadence.DecisionTaskTimedOutEventAttributes; -import com.uber.cadence.EntityNotExistsError; -import com.uber.cadence.EventType; -import com.uber.cadence.ExternalWorkflowExecutionSignaledEventAttributes; -import com.uber.cadence.FailWorkflowExecutionDecisionAttributes; -import com.uber.cadence.GetWorkflowExecutionHistoryRequest; -import com.uber.cadence.History; -import com.uber.cadence.HistoryEvent; -import com.uber.cadence.InternalServiceError; -import com.uber.cadence.PollForActivityTaskRequest; -import com.uber.cadence.PollForActivityTaskResponse; -import com.uber.cadence.PollForDecisionTaskRequest; -import com.uber.cadence.PollForDecisionTaskResponse; -import com.uber.cadence.RequestCancelActivityTaskDecisionAttributes; -import com.uber.cadence.RequestCancelWorkflowExecutionRequest; -import com.uber.cadence.RespondActivityTaskCanceledByIDRequest; -import com.uber.cadence.RespondActivityTaskCanceledRequest; -import com.uber.cadence.RespondActivityTaskCompletedByIDRequest; -import com.uber.cadence.RespondActivityTaskCompletedRequest; -import com.uber.cadence.RespondActivityTaskFailedByIDRequest; -import com.uber.cadence.RespondActivityTaskFailedRequest; -import com.uber.cadence.RespondDecisionTaskCompletedRequest; -import com.uber.cadence.RespondDecisionTaskFailedRequest; -import com.uber.cadence.RetryPolicy; -import com.uber.cadence.ScheduleActivityTaskDecisionAttributes; -import com.uber.cadence.SignalExternalWorkflowExecutionDecisionAttributes; -import com.uber.cadence.SignalExternalWorkflowExecutionFailedCause; -import com.uber.cadence.SignalExternalWorkflowExecutionFailedEventAttributes; -import com.uber.cadence.SignalExternalWorkflowExecutionInitiatedEventAttributes; -import com.uber.cadence.StartChildWorkflowExecutionDecisionAttributes; -import com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes; -import com.uber.cadence.StartChildWorkflowExecutionInitiatedEventAttributes; -import com.uber.cadence.StartTimerDecisionAttributes; -import com.uber.cadence.StartWorkflowExecutionRequest; -import com.uber.cadence.TimeoutType; -import com.uber.cadence.TimerCanceledEventAttributes; -import com.uber.cadence.TimerFiredEventAttributes; -import com.uber.cadence.TimerStartedEventAttributes; -import com.uber.cadence.WorkflowExecution; -import com.uber.cadence.WorkflowExecutionAlreadyStartedError; -import com.uber.cadence.WorkflowExecutionCancelRequestedEventAttributes; -import com.uber.cadence.WorkflowExecutionCanceledEventAttributes; -import com.uber.cadence.WorkflowExecutionCompletedEventAttributes; -import com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes; -import com.uber.cadence.WorkflowExecutionFailedEventAttributes; -import com.uber.cadence.WorkflowExecutionStartedEventAttributes; -import com.uber.cadence.WorkflowExecutionTimedOutEventAttributes; +import com.uber.cadence.api.v1.*; import com.uber.cadence.internal.testservice.TestWorkflowStore.ActivityTask; import com.uber.cadence.internal.testservice.TestWorkflowStore.DecisionTask; import com.uber.cadence.internal.testservice.TestWorkflowStore.TaskListId; +import com.uber.cadence.serviceclient.exceptions.BadRequestException; +import com.uber.cadence.serviceclient.exceptions.EntityNotExistsException; +import com.uber.cadence.serviceclient.exceptions.InternalServiceException; import java.util.List; import java.util.Optional; import java.util.OptionalLong; @@ -337,19 +272,17 @@ public static StateMachine newSignalExternalStateMachine() { private static void timeoutChildWorkflow( RequestContext ctx, ChildWorkflowData data, TimeoutType timeoutType, long notUsed) { StartChildWorkflowExecutionInitiatedEventAttributes ie = data.initiatedEvent; - ChildWorkflowExecutionTimedOutEventAttributes a = - new ChildWorkflowExecutionTimedOutEventAttributes() + ChildWorkflowExecutionTimedOutEventAttributes.Builder a = + ChildWorkflowExecutionTimedOutEventAttributes.newBuilder() .setDomain(ie.getDomain()) .setStartedEventId(data.startedEventId) .setWorkflowExecution(data.execution) .setWorkflowType(ie.getWorkflowType()) .setTimeoutType(timeoutType) .setInitiatedEventId(data.initiatedEventId); - HistoryEvent event = - new HistoryEvent() - .setEventType(EventType.ChildWorkflowExecutionTimedOut) - .setChildWorkflowExecutionTimedOutEventAttributes(a); - ctx.addEvent(event); + HistoryEvent.Builder event = + HistoryEvent.newBuilder().setChildWorkflowExecutionTimedOutEventAttributes(a); + ctx.addEvent(event.build()); } private static void startChildWorkflowFailed( @@ -357,16 +290,16 @@ private static void startChildWorkflowFailed( ChildWorkflowData data, StartChildWorkflowExecutionFailedEventAttributes a, long notUsed) { - a.setInitiatedEventId(data.initiatedEventId); - a.setWorkflowType(data.initiatedEvent.getWorkflowType()); - a.setWorkflowId(data.initiatedEvent.getWorkflowId()); - if (data.initiatedEvent.isSetDomain()) { - a.setDomain(data.initiatedEvent.getDomain()); + StartChildWorkflowExecutionFailedEventAttributes.Builder builder = a.toBuilder(); + builder.setInitiatedEventId(data.initiatedEventId); + builder.setWorkflowType(data.initiatedEvent.getWorkflowType()); + builder.setWorkflowId(data.initiatedEvent.getWorkflowId()); + if (!data.initiatedEvent.getDomain().isEmpty()) { + builder.setDomain(data.initiatedEvent.getDomain()); } HistoryEvent event = - new HistoryEvent() - .setEventType(EventType.StartChildWorkflowExecutionFailed) - .setStartChildWorkflowExecutionFailedEventAttributes(a); + HistoryEvent.newBuilder() + .setStartChildWorkflowExecutionFailedEventAttributes(a).build(); ctx.addEvent(event); } @@ -406,8 +339,9 @@ private static void childWorkflowFailed( ChildWorkflowData data, ChildWorkflowExecutionFailedEventAttributes a, long notUsed) { - a.setInitiatedEventId(data.initiatedEventId); - a.setStartedEventId(data.startedEventId); + ChildWorkflowExecutionFailedEventAttributes.Builder builder = a.toBuilder(); + builder.setInitiatedEventId(data.initiatedEventId); + builder.setStartedEventId(data.startedEventId); a.setWorkflowExecution(data.execution); a.setWorkflowType(data.initiatedEvent.getWorkflowType()); if (data.initiatedEvent.domain != null) { @@ -518,25 +452,25 @@ private static void addStartChildTask( private static void startWorkflow( RequestContext ctx, WorkflowData data, StartWorkflowExecutionRequest request, long notUsed) - throws BadRequestError { + throws BadRequestException { WorkflowExecutionStartedEventAttributes a = new WorkflowExecutionStartedEventAttributes(); if (request.isSetIdentity()) { a.setIdentity(request.getIdentity()); } if (!request.isSetTaskStartToCloseTimeoutSeconds()) { - throw new BadRequestError("missing taskStartToCloseTimeoutSeconds"); + throw new BadRequestException("missing taskStartToCloseTimeoutSeconds"); } a.setTaskStartToCloseTimeoutSeconds(request.getTaskStartToCloseTimeoutSeconds()); if (!request.isSetWorkflowType()) { - throw new BadRequestError("missing workflowType"); + throw new BadRequestException("missing workflowType"); } a.setWorkflowType(request.getWorkflowType()); if (!request.isSetTaskList()) { - throw new BadRequestError("missing taskList"); + throw new BadRequestException("missing taskList"); } a.setTaskList(request.getTaskList()); if (!request.isSetExecutionStartToCloseTimeoutSeconds()) { - throw new BadRequestError("missing executionStartToCloseTimeoutSeconds"); + throw new BadRequestException("missing executionStartToCloseTimeoutSeconds"); } a.setExecutionStartToCloseTimeoutSeconds(request.getExecutionStartToCloseTimeoutSeconds()); if (request.isSetInput()) { @@ -686,7 +620,7 @@ private static void scheduleActivityTask( ActivityTaskData data, ScheduleActivityTaskDecisionAttributes d, long decisionTaskCompletedEventId) - throws BadRequestError { + throws BadRequestException { int scheduleToCloseTimeoutSeconds = d.getScheduleToCloseTimeoutSeconds(); int scheduleToStartTimeoutSeconds = d.getScheduleToStartTimeoutSeconds(); RetryState retryState; @@ -839,8 +773,8 @@ private static void startDecisionTask( events = events.subList((int) data.previousStartedEventId, events.size()); } // get it from pervious started event id. - } catch (EntityNotExistsError entityNotExistsError) { - throw new InternalServiceError(entityNotExistsError.toString()); + } catch (EntityNotExistsException EntityNotExistsException) { + throw new InternalServiceException(EntityNotExistsException.toString()); } data.decisionTask.setHistory(new History().setEvents(events)); data.startedEventId = startedEventId; diff --git a/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowMutableState.java b/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowMutableState.java index f662ebedd..cfc6beeee 100644 --- a/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowMutableState.java +++ b/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowMutableState.java @@ -17,40 +17,12 @@ package com.uber.cadence.internal.testservice; -import com.uber.cadence.BadRequestError; -import com.uber.cadence.ChildWorkflowExecutionCanceledEventAttributes; -import com.uber.cadence.ChildWorkflowExecutionCompletedEventAttributes; -import com.uber.cadence.ChildWorkflowExecutionFailedEventAttributes; -import com.uber.cadence.ChildWorkflowExecutionStartedEventAttributes; -import com.uber.cadence.ChildWorkflowExecutionTimedOutEventAttributes; -import com.uber.cadence.EntityNotExistsError; -import com.uber.cadence.InternalServiceError; -import com.uber.cadence.PollForActivityTaskRequest; -import com.uber.cadence.PollForActivityTaskResponse; -import com.uber.cadence.PollForDecisionTaskRequest; -import com.uber.cadence.PollForDecisionTaskResponse; -import com.uber.cadence.QueryWorkflowRequest; -import com.uber.cadence.QueryWorkflowResponse; -import com.uber.cadence.RecordActivityTaskHeartbeatResponse; -import com.uber.cadence.RequestCancelWorkflowExecutionRequest; -import com.uber.cadence.RespondActivityTaskCanceledByIDRequest; -import com.uber.cadence.RespondActivityTaskCanceledRequest; -import com.uber.cadence.RespondActivityTaskCompletedByIDRequest; -import com.uber.cadence.RespondActivityTaskCompletedRequest; -import com.uber.cadence.RespondActivityTaskFailedByIDRequest; -import com.uber.cadence.RespondActivityTaskFailedRequest; -import com.uber.cadence.RespondDecisionTaskCompletedRequest; -import com.uber.cadence.RespondDecisionTaskFailedRequest; -import com.uber.cadence.RespondQueryTaskCompletedRequest; -import com.uber.cadence.SignalExternalWorkflowExecutionDecisionAttributes; -import com.uber.cadence.SignalExternalWorkflowExecutionFailedCause; -import com.uber.cadence.SignalWorkflowExecutionRequest; -import com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes; -import com.uber.cadence.StartWorkflowExecutionRequest; -import com.uber.cadence.StickyExecutionAttributes; -import com.uber.cadence.WorkflowExecutionAlreadyCompletedError; -import com.uber.cadence.WorkflowExecutionCloseStatus; +import com.uber.cadence.api.v1.*; import com.uber.cadence.internal.testservice.TestWorkflowMutableStateImpl.QueryId; +import com.uber.cadence.serviceclient.exceptions.BadRequestException; +import com.uber.cadence.serviceclient.exceptions.EntityNotExistsException; +import com.uber.cadence.serviceclient.exceptions.InternalServiceException; +import com.uber.cadence.serviceclient.exceptions.WorkflowExecutionAlreadyCompletedException; import java.util.Optional; import org.apache.thrift.TException; @@ -64,102 +36,102 @@ interface TestWorkflowMutableState { StartWorkflowExecutionRequest getStartRequest(); void startDecisionTask(PollForDecisionTaskResponse task, PollForDecisionTaskRequest pollRequest) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void completeDecisionTask(int historySize, RespondDecisionTaskCompletedRequest request) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void completeSignalExternalWorkflowExecution(String signalId, String runId) - throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws EntityNotExistsException, InternalServiceException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void failSignalExternalWorkflowExecution( String signalId, SignalExternalWorkflowExecutionFailedCause cause) - throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws EntityNotExistsException, InternalServiceException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void failDecisionTask(RespondDecisionTaskFailedRequest request) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void childWorkflowStarted(ChildWorkflowExecutionStartedEventAttributes a) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void childWorkflowFailed(String workflowId, ChildWorkflowExecutionFailedEventAttributes a) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void childWorkflowTimedOut(String activityId, ChildWorkflowExecutionTimedOutEventAttributes a) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void failStartChildWorkflow(String workflowId, StartChildWorkflowExecutionFailedEventAttributes a) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void childWorkflowCompleted(String workflowId, ChildWorkflowExecutionCompletedEventAttributes a) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void childWorkflowCanceled(String workflowId, ChildWorkflowExecutionCanceledEventAttributes a) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void startWorkflow( boolean continuedAsNew, Optional signalWithStartSignal) - throws InternalServiceError, BadRequestError; + throws InternalServiceException, BadRequestException; void startActivityTask(PollForActivityTaskResponse task, PollForActivityTaskRequest pollRequest) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void completeActivityTask(String activityId, RespondActivityTaskCompletedRequest request) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void completeActivityTaskById(String activityId, RespondActivityTaskCompletedByIDRequest request) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void failActivityTask(String activityId, RespondActivityTaskFailedRequest request) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void failActivityTaskById(String id, RespondActivityTaskFailedByIDRequest failRequest) - throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws EntityNotExistsException, InternalServiceException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; RecordActivityTaskHeartbeatResponse heartbeatActivityTask(String activityId, byte[] details) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void signal(SignalWorkflowExecutionRequest signalRequest) - throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws EntityNotExistsException, InternalServiceException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void signalFromWorkflow(SignalExternalWorkflowExecutionDecisionAttributes a) - throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws EntityNotExistsException, InternalServiceException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void requestCancelWorkflowExecution(RequestCancelWorkflowExecutionRequest cancelRequest) - throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws EntityNotExistsException, InternalServiceException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void cancelActivityTask(String id, RespondActivityTaskCanceledRequest canceledRequest) - throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws EntityNotExistsException, InternalServiceException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; void cancelActivityTaskById(String id, RespondActivityTaskCanceledByIDRequest canceledRequest) - throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError, - BadRequestError; + throws EntityNotExistsException, InternalServiceException, + WorkflowExecutionAlreadyCompletedException, BadRequestException; QueryWorkflowResponse query(QueryWorkflowRequest queryRequest) throws TException; void completeQuery(QueryId queryId, RespondQueryTaskCompletedRequest completeRequest) - throws EntityNotExistsError; + throws EntityNotExistsException; StickyExecutionAttributes getStickyExecutionAttributes(); diff --git a/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateAttrUtil.java b/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateAttrUtil.java index bffb9ba70..f863a101a 100644 --- a/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateAttrUtil.java +++ b/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateAttrUtil.java @@ -19,54 +19,56 @@ package com.uber.cadence.internal.testservice; -import com.uber.cadence.*; +import com.uber.cadence.api.v1.*; +import com.uber.cadence.serviceclient.exceptions.BadRequestException; public class TestWorkflowMutableStateAttrUtil { static void validateScheduleActivityTask(ScheduleActivityTaskDecisionAttributes a) - throws BadRequestError { + throws BadRequestException { if (a == null) { - throw new BadRequestError("ScheduleActivityTaskDecisionAttributes is not set on decision."); + throw new BadRequestException( + "ScheduleActivityTaskDecisionAttributes is not set on decision."); } - if (a.getTaskList() == null || a.getTaskList().getName().isEmpty()) { - throw new BadRequestError("TaskList is not set on decision."); + if (!a.hasTaskList() || a.getTaskList().getName().isEmpty()) { + throw new BadRequestException("TaskList is not set on decision."); } - if (a.getActivityId() == null || a.getActivityId().isEmpty()) { - throw new BadRequestError("ActivityId is not set on decision."); + if (a.getActivityId().isEmpty() || a.getActivityId().isEmpty()) { + throw new BadRequestException("ActivityId is not set on decision."); } - if (a.getActivityType() == null - || a.getActivityType().getName() == null - || a.getActivityType().getName().isEmpty()) { - throw new BadRequestError("ActivityType is not set on decision."); + if (!a.hasActivityType() || a.getActivityType().getName().isEmpty()) { + throw new BadRequestException("ActivityType is not set on decision."); } - if (a.getStartToCloseTimeoutSeconds() <= 0) { - throw new BadRequestError("A valid StartToCloseTimeoutSeconds is not set on decision."); + if (a.getStartToCloseTimeout().getSeconds() <= 0) { + throw new BadRequestException("A valid StartToCloseTimeoutSeconds is not set on decision."); } - if (a.getScheduleToStartTimeoutSeconds() <= 0) { - throw new BadRequestError("A valid ScheduleToStartTimeoutSeconds is not set on decision."); + if (a.getScheduleToStartTimeout().getSeconds() <= 0) { + throw new BadRequestException( + "A valid ScheduleToStartTimeoutSeconds is not set on decision."); } - if (a.getScheduleToCloseTimeoutSeconds() <= 0) { - throw new BadRequestError("A valid ScheduleToCloseTimeoutSeconds is not set on decision."); + if (a.getScheduleToCloseTimeout().getSeconds() <= 0) { + throw new BadRequestException( + "A valid ScheduleToCloseTimeoutSeconds is not set on decision."); } - if (a.getHeartbeatTimeoutSeconds() < 0) { - throw new BadRequestError("Ac valid HeartbeatTimeoutSeconds is not set on decision."); + if (a.getHeartbeatTimeout().getSeconds() < 0) { + throw new BadRequestException("Ac valid HeartbeatTimeoutSeconds is not set on decision."); } } static void validateStartChildExecutionAttributes(StartChildWorkflowExecutionDecisionAttributes a) - throws BadRequestError { + throws BadRequestException { if (a == null) { - throw new BadRequestError( + throw new BadRequestException( "StartChildWorkflowExecutionDecisionAttributes is not set on decision."); } if (a.getWorkflowId().isEmpty()) { - throw new BadRequestError("Required field WorkflowID is not set on decision."); + throw new BadRequestException("Required field WorkflowID is not set on decision."); } if (a.getWorkflowType() == null || a.getWorkflowType().getName().isEmpty()) { - throw new BadRequestError("Required field WorkflowType is not set on decision."); + throw new BadRequestException("Required field WorkflowType is not set on decision."); } RetryPolicy retryPolicy = a.getRetryPolicy(); @@ -75,22 +77,25 @@ static void validateStartChildExecutionAttributes(StartChildWorkflowExecutionDec } } - public static void inheritUnsetPropertiesFromParentWorkflow( - StartWorkflowExecutionRequest startRequest, StartChildWorkflowExecutionDecisionAttributes a) { + public static StartChildWorkflowExecutionDecisionAttributes + inheritUnsetPropertiesFromParentWorkflow( + StartWorkflowExecutionRequest startRequest, + StartChildWorkflowExecutionDecisionAttributes a) { + StartChildWorkflowExecutionDecisionAttributes.Builder res = a.toBuilder(); // Inherit tasklist from parent workflow execution if not provided on decision - if (a.getTaskList() == null || a.getTaskList().getName().isEmpty()) { - a.setTaskList(startRequest.getTaskList()); + if (!a.hasTaskList() || a.getTaskList().getName().isEmpty()) { + res.setTaskList(startRequest.getTaskList()); } // Inherit workflow timeout from parent workflow execution if not provided on decision - if (a.getExecutionStartToCloseTimeoutSeconds() <= 0) { - a.setExecutionStartToCloseTimeoutSeconds( - startRequest.getExecutionStartToCloseTimeoutSeconds()); + if (!a.hasExecutionStartToCloseTimeout()) { + res.setExecutionStartToCloseTimeout(startRequest.getExecutionStartToCloseTimeout()); } // Inherit decision task timeout from parent workflow execution if not provided on decision - if (a.getTaskStartToCloseTimeoutSeconds() <= 0) { - a.setTaskStartToCloseTimeoutSeconds(startRequest.getTaskStartToCloseTimeoutSeconds()); + if (!a.hasTaskStartToCloseTimeout()) { + res.setTaskStartToCloseTimeout(startRequest.getTaskStartToCloseTimeout()); } + return res.build(); } } diff --git a/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateImpl.java b/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateImpl.java index 79ac3dd26..cc0bbe373 100644 --- a/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateImpl.java +++ b/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateImpl.java @@ -27,72 +27,7 @@ import com.cronutils.parser.CronParser; import com.google.common.base.Strings; import com.google.common.base.Throwables; -import com.uber.cadence.ActivityTaskScheduledEventAttributes; -import com.uber.cadence.BadRequestError; -import com.uber.cadence.CancelTimerDecisionAttributes; -import com.uber.cadence.CancelTimerFailedEventAttributes; -import com.uber.cadence.CancelWorkflowExecutionDecisionAttributes; -import com.uber.cadence.ChildWorkflowExecutionCanceledEventAttributes; -import com.uber.cadence.ChildWorkflowExecutionCompletedEventAttributes; -import com.uber.cadence.ChildWorkflowExecutionFailedEventAttributes; -import com.uber.cadence.ChildWorkflowExecutionStartedEventAttributes; -import com.uber.cadence.ChildWorkflowExecutionTimedOutEventAttributes; -import com.uber.cadence.CompleteWorkflowExecutionDecisionAttributes; -import com.uber.cadence.ContinueAsNewWorkflowExecutionDecisionAttributes; -import com.uber.cadence.Decision; -import com.uber.cadence.DecisionTaskFailedCause; -import com.uber.cadence.EntityNotExistsError; -import com.uber.cadence.EventType; -import com.uber.cadence.FailWorkflowExecutionDecisionAttributes; -import com.uber.cadence.HistoryEvent; -import com.uber.cadence.InternalServiceError; -import com.uber.cadence.MarkerRecordedEventAttributes; -import com.uber.cadence.PollForActivityTaskRequest; -import com.uber.cadence.PollForActivityTaskResponse; -import com.uber.cadence.PollForDecisionTaskRequest; -import com.uber.cadence.PollForDecisionTaskResponse; -import com.uber.cadence.QueryConsistencyLevel; -import com.uber.cadence.QueryFailedError; -import com.uber.cadence.QueryRejectCondition; -import com.uber.cadence.QueryRejected; -import com.uber.cadence.QueryResultType; -import com.uber.cadence.QueryTaskCompletedType; -import com.uber.cadence.QueryWorkflowRequest; -import com.uber.cadence.QueryWorkflowResponse; -import com.uber.cadence.RecordActivityTaskHeartbeatResponse; -import com.uber.cadence.RecordMarkerDecisionAttributes; -import com.uber.cadence.RequestCancelActivityTaskDecisionAttributes; -import com.uber.cadence.RequestCancelActivityTaskFailedEventAttributes; -import com.uber.cadence.RequestCancelExternalWorkflowExecutionDecisionAttributes; -import com.uber.cadence.RequestCancelWorkflowExecutionRequest; -import com.uber.cadence.RespondActivityTaskCanceledByIDRequest; -import com.uber.cadence.RespondActivityTaskCanceledRequest; -import com.uber.cadence.RespondActivityTaskCompletedByIDRequest; -import com.uber.cadence.RespondActivityTaskCompletedRequest; -import com.uber.cadence.RespondActivityTaskFailedByIDRequest; -import com.uber.cadence.RespondActivityTaskFailedRequest; -import com.uber.cadence.RespondDecisionTaskCompletedRequest; -import com.uber.cadence.RespondDecisionTaskFailedRequest; -import com.uber.cadence.RespondQueryTaskCompletedRequest; -import com.uber.cadence.ScheduleActivityTaskDecisionAttributes; -import com.uber.cadence.SignalExternalWorkflowExecutionDecisionAttributes; -import com.uber.cadence.SignalExternalWorkflowExecutionFailedCause; -import com.uber.cadence.SignalWorkflowExecutionRequest; -import com.uber.cadence.StartChildWorkflowExecutionDecisionAttributes; -import com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes; -import com.uber.cadence.StartTimerDecisionAttributes; -import com.uber.cadence.StartWorkflowExecutionRequest; -import com.uber.cadence.StickyExecutionAttributes; -import com.uber.cadence.TimeoutType; -import com.uber.cadence.UpsertWorkflowSearchAttributesDecisionAttributes; -import com.uber.cadence.UpsertWorkflowSearchAttributesEventAttributes; -import com.uber.cadence.WorkflowExecution; -import com.uber.cadence.WorkflowExecutionAlreadyCompletedError; -import com.uber.cadence.WorkflowExecutionCloseStatus; -import com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes; -import com.uber.cadence.WorkflowExecutionSignaledEventAttributes; -import com.uber.cadence.WorkflowQuery; -import com.uber.cadence.WorkflowQueryResult; +import com.uber.cadence.api.v1.*; import com.uber.cadence.internal.common.WorkflowExecutionUtils; import com.uber.cadence.internal.testservice.StateMachines.Action; import com.uber.cadence.internal.testservice.StateMachines.ActivityTaskData; @@ -103,6 +38,10 @@ import com.uber.cadence.internal.testservice.StateMachines.TimerData; import com.uber.cadence.internal.testservice.StateMachines.WorkflowData; import com.uber.cadence.internal.testservice.TestWorkflowStore.TaskListId; +import com.uber.cadence.serviceclient.exceptions.BadRequestException; +import com.uber.cadence.serviceclient.exceptions.EntityNotExistsException; +import com.uber.cadence.serviceclient.exceptions.InternalServiceException; +import com.uber.cadence.serviceclient.exceptions.WorkflowExecutionAlreadyCompletedException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; @@ -138,7 +77,7 @@ class TestWorkflowMutableStateImpl implements TestWorkflowMutableState { private interface UpdateProcedure { void apply(RequestContext ctx) - throws InternalServiceError, BadRequestError, EntityNotExistsError; + throws InternalServiceException, BadRequestException, EntityNotExistsException; } private static final Logger log = LoggerFactory.getLogger(TestWorkflowMutableStateImpl.class); @@ -207,23 +146,23 @@ void apply(RequestContext ctx) } private void update(UpdateProcedure updater) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); update(false, updater, stackTraceElements[2].getMethodName()); } private void completeDecisionUpdate(UpdateProcedure updater, StickyExecutionAttributes attributes) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); stickyExecutionAttributes = attributes; update(true, updater, stackTraceElements[2].getMethodName()); } private void update(boolean completeDecisionUpdate, UpdateProcedure updater, String caller) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { String callerInfo = "Decision Update from " + caller; lock.lock(); LockHandle lockHandle = selfAdvancingTimer.lockTimeSkipping(callerInfo); @@ -244,13 +183,13 @@ private void update(boolean completeDecisionUpdate, UpdateProcedure updater, Str } else { nextEventId = ctx.commitChanges(store); } - } catch (InternalServiceError - | EntityNotExistsError - | WorkflowExecutionAlreadyCompletedError - | BadRequestError e) { + } catch (InternalServiceException + | EntityNotExistsException + | WorkflowExecutionAlreadyCompletedException + | BadRequestException e) { throw e; } catch (Exception e) { - throw new InternalServiceError(Throwables.getStackTraceAsString(e)); + throw new InternalServiceException(Throwables.getStackTraceAsString(e)); } finally { lockHandle.unlock(); lock.unlock(); @@ -278,15 +217,15 @@ public Optional getCloseStatus() { case CANCELLATION_REQUESTED: return Optional.empty(); case FAILED: - return Optional.of(WorkflowExecutionCloseStatus.FAILED); + return Optional.of(WorkflowExecutionCloseStatus.WORKFLOW_EXECUTION_CLOSE_STATUS_FAILED); case TIMED_OUT: - return Optional.of(WorkflowExecutionCloseStatus.TIMED_OUT); + return Optional.of(WorkflowExecutionCloseStatus.WORKFLOW_EXECUTION_CLOSE_STATUS_TIMED_OUT); case CANCELED: - return Optional.of(WorkflowExecutionCloseStatus.CANCELED); + return Optional.of(WorkflowExecutionCloseStatus.WORKFLOW_EXECUTION_CLOSE_STATUS_CANCELED); case COMPLETED: - return Optional.of(WorkflowExecutionCloseStatus.COMPLETED); + return Optional.of(WorkflowExecutionCloseStatus.WORKFLOW_EXECUTION_CLOSE_STATUS_COMPLETED); case CONTINUED_AS_NEW: - return Optional.of(WorkflowExecutionCloseStatus.CONTINUED_AS_NEW); + return Optional.of(WorkflowExecutionCloseStatus.WORKFLOW_EXECUTION_CLOSE_STATUS_CONTINUED_AS_NEW); } throw new IllegalStateException("unreachable"); } @@ -309,8 +248,8 @@ public Optional getParent() { @Override public void startDecisionTask( PollForDecisionTaskResponse task, PollForDecisionTaskRequest pollRequest) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { if (task.getQuery() == null) { update( ctx -> { @@ -326,8 +265,8 @@ public void startDecisionTask( @Override public void completeDecisionTask(int historySize, RespondDecisionTaskCompletedRequest request) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { List decisions = request.getDecisions(); completeDecisionUpdate( ctx -> { @@ -342,7 +281,7 @@ public void completeDecisionTask(int historySize, RespondDecisionTaskCompletedRe } if (ctx.getInitialEventId() != historySize + 1) { - throw new BadRequestError( + throw new BadRequestException( "Expired decision: expectedHistorySize=" + historySize + "," @@ -369,7 +308,7 @@ public void completeDecisionTask(int historySize, RespondDecisionTaskCompletedRe return; } if (decision == null) { - throw new EntityNotExistsError("No outstanding decision"); + throw new EntityNotExistsException("No outstanding decision"); } decision.action(StateMachines.Action.COMPLETE, ctx, request, 0); for (Decision d : decisions) { @@ -419,7 +358,7 @@ private boolean hasCompleteDecision(List decisions) { private void processDecision( RequestContext ctx, Decision d, String identity, long decisionTaskCompletedId) - throws BadRequestError, InternalServiceError { + throws BadRequestException, InternalServiceException { switch (d.getDecisionType()) { case CompleteWorkflowExecution: processCompleteWorkflowExecution( @@ -500,9 +439,9 @@ private void processRequestCancelExternalWorkflowExecution( private void processRecordMarker( RequestContext ctx, RecordMarkerDecisionAttributes attr, long decisionTaskCompletedId) - throws BadRequestError { + throws BadRequestException { if (!attr.isSetMarkerName()) { - throw new BadRequestError("marker name is required"); + throw new BadRequestException("marker name is required"); } MarkerRecordedEventAttributes marker = @@ -520,7 +459,7 @@ private void processRecordMarker( private void processCancelTimer( RequestContext ctx, CancelTimerDecisionAttributes d, long decisionTaskCompletedId) - throws InternalServiceError, BadRequestError { + throws InternalServiceException, BadRequestException { String timerId = d.getTimerId(); StateMachine timer = timers.get(timerId); if (timer == null) { @@ -544,7 +483,7 @@ private void processRequestCancelActivityTask( RequestContext ctx, RequestCancelActivityTaskDecisionAttributes a, long decisionTaskCompletedId) - throws InternalServiceError, BadRequestError { + throws InternalServiceException, BadRequestException { String activityId = a.getActivityId(); StateMachine activity = activities.get(activityId); if (activity == null) { @@ -571,12 +510,12 @@ private void processRequestCancelActivityTask( private void processScheduleActivityTask( RequestContext ctx, ScheduleActivityTaskDecisionAttributes a, long decisionTaskCompletedId) - throws BadRequestError, InternalServiceError { + throws BadRequestException, InternalServiceException { validateScheduleActivityTask(a); String activityId = a.getActivityId(); StateMachine activity = activities.get(activityId); if (activity != null) { - throw new BadRequestError("Already open activity with " + activityId); + throw new BadRequestException("Already open activity with " + activityId); } activity = StateMachines.newActivityStateMachine(store, this.startRequest); activities.put(activityId, activity); @@ -597,7 +536,7 @@ private void processStartChildWorkflow( RequestContext ctx, StartChildWorkflowExecutionDecisionAttributes a, long decisionTaskCompletedId) - throws BadRequestError, InternalServiceError { + throws BadRequestException, InternalServiceException { validateStartChildExecutionAttributes(a); inheritUnsetPropertiesFromParentWorkflow(startRequest, a); StateMachine child = StateMachines.newChildWorkflowStateMachine(service); @@ -610,7 +549,7 @@ private void processSignalExternalWorkflowExecution( RequestContext ctx, SignalExternalWorkflowExecutionDecisionAttributes a, long decisionTaskCompletedId) - throws InternalServiceError, BadRequestError { + throws InternalServiceException, BadRequestException { String signalId = UUID.randomUUID().toString(); StateMachine signalStateMachine = StateMachines.newSignalExternalStateMachine(); @@ -630,8 +569,8 @@ private void processSignalExternalWorkflowExecution( @Override public void completeSignalExternalWorkflowExecution(String signalId, String runId) - throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws EntityNotExistsException, InternalServiceException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { update( ctx -> { StateMachine signal = getSignal(signalId); @@ -644,8 +583,8 @@ public void completeSignalExternalWorkflowExecution(String signalId, String runI @Override public void failSignalExternalWorkflowExecution( String signalId, SignalExternalWorkflowExecutionFailedCause cause) - throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws EntityNotExistsException, InternalServiceException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { update( ctx -> { StateMachine signal = getSignal(signalId); @@ -655,10 +594,11 @@ public void failSignalExternalWorkflowExecution( }); } - private StateMachine getSignal(String signalId) throws EntityNotExistsError { + private StateMachine getSignal(String signalId) + throws EntityNotExistsException { StateMachine signal = externalSignals.get(signalId); if (signal == null) { - throw new EntityNotExistsError("unknown signalId: " + signalId); + throw new EntityNotExistsException("unknown signalId: " + signalId); } return signal; } @@ -666,8 +606,8 @@ private StateMachine getSignal(String signalId) throws Entit // TODO: insert a single decision failure into the history @Override public void failDecisionTask(RespondDecisionTaskFailedRequest request) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { completeDecisionUpdate( ctx -> { decision.action(Action.FAIL, ctx, request, 0); @@ -691,7 +631,7 @@ private void timeoutDecisionTask(long scheduledEventId) { scheduleDecision(ctx); }, null); // reset sticky attributes to null - } catch (EntityNotExistsError e) { + } catch (EntityNotExistsException e) { // Expected as timers are not removed } catch (Exception e) { // Cannot fail to timer threads @@ -701,8 +641,8 @@ private void timeoutDecisionTask(long scheduledEventId) { @Override public void childWorkflowStarted(ChildWorkflowExecutionStartedEventAttributes a) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { update( ctx -> { StateMachine child = getChildWorkflow(a.getInitiatedEventId()); @@ -716,8 +656,8 @@ public void childWorkflowStarted(ChildWorkflowExecutionStartedEventAttributes a) @Override public void childWorkflowFailed(String activityId, ChildWorkflowExecutionFailedEventAttributes a) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { update( ctx -> { StateMachine child = getChildWorkflow(a.getInitiatedEventId()); @@ -731,8 +671,8 @@ public void childWorkflowFailed(String activityId, ChildWorkflowExecutionFailedE @Override public void childWorkflowTimedOut( String activityId, ChildWorkflowExecutionTimedOutEventAttributes a) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { update( ctx -> { StateMachine child = getChildWorkflow(a.getInitiatedEventId()); @@ -746,8 +686,8 @@ public void childWorkflowTimedOut( @Override public void failStartChildWorkflow( String childId, StartChildWorkflowExecutionFailedEventAttributes a) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { update( ctx -> { StateMachine child = getChildWorkflow(a.getInitiatedEventId()); @@ -761,8 +701,8 @@ public void failStartChildWorkflow( @Override public void childWorkflowCompleted( String activityId, ChildWorkflowExecutionCompletedEventAttributes a) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { update( ctx -> { StateMachine child = getChildWorkflow(a.getInitiatedEventId()); @@ -776,8 +716,8 @@ public void childWorkflowCompleted( @Override public void childWorkflowCanceled( String activityId, ChildWorkflowExecutionCanceledEventAttributes a) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { update( ctx -> { StateMachine child = getChildWorkflow(a.getInitiatedEventId()); @@ -790,14 +730,14 @@ public void childWorkflowCanceled( private void processStartTimer( RequestContext ctx, StartTimerDecisionAttributes a, long decisionTaskCompletedId) - throws BadRequestError, InternalServiceError { + throws BadRequestException, InternalServiceException { String timerId = a.getTimerId(); if (timerId == null) { - throw new BadRequestError("A valid TimerId is not set on StartTimerDecision"); + throw new BadRequestException("A valid TimerId is not set on StartTimerDecision"); } StateMachine timer = timers.get(timerId); if (timer != null) { - throw new BadRequestError("Already open timer with " + timerId); + throw new BadRequestException("Already open timer with " + timerId); } timer = StateMachines.newTimerStateMachine(); timers.put(timerId, timer); @@ -825,10 +765,10 @@ private void fireTimer(String timerId) { timers.remove(timerId); scheduleDecision(ctx); }); - } catch (BadRequestError - | InternalServiceError - | EntityNotExistsError - | WorkflowExecutionAlreadyCompletedError e) { + } catch (BadRequestException + | InternalServiceException + | EntityNotExistsException + | WorkflowExecutionAlreadyCompletedException e) { // Cannot fail to timer threads log.error("Failure firing a timer", e); } @@ -839,7 +779,7 @@ private void processFailWorkflowExecution( FailWorkflowExecutionDecisionAttributes d, long decisionTaskCompletedId, String identity) - throws InternalServiceError, BadRequestError { + throws InternalServiceException, BadRequestException { WorkflowData data = workflow.getData(); if (data.retryState.isPresent()) { RetryState rs = data.retryState.get(); @@ -899,9 +839,9 @@ private void processFailWorkflowExecution( parent .get() .childWorkflowFailed(ctx.getExecutionId().getWorkflowId().getWorkflowId(), a); - } catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) { + } catch (EntityNotExistsException | WorkflowExecutionAlreadyCompletedException e) { // Parent might already close - } catch (BadRequestError | InternalServiceError e) { + } catch (BadRequestException | InternalServiceException e) { log.error("Failure reporting child completion", e); } }); @@ -913,7 +853,7 @@ private void processCompleteWorkflowExecution( CompleteWorkflowExecutionDecisionAttributes d, long decisionTaskCompletedId, String identity) - throws InternalServiceError, BadRequestError { + throws InternalServiceException, BadRequestException { WorkflowData data = workflow.getData(); if (!Strings.isNullOrEmpty(data.cronSchedule)) { startNewCronRun(ctx, decisionTaskCompletedId, identity, data, d.getResult()); @@ -938,9 +878,9 @@ private void processCompleteWorkflowExecution( .get() .childWorkflowCompleted( ctx.getExecutionId().getWorkflowId().getWorkflowId(), a); - } catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) { + } catch (EntityNotExistsException | WorkflowExecutionAlreadyCompletedException e) { // Parent might already close - } catch (BadRequestError | InternalServiceError e) { + } catch (BadRequestException | InternalServiceException e) { log.error("Failure reporting child completion", e); } }); @@ -953,7 +893,7 @@ private void startNewCronRun( String identity, WorkflowData data, byte[] lastCompletionResult) - throws InternalServiceError, BadRequestError { + throws InternalServiceException, BadRequestException { CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX); CronParser parser = new CronParser(cronDefinition); Cron cron = parser.parse(data.cronSchedule); @@ -1000,7 +940,7 @@ private void startNewCronRun( private void processCancelWorkflowExecution( RequestContext ctx, CancelWorkflowExecutionDecisionAttributes d, long decisionTaskCompletedId) - throws InternalServiceError, BadRequestError { + throws InternalServiceException, BadRequestException { workflow.action(StateMachines.Action.CANCEL, ctx, d, decisionTaskCompletedId); if (parent.isPresent()) { ctx.lockTimer(); // unlocked by the parent @@ -1019,9 +959,9 @@ private void processCancelWorkflowExecution( .get() .childWorkflowCanceled( ctx.getExecutionId().getWorkflowId().getWorkflowId(), a); - } catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) { + } catch (EntityNotExistsException | WorkflowExecutionAlreadyCompletedException e) { // Parent might already close - } catch (BadRequestError | InternalServiceError e) { + } catch (BadRequestException | InternalServiceException e) { log.error("Failure reporting child completion", e); } }); @@ -1033,7 +973,7 @@ private void processContinueAsNewWorkflowExecution( ContinueAsNewWorkflowExecutionDecisionAttributes d, long decisionTaskCompletedId, String identity) - throws InternalServiceError, BadRequestError { + throws InternalServiceException, BadRequestException { workflow.action(Action.CONTINUE_AS_NEW, ctx, d, decisionTaskCompletedId); HistoryEvent event = ctx.getEvents().get(ctx.getEvents().size() - 1); String runId = @@ -1052,7 +992,7 @@ private void processUpsertWorkflowSearchAttributes( RequestContext ctx, UpsertWorkflowSearchAttributesDecisionAttributes attr, long decisionTaskCompletedId) - throws BadRequestError, InternalServiceError { + throws BadRequestException, InternalServiceException { UpsertWorkflowSearchAttributesEventAttributes upsertEventAttr = new UpsertWorkflowSearchAttributesEventAttributes() .setSearchAttributes(attr.getSearchAttributes()) @@ -1067,7 +1007,7 @@ private void processUpsertWorkflowSearchAttributes( @Override public void startWorkflow( boolean continuedAsNew, Optional signalWithStartSignal) - throws InternalServiceError, BadRequestError { + throws InternalServiceException, BadRequestException { try { update( ctx -> { @@ -1082,7 +1022,7 @@ public void startWorkflow( () -> { try { update(ctx1 -> scheduleDecision(ctx1)); - } catch (EntityNotExistsError e) { + } catch (EntityNotExistsException e) { // Expected as timers are not removed } catch (Exception e) { // Cannot fail to timer threads @@ -1102,8 +1042,8 @@ public void startWorkflow( ctx.addTimer( executionTimeoutTimerDelay, this::timeoutWorkflow, "workflow execution timeout"); }); - } catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) { - throw new InternalServiceError(Throwables.getStackTraceAsString(e)); + } catch (EntityNotExistsException | WorkflowExecutionAlreadyCompletedException e) { + throw new InternalServiceException(Throwables.getStackTraceAsString(e)); } if (!continuedAsNew && parent.isPresent()) { ChildWorkflowExecutionStartedEventAttributes a = @@ -1114,15 +1054,16 @@ public void startWorkflow( .setWorkflowType(startRequest.getWorkflowType()); try { parent.get().childWorkflowStarted(a); - } catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) { + } catch (EntityNotExistsException | WorkflowExecutionAlreadyCompletedException e) { // Not a problem. Parent might just close by now. - } catch (BadRequestError | InternalServiceError e) { + } catch (BadRequestException | InternalServiceException e) { log.error("Failure reporting child completion", e); } } } - private void scheduleDecision(RequestContext ctx) throws InternalServiceError, BadRequestError { + private void scheduleDecision(RequestContext ctx) + throws InternalServiceException, BadRequestException { if (decision != null) { if (decision.getState() == StateMachines.State.INITIATED) { return; // No need to schedule again @@ -1138,7 +1079,7 @@ private void scheduleDecision(RequestContext ctx) throws InternalServiceError, B ctx.lockTimer(); return; } - throw new InternalServiceError("unexpected decision state: " + decision.getState()); + throw new InternalServiceException("unexpected decision state: " + decision.getState()); } this.decision = StateMachines.newDecisionStateMachine(lastNonFailedDecisionStartEventId, store); decision.action(StateMachines.Action.INITIATE, ctx, startRequest, 0); @@ -1148,8 +1089,8 @@ private void scheduleDecision(RequestContext ctx) throws InternalServiceError, B @Override public void startActivityTask( PollForActivityTaskResponse task, PollForActivityTaskRequest pollRequest) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { update( ctx -> { String activityId = task.getActivityId(); @@ -1169,10 +1110,10 @@ public void startActivityTask( } private void checkCompleted() - throws EntityNotExistsError, WorkflowExecutionAlreadyCompletedError { + throws EntityNotExistsException, WorkflowExecutionAlreadyCompletedException { State workflowState = workflow.getState(); if (isTerminalState(workflowState)) { - throw new WorkflowExecutionAlreadyCompletedError( + throw new WorkflowExecutionAlreadyCompletedException( "Workflow is already completed: " + workflowState); } } @@ -1189,21 +1130,21 @@ private void updateHeartbeatTimer( RequestContext ctx, String activityId, StateMachine activity, - int startToCloseTimeout, - int heartbeatTimeout) { + com.google.protobuf.Duration startToCloseTimeout, + com.google.protobuf.Duration heartbeatTimeout) { if (heartbeatTimeout > 0 && heartbeatTimeout < startToCloseTimeout) { activity.getData().lastHeartbeatTime = clock.getAsLong(); ctx.addTimer( heartbeatTimeout, - () -> timeoutActivity(activityId, TimeoutType.HEARTBEAT), + () -> timeoutActivity(activityId, TimeoutType.TIMEOUT_TYPE_HEARTBEAT), "Activity Heartbeat Timeout"); } } @Override public void completeActivityTask(String activityId, RespondActivityTaskCompletedRequest request) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { update( ctx -> { StateMachine activity = getActivity(activityId); @@ -1217,8 +1158,8 @@ public void completeActivityTask(String activityId, RespondActivityTaskCompleted @Override public void completeActivityTaskById( String activityId, RespondActivityTaskCompletedByIDRequest request) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { update( ctx -> { StateMachine activity = getActivity(activityId); @@ -1231,8 +1172,8 @@ public void completeActivityTaskById( @Override public void failActivityTask(String activityId, RespondActivityTaskFailedRequest request) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { update( ctx -> { StateMachine activity = getActivity(activityId); @@ -1263,7 +1204,7 @@ private void addActivityRetryTimer(RequestContext ctx, StateMachine ctx1.addActivityTask(data.activityTask)); - } catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) { + } catch (EntityNotExistsException | WorkflowExecutionAlreadyCompletedException e) { unlockTimer = true; // Expected as timers are not removed } catch (Exception e) { @@ -1283,8 +1224,8 @@ private void addActivityRetryTimer(RequestContext ctx, StateMachine { StateMachine activity = getActivity(activityId); @@ -1301,8 +1242,8 @@ public void failActivityTaskById(String activityId, RespondActivityTaskFailedByI @Override public void cancelActivityTask(String activityId, RespondActivityTaskCanceledRequest request) - throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws EntityNotExistsException, InternalServiceException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { update( ctx -> { StateMachine activity = getActivity(activityId); @@ -1316,8 +1257,8 @@ public void cancelActivityTask(String activityId, RespondActivityTaskCanceledReq @Override public void cancelActivityTaskById( String activityId, RespondActivityTaskCanceledByIDRequest request) - throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws EntityNotExistsException, InternalServiceException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { update( ctx -> { StateMachine activity = getActivity(activityId); @@ -1331,8 +1272,9 @@ public void cancelActivityTaskById( @Override public RecordActivityTaskHeartbeatResponse heartbeatActivityTask( String activityId, byte[] details) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError { - RecordActivityTaskHeartbeatResponse result = new RecordActivityTaskHeartbeatResponse(); + throws InternalServiceException, EntityNotExistsException, + WorkflowExecutionAlreadyCompletedException { + RecordActivityTaskHeartbeatResponse.Builder result = RecordActivityTaskHeartbeatResponse.newBuilder(); try { update( ctx -> { @@ -1343,19 +1285,19 @@ public RecordActivityTaskHeartbeatResponse heartbeatActivityTask( } ActivityTaskData data = activity.getData(); data.lastHeartbeatTime = clock.getAsLong(); - int startToCloseTimeout = data.scheduledEvent.getStartToCloseTimeoutSeconds(); - int heartbeatTimeout = data.scheduledEvent.getHeartbeatTimeoutSeconds(); + Duration startToCloseTimeout = data.scheduledEvent.getStartToCloseTimeout(); + Duration heartbeatTimeout = data.scheduledEvent.getHeartbeatTimeout(); updateHeartbeatTimer(ctx, activityId, activity, startToCloseTimeout, heartbeatTimeout); }); - } catch (InternalServiceError - | EntityNotExistsError - | WorkflowExecutionAlreadyCompletedError e) { + } catch (InternalServiceException + | EntityNotExistsException + | WorkflowExecutionAlreadyCompletedException e) { throw e; } catch (Exception e) { - throw new InternalServiceError(Throwables.getStackTraceAsString(e)); + throw new InternalServiceException(Throwables.getStackTraceAsString(e)); } - return result; + return result.build(); } private void timeoutActivity(String activityId, TimeoutType timeoutType) { @@ -1364,17 +1306,17 @@ private void timeoutActivity(String activityId, TimeoutType timeoutType) { update( ctx -> { StateMachine activity = getActivity(activityId); - if (timeoutType == TimeoutType.SCHEDULE_TO_START + if (timeoutType == TimeoutType.TIMEOUT_TYPE_SCHEDULE_TO_START && activity.getState() != StateMachines.State.INITIATED) { - throw new EntityNotExistsError("Not in INITIATED"); + throw new EntityNotExistsException("Not in INITIATED"); } - if (timeoutType == TimeoutType.HEARTBEAT) { + if (timeoutType == TimeoutType.TIMEOUT_TYPE_HEARTBEAT) { // Deal with timers which are never cancelled long heartbeatTimeout = TimeUnit.SECONDS.toMillis( activity.getData().scheduledEvent.getHeartbeatTimeoutSeconds()); if (clock.getAsLong() - activity.getData().lastHeartbeatTime < heartbeatTimeout) { - throw new EntityNotExistsError("Not heartbeat timeout"); + throw new EntityNotExistsException("Not heartbeat timeout"); } } activity.action(StateMachines.Action.TIME_OUT, ctx, timeoutType, 0); @@ -1385,7 +1327,7 @@ private void timeoutActivity(String activityId, TimeoutType timeoutType) { addActivityRetryTimer(ctx, activity); } }); - } catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) { + } catch (EntityNotExistsException | WorkflowExecutionAlreadyCompletedException e) { // Expected as timers are not removed unlockTimer = false; } catch (Exception e) { @@ -1415,16 +1357,16 @@ private void timeoutWorkflow() { if (isTerminalState(workflow.getState())) { return; } - workflow.action(StateMachines.Action.TIME_OUT, ctx, TimeoutType.START_TO_CLOSE, 0); + workflow.action(StateMachines.Action.TIME_OUT, ctx, TimeoutType.TIMEOUT_TYPE_START_TO_CLOSE, 0); if (parent != null) { ctx.lockTimer(); // unlocked by the parent } ForkJoinPool.commonPool().execute(() -> reportWorkflowTimeoutToParent(ctx)); }); - } catch (BadRequestError - | InternalServiceError - | EntityNotExistsError - | WorkflowExecutionAlreadyCompletedError e) { + } catch (BadRequestException + | InternalServiceException + | EntityNotExistsException + | WorkflowExecutionAlreadyCompletedException e) { // Cannot fail to timer threads log.error("Failure trying to timeout a workflow", e); } @@ -1443,17 +1385,17 @@ private void reportWorkflowTimeoutToParent(RequestContext ctx) { .setDomain(ctx.getDomain()) .setWorkflowExecution(ctx.getExecution()); parent.get().childWorkflowTimedOut(ctx.getExecutionId().getWorkflowId().getWorkflowId(), a); - } catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) { + } catch (EntityNotExistsException | WorkflowExecutionAlreadyCompletedException e) { // Parent might already close - } catch (BadRequestError | InternalServiceError e) { + } catch (BadRequestException | InternalServiceException e) { log.error("Failure reporting child timing out", e); } } @Override public void signal(SignalWorkflowExecutionRequest signalRequest) - throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws EntityNotExistsException, InternalServiceException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { update( ctx -> { addExecutionSignaledEvent(ctx, signalRequest); @@ -1463,8 +1405,8 @@ public void signal(SignalWorkflowExecutionRequest signalRequest) @Override public void signalFromWorkflow(SignalExternalWorkflowExecutionDecisionAttributes a) - throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws EntityNotExistsException, InternalServiceException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { update( ctx -> { addExecutionSignaledByExternalEvent(ctx, a); @@ -1474,8 +1416,8 @@ public void signalFromWorkflow(SignalExternalWorkflowExecutionDecisionAttributes @Override public void requestCancelWorkflowExecution(RequestCancelWorkflowExecutionRequest cancelRequest) - throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { + throws EntityNotExistsException, InternalServiceException, + WorkflowExecutionAlreadyCompletedException, BadRequestException { update( ctx -> { workflow.action(StateMachines.Action.REQUEST_CANCELLATION, ctx, cancelRequest, 0); @@ -1533,16 +1475,16 @@ public QueryWorkflowResponse query(QueryWorkflowRequest queryRequest) throws TEx if (cause instanceof TException) { throw (TException) cause; } - throw new InternalServiceError(Throwables.getStackTraceAsString(cause)); + throw new InternalServiceException(Throwables.getStackTraceAsString(cause)); } } @Override public void completeQuery(QueryId queryId, RespondQueryTaskCompletedRequest completeRequest) - throws EntityNotExistsError { + throws EntityNotExistsException { CompletableFuture result = queries.get(queryId.getQueryId()); if (result == null) { - throw new EntityNotExistsError("Unknown query id: " + queryId.getQueryId()); + throw new EntityNotExistsException("Unknown query id: " + queryId.getQueryId()); } if (completeRequest.getCompletedType() == QueryTaskCompletedType.COMPLETED) { QueryWorkflowResponse response = @@ -1591,19 +1533,19 @@ private void addExecutionSignaledByExternalEvent( } private StateMachine getActivity(String activityId) - throws EntityNotExistsError { + throws EntityNotExistsException { StateMachine activity = activities.get(activityId); if (activity == null) { - throw new EntityNotExistsError("unknown activityId: " + activityId); + throw new EntityNotExistsException("unknown activityId: " + activityId); } return activity; } private StateMachine getChildWorkflow(long initiatedEventId) - throws InternalServiceError { + throws InternalServiceException { StateMachine child = childWorkflows.get(initiatedEventId); if (child == null) { - throw new InternalServiceError("unknown initiatedEventId: " + initiatedEventId); + throw new InternalServiceException("unknown initiatedEventId: " + initiatedEventId); } return child; } @@ -1631,23 +1573,23 @@ String getQueryId() { return queryId; } - byte[] toBytes() throws InternalServiceError { + byte[] toBytes() throws InternalServiceException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bout); addBytes(out); return bout.toByteArray(); } - void addBytes(DataOutputStream out) throws InternalServiceError { + void addBytes(DataOutputStream out) throws InternalServiceException { try { executionId.addBytes(out); out.writeUTF(queryId); } catch (IOException e) { - throw new InternalServiceError(Throwables.getStackTraceAsString(e)); + throw new InternalServiceException(Throwables.getStackTraceAsString(e)); } } - static QueryId fromBytes(byte[] serialized) throws InternalServiceError { + static QueryId fromBytes(byte[] serialized) throws InternalServiceException { ByteArrayInputStream bin = new ByteArrayInputStream(serialized); DataInputStream in = new DataInputStream(bin); try { @@ -1655,7 +1597,7 @@ static QueryId fromBytes(byte[] serialized) throws InternalServiceError { String queryId = in.readUTF(); return new QueryId(executionId, queryId); } catch (IOException e) { - throw new InternalServiceError(Throwables.getStackTraceAsString(e)); + throw new InternalServiceException(Throwables.getStackTraceAsString(e)); } } } diff --git a/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowService.java b/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowService.java index 8af30e9d6..4f2b87f17 100644 --- a/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowService.java +++ b/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowService.java @@ -17,108 +17,23 @@ package com.uber.cadence.internal.testservice; -import com.uber.cadence.BadRequestError; -import com.uber.cadence.ClientVersionNotSupportedError; -import com.uber.cadence.ClusterInfo; -import com.uber.cadence.CountWorkflowExecutionsRequest; -import com.uber.cadence.CountWorkflowExecutionsResponse; -import com.uber.cadence.DeprecateDomainRequest; -import com.uber.cadence.DescribeDomainRequest; -import com.uber.cadence.DescribeDomainResponse; -import com.uber.cadence.DescribeTaskListRequest; -import com.uber.cadence.DescribeTaskListResponse; -import com.uber.cadence.DescribeWorkflowExecutionRequest; -import com.uber.cadence.DescribeWorkflowExecutionResponse; -import com.uber.cadence.DomainAlreadyExistsError; -import com.uber.cadence.DomainNotActiveError; -import com.uber.cadence.EntityNotExistsError; -import com.uber.cadence.GetSearchAttributesResponse; -import com.uber.cadence.GetTaskListsByDomainRequest; -import com.uber.cadence.GetTaskListsByDomainResponse; -import com.uber.cadence.GetWorkflowExecutionHistoryRequest; -import com.uber.cadence.GetWorkflowExecutionHistoryResponse; -import com.uber.cadence.InternalServiceError; -import com.uber.cadence.LimitExceededError; -import com.uber.cadence.ListArchivedWorkflowExecutionsRequest; -import com.uber.cadence.ListArchivedWorkflowExecutionsResponse; -import com.uber.cadence.ListClosedWorkflowExecutionsRequest; -import com.uber.cadence.ListClosedWorkflowExecutionsResponse; -import com.uber.cadence.ListDomainsRequest; -import com.uber.cadence.ListDomainsResponse; -import com.uber.cadence.ListOpenWorkflowExecutionsRequest; -import com.uber.cadence.ListOpenWorkflowExecutionsResponse; -import com.uber.cadence.ListTaskListPartitionsRequest; -import com.uber.cadence.ListTaskListPartitionsResponse; -import com.uber.cadence.ListWorkflowExecutionsRequest; -import com.uber.cadence.ListWorkflowExecutionsResponse; -import com.uber.cadence.PollForActivityTaskRequest; -import com.uber.cadence.PollForActivityTaskResponse; -import com.uber.cadence.PollForDecisionTaskRequest; -import com.uber.cadence.PollForDecisionTaskResponse; -import com.uber.cadence.QueryFailedError; -import com.uber.cadence.QueryWorkflowRequest; -import com.uber.cadence.QueryWorkflowResponse; -import com.uber.cadence.RecordActivityTaskHeartbeatByIDRequest; -import com.uber.cadence.RecordActivityTaskHeartbeatRequest; -import com.uber.cadence.RecordActivityTaskHeartbeatResponse; -import com.uber.cadence.RefreshWorkflowTasksRequest; -import com.uber.cadence.RegisterDomainRequest; -import com.uber.cadence.RequestCancelWorkflowExecutionRequest; -import com.uber.cadence.ResetStickyTaskListRequest; -import com.uber.cadence.ResetStickyTaskListResponse; -import com.uber.cadence.ResetWorkflowExecutionRequest; -import com.uber.cadence.ResetWorkflowExecutionResponse; -import com.uber.cadence.RespondActivityTaskCanceledByIDRequest; -import com.uber.cadence.RespondActivityTaskCanceledRequest; -import com.uber.cadence.RespondActivityTaskCompletedByIDRequest; -import com.uber.cadence.RespondActivityTaskCompletedRequest; -import com.uber.cadence.RespondActivityTaskFailedByIDRequest; -import com.uber.cadence.RespondActivityTaskFailedRequest; -import com.uber.cadence.RespondDecisionTaskCompletedRequest; -import com.uber.cadence.RespondDecisionTaskCompletedResponse; -import com.uber.cadence.RespondDecisionTaskFailedRequest; -import com.uber.cadence.RespondQueryTaskCompletedRequest; -import com.uber.cadence.RestartWorkflowExecutionRequest; -import com.uber.cadence.RestartWorkflowExecutionResponse; -import com.uber.cadence.RetryPolicy; -import com.uber.cadence.ServiceBusyError; -import com.uber.cadence.SignalExternalWorkflowExecutionDecisionAttributes; -import com.uber.cadence.SignalExternalWorkflowExecutionFailedCause; -import com.uber.cadence.SignalWithStartWorkflowExecutionAsyncRequest; -import com.uber.cadence.SignalWithStartWorkflowExecutionAsyncResponse; -import com.uber.cadence.SignalWithStartWorkflowExecutionRequest; -import com.uber.cadence.SignalWorkflowExecutionRequest; -import com.uber.cadence.StartWorkflowExecutionAsyncRequest; -import com.uber.cadence.StartWorkflowExecutionAsyncResponse; -import com.uber.cadence.StartWorkflowExecutionRequest; -import com.uber.cadence.StartWorkflowExecutionResponse; -import com.uber.cadence.TerminateWorkflowExecutionRequest; -import com.uber.cadence.UpdateDomainRequest; -import com.uber.cadence.UpdateDomainResponse; -import com.uber.cadence.WorkflowExecution; -import com.uber.cadence.WorkflowExecutionAlreadyCompletedError; -import com.uber.cadence.WorkflowExecutionAlreadyStartedError; -import com.uber.cadence.WorkflowExecutionCloseStatus; -import com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes; -import com.uber.cadence.WorkflowExecutionFilter; -import com.uber.cadence.WorkflowExecutionInfo; -import com.uber.cadence.WorkflowIdReusePolicy; +import com.uber.cadence.api.v1.*; import com.uber.cadence.internal.testservice.TestWorkflowMutableStateImpl.QueryId; import com.uber.cadence.internal.testservice.TestWorkflowStore.WorkflowState; +import com.uber.cadence.serviceclient.CallMetaData; import com.uber.cadence.serviceclient.ClientOptions; -import com.uber.cadence.serviceclient.IWorkflowService; -import java.time.Duration; +import com.uber.cadence.serviceclient.IWorkflowServiceV4; +import com.uber.cadence.serviceclient.exceptions.*; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.OptionalLong; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; import java.util.concurrent.ForkJoinPool; -import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import javax.annotation.Nullable; import org.apache.thrift.TException; import org.apache.thrift.async.AsyncMethodCallback; import org.slf4j.Logger; @@ -128,8 +43,7 @@ * In memory implementation of the Cadence service. To be used for testing purposes only. Do not use * directly. Instead use {@link com.uber.cadence.testing.TestWorkflowEnvironment}. */ -public final class TestWorkflowService implements IWorkflowService { - +public final class TestWorkflowService implements IWorkflowServiceV4 { private static final Logger log = LoggerFactory.getLogger(TestWorkflowService.class); private final Lock lock = new ReentrantLock(); @@ -143,23 +57,13 @@ public final class TestWorkflowService implements IWorkflowService { private final ForkJoinPool forkJoinPool = new ForkJoinPool(4); - @Override - public void close() { - store.close(); - } - - @Override - public ClientOptions getOptions() { - return ClientOptions.defaultInstance(); - } - private TestWorkflowMutableState getMutableState(ExecutionId executionId) - throws InternalServiceError, EntityNotExistsError { + throws InternalServiceException, EntityNotExistsException { return getMutableState(executionId, true); } private TestWorkflowMutableState getMutableState(ExecutionId executionId, boolean failNotExists) - throws InternalServiceError, EntityNotExistsError { + throws InternalServiceException, EntityNotExistsException { lock.lock(); try { if (executionId.getExecution().getRunId() == null) { @@ -167,7 +71,7 @@ private TestWorkflowMutableState getMutableState(ExecutionId executionId, boolea } TestWorkflowMutableState mutableState = executions.get(executionId); if (mutableState == null && failNotExists) { - throw new InternalServiceError("Execution not found in mutable state: " + executionId); + throw new InternalServiceException("Execution not found in mutable state: " + executionId); } return mutableState; } finally { @@ -176,17 +80,17 @@ private TestWorkflowMutableState getMutableState(ExecutionId executionId, boolea } private TestWorkflowMutableState getMutableState(WorkflowId workflowId) - throws EntityNotExistsError { + throws EntityNotExistsException { return getMutableState(workflowId, true); } private TestWorkflowMutableState getMutableState(WorkflowId workflowId, boolean failNotExists) - throws EntityNotExistsError { + throws EntityNotExistsException { lock.lock(); try { TestWorkflowMutableState mutableState = executionsByWorkflowId.get(workflowId); if (mutableState == null && failNotExists) { - throw new EntityNotExistsError("Execution not found in mutable state: " + workflowId); + throw new EntityNotExistsException("Execution not found in mutable state: " + workflowId); } return mutableState; } finally { @@ -195,1063 +99,528 @@ private TestWorkflowMutableState getMutableState(WorkflowId workflowId, boolean } @Override - public void RegisterDomain(RegisterDomainRequest registerRequest) - throws BadRequestError, InternalServiceError, DomainAlreadyExistsError, TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public DescribeDomainResponse DescribeDomain(DescribeDomainRequest describeRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public ListDomainsResponse ListDomains(ListDomainsRequest listRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError, - TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public UpdateDomainResponse UpdateDomain(UpdateDomainRequest updateRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void DeprecateDomain(DeprecateDomainRequest deprecateRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public RestartWorkflowExecutionResponse RestartWorkflowExecution( - RestartWorkflowExecutionRequest restartRequest) - throws BadRequestError, ServiceBusyError, DomainNotActiveError, LimitExceededError, - EntityNotExistsError, ClientVersionNotSupportedError, TException { - throw new UnsupportedOperationException("not implemented"); - } + public Blocking blockingStub() { + return new Blocking() { + @Override + public StartWorkflowExecutionResponse startWorkflowExecution( + StartWorkflowExecutionRequest request, @Nullable CallMetaData meta) { + return startWorkflowExecutionImpl( + request, 0, Optional.empty(), OptionalLong.empty(), Optional.empty()); + } - @Override - public GetTaskListsByDomainResponse GetTaskListsByDomain(GetTaskListsByDomainRequest request) - throws BadRequestError, EntityNotExistsError, LimitExceededError, ServiceBusyError, - ClientVersionNotSupportedError, TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public StartWorkflowExecutionAsyncResponse startWorkflowExecutionAsync( + StartWorkflowExecutionAsyncRequest request, @Nullable CallMetaData meta) { + startWorkflowExecution(request.getRequest(), meta); + // Just run it + return StartWorkflowExecutionAsyncResponse.getDefaultInstance(); + } - @Override - public StartWorkflowExecutionResponse StartWorkflowExecution( - StartWorkflowExecutionRequest startRequest) throws TException { - return startWorkflowExecutionImpl( - startRequest, 0, Optional.empty(), OptionalLong.empty(), Optional.empty()); - } + @Override + public GetWorkflowExecutionHistoryResponse getWorkflowExecutionHistory( + GetWorkflowExecutionHistoryRequest getRequest, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceBusyException, ServiceClientException { + ExecutionId executionId = + new ExecutionId(getRequest.getDomain(), getRequest.getWorkflowExecution()); + TestWorkflowMutableState mutableState = getMutableState(executionId); - @Override - public StartWorkflowExecutionAsyncResponse StartWorkflowExecutionAsync( - StartWorkflowExecutionAsyncRequest startRequest) - throws BadRequestError, WorkflowExecutionAlreadyStartedError, ServiceBusyError, - DomainNotActiveError, LimitExceededError, EntityNotExistsError, - ClientVersionNotSupportedError, TException { - // Just run it - StartWorkflowExecution(startRequest.getRequest()); - return new StartWorkflowExecutionAsyncResponse(); - } + return store.getWorkflowExecutionHistory(mutableState.getExecutionId(), getRequest); + } - StartWorkflowExecutionResponse startWorkflowExecutionImpl( - StartWorkflowExecutionRequest startRequest, - int backoffStartIntervalInSeconds, - Optional parent, - OptionalLong parentChildInitiatedEventId, - Optional signalWithStartSignal) - throws BadRequestError, WorkflowExecutionAlreadyStartedError, InternalServiceError { - String requestWorkflowId = requireNotNull("WorkflowId", startRequest.getWorkflowId()); - String domain = requireNotNull("Domain", startRequest.getDomain()); - WorkflowId workflowId = new WorkflowId(domain, requestWorkflowId); - TestWorkflowMutableState existing; - lock.lock(); - try { - existing = executionsByWorkflowId.get(workflowId); - if (existing != null) { - Optional statusOptional = existing.getCloseStatus(); - WorkflowIdReusePolicy policy = - startRequest.isSetWorkflowIdReusePolicy() - ? startRequest.getWorkflowIdReusePolicy() - : WorkflowIdReusePolicy.AllowDuplicateFailedOnly; - if (!statusOptional.isPresent() || policy == WorkflowIdReusePolicy.RejectDuplicate) { - return throwDuplicatedWorkflow(startRequest, existing); + @Override + public PollForDecisionTaskResponse pollForDecisionTask( + PollForDecisionTaskRequest pollRequest, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, ServiceBusyException, + ServiceClientException { + PollForDecisionTaskResponse task; + try { + task = store.pollForDecisionTask(pollRequest); + } catch (InterruptedException e) { + return PollForDecisionTaskResponse.getDefaultInstance(); } - WorkflowExecutionCloseStatus status = statusOptional.get(); - if (policy == WorkflowIdReusePolicy.AllowDuplicateFailedOnly - && (status == WorkflowExecutionCloseStatus.COMPLETED - || status == WorkflowExecutionCloseStatus.CONTINUED_AS_NEW)) { - return throwDuplicatedWorkflow(startRequest, existing); + ExecutionId executionId = + new ExecutionId(pollRequest.getDomain(), task.getWorkflowExecution()); + TestWorkflowMutableState mutableState = getMutableState(executionId); + try { + mutableState.startDecisionTask(task, pollRequest); + // The task always has the original tasklist is was created on as part of the response. + // This + // may different + // then the task list it was scheduled on as in the case of sticky execution. + return task.toBuilder() + .setWorkflowExecutionTaskList(mutableState.getStartRequest().getTaskList()) + .build(); + ; + } catch (EntityNotExistsException e) { + if (log.isDebugEnabled()) { + log.debug("Skipping outdated decision task for " + executionId, e); + } + // skip the task } + return task.toBuilder() + .setWorkflowExecutionTaskList(mutableState.getStartRequest().getTaskList()) + .build(); + ; } - RetryPolicy retryPolicy = startRequest.getRetryPolicy(); - Optional retryState = newRetryStateLocked(retryPolicy); - return startWorkflowExecutionNoRunningCheckLocked( - startRequest, - Optional.empty(), - retryState, - backoffStartIntervalInSeconds, - null, - parent, - parentChildInitiatedEventId, - signalWithStartSignal, - workflowId); - } finally { - lock.unlock(); - } - } - - private Optional newRetryStateLocked(RetryPolicy retryPolicy) throws BadRequestError { - if (retryPolicy == null) { - return Optional.empty(); - } - long expirationInterval = - TimeUnit.SECONDS.toMillis(retryPolicy.getExpirationIntervalInSeconds()); - long expirationTime = store.currentTimeMillis() + expirationInterval; - return Optional.of(new RetryState(retryPolicy, expirationTime)); - } - private StartWorkflowExecutionResponse throwDuplicatedWorkflow( - StartWorkflowExecutionRequest startRequest, TestWorkflowMutableState existing) - throws WorkflowExecutionAlreadyStartedError { - WorkflowExecutionAlreadyStartedError error = new WorkflowExecutionAlreadyStartedError(); - WorkflowExecution execution = existing.getExecutionId().getExecution(); - error.setMessage( - String.format( - "WorkflowId: %s, " + "RunId: %s", execution.getWorkflowId(), execution.getRunId())); - error.setRunId(execution.getRunId()); - error.setStartRequestId(startRequest.getRequestId()); - throw error; - } - - private StartWorkflowExecutionResponse startWorkflowExecutionNoRunningCheckLocked( - StartWorkflowExecutionRequest startRequest, - Optional continuedExecutionRunId, - Optional retryState, - int backoffStartIntervalInSeconds, - byte[] lastCompletionResult, - Optional parent, - OptionalLong parentChildInitiatedEventId, - Optional signalWithStartSignal, - WorkflowId workflowId) - throws InternalServiceError, BadRequestError { - String domain = startRequest.getDomain(); - TestWorkflowMutableState mutableState = - new TestWorkflowMutableStateImpl( - startRequest, - retryState, - backoffStartIntervalInSeconds, - lastCompletionResult, - parent, - parentChildInitiatedEventId, - continuedExecutionRunId, - this, - store); - WorkflowExecution execution = mutableState.getExecutionId().getExecution(); - ExecutionId executionId = new ExecutionId(domain, execution); - executionsByWorkflowId.put(workflowId, mutableState); - executions.put(executionId, mutableState); - mutableState.startWorkflow(continuedExecutionRunId.isPresent(), signalWithStartSignal); - return new StartWorkflowExecutionResponse().setRunId(execution.getRunId()); - } - - @Override - public GetWorkflowExecutionHistoryResponse GetWorkflowExecutionHistory( - GetWorkflowExecutionHistoryRequest getRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError, - TException { - ExecutionId executionId = new ExecutionId(getRequest.getDomain(), getRequest.getExecution()); - TestWorkflowMutableState mutableState = getMutableState(executionId); - - return store.getWorkflowExecutionHistory(mutableState.getExecutionId(), getRequest); - } - - @Override - public GetWorkflowExecutionHistoryResponse GetWorkflowExecutionHistoryWithTimeout( - GetWorkflowExecutionHistoryRequest getRequest, Long timeoutInMillis) - throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError, - TException { - - return GetWorkflowExecutionHistory(getRequest); - } - - @Override - public PollForDecisionTaskResponse PollForDecisionTask(PollForDecisionTaskRequest pollRequest) - throws BadRequestError, InternalServiceError, ServiceBusyError, TException { - PollForDecisionTaskResponse task; - try { - task = store.pollForDecisionTask(pollRequest); - } catch (InterruptedException e) { - return new PollForDecisionTaskResponse(); - } - ExecutionId executionId = new ExecutionId(pollRequest.getDomain(), task.getWorkflowExecution()); - TestWorkflowMutableState mutableState = getMutableState(executionId); - try { - mutableState.startDecisionTask(task, pollRequest); - // The task always has the original tasklist is was created on as part of the response. This - // may different - // then the task list it was scheduled on as in the case of sticky execution. - task.setWorkflowExecutionTaskList(mutableState.getStartRequest().taskList); - return task; - } catch (EntityNotExistsError e) { - if (log.isDebugEnabled()) { - log.debug("Skipping outdated decision task for " + executionId, e); + @Override + public RespondDecisionTaskCompletedResponse respondDecisionTaskCompleted( + RespondDecisionTaskCompletedRequest request, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceClientException { + DecisionTaskToken taskToken = + DecisionTaskToken.fromBytes(request.getTaskToken().toByteArray()); + TestWorkflowMutableState mutableState = getMutableState(taskToken.getExecutionId()); + mutableState.completeDecisionTask(taskToken.getHistorySize(), request); + return RespondDecisionTaskCompletedResponse.getDefaultInstance(); } - // skip the task - } - task.setWorkflowExecutionTaskList(mutableState.getStartRequest().taskList); - return task; - } - - @Override - public RespondDecisionTaskCompletedResponse RespondDecisionTaskCompleted( - RespondDecisionTaskCompletedRequest request) - throws BadRequestError, InternalServiceError, EntityNotExistsError, TException { - DecisionTaskToken taskToken = DecisionTaskToken.fromBytes(request.getTaskToken()); - TestWorkflowMutableState mutableState = getMutableState(taskToken.getExecutionId()); - mutableState.completeDecisionTask(taskToken.getHistorySize(), request); - return new RespondDecisionTaskCompletedResponse(); - } - - @Override - public void RespondDecisionTaskFailed(RespondDecisionTaskFailedRequest failedRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, TException { - DecisionTaskToken taskToken = DecisionTaskToken.fromBytes(failedRequest.getTaskToken()); - TestWorkflowMutableState mutableState = getMutableState(taskToken.getExecutionId()); - mutableState.failDecisionTask(failedRequest); - } - @Override - public PollForActivityTaskResponse PollForActivityTask(PollForActivityTaskRequest pollRequest) - throws BadRequestError, InternalServiceError, ServiceBusyError, TException { - PollForActivityTaskResponse task; - while (true) { - try { - task = store.pollForActivityTask(pollRequest); - } catch (InterruptedException e) { - return new PollForActivityTaskResponse(); + @Override + public RespondDecisionTaskFailedResponse respondDecisionTaskFailed( + RespondDecisionTaskFailedRequest failedRequest, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceClientException { + DecisionTaskToken taskToken = + DecisionTaskToken.fromBytes(failedRequest.getTaskToken().toByteArray()); + TestWorkflowMutableState mutableState = getMutableState(taskToken.getExecutionId()); + mutableState.failDecisionTask(failedRequest); + return RespondDecisionTaskFailedResponse.getDefaultInstance(); } - ExecutionId executionId = - new ExecutionId(pollRequest.getDomain(), task.getWorkflowExecution()); - TestWorkflowMutableState mutableState = getMutableState(executionId); - try { - mutableState.startActivityTask(task, pollRequest); - return task; - } catch (EntityNotExistsError e) { - if (log.isDebugEnabled()) { - log.debug("Skipping outdated activity task for " + executionId, e); + + @Override + public PollForActivityTaskResponse pollForActivityTask( + PollForActivityTaskRequest pollRequest, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, ServiceBusyException, + ServiceClientException { + PollForActivityTaskResponse task; + while (true) { + try { + task = store.pollForActivityTask(pollRequest); + } catch (InterruptedException e) { + return PollForActivityTaskResponse.getDefaultInstance(); + } + ExecutionId executionId = + new ExecutionId(pollRequest.getDomain(), task.getWorkflowExecution()); + TestWorkflowMutableState mutableState = getMutableState(executionId); + try { + mutableState.startActivityTask(task, pollRequest); + return task; + } catch (EntityNotExistsException e) { + if (log.isDebugEnabled()) { + log.debug("Skipping outdated activity task for " + executionId, e); + } + } } } - } - } - - @Override - public RecordActivityTaskHeartbeatResponse RecordActivityTaskHeartbeat( - RecordActivityTaskHeartbeatRequest heartbeatRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, TException { - ActivityId activityId = ActivityId.fromBytes(heartbeatRequest.getTaskToken()); - TestWorkflowMutableState mutableState = getMutableState(activityId.getExecutionId()); - return mutableState.heartbeatActivityTask(activityId.getId(), heartbeatRequest.getDetails()); - } - - @Override - public RecordActivityTaskHeartbeatResponse RecordActivityTaskHeartbeatByID( - RecordActivityTaskHeartbeatByIDRequest heartbeatRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, DomainNotActiveError, - LimitExceededError, ServiceBusyError, TException { - ExecutionId execution = - new ExecutionId( - heartbeatRequest.getDomain(), - heartbeatRequest.getWorkflowID(), - heartbeatRequest.getRunID()); - TestWorkflowMutableState mutableState = getMutableState(execution); - return mutableState.heartbeatActivityTask( - heartbeatRequest.getActivityID(), heartbeatRequest.getDetails()); - } - - @Override - public void RespondActivityTaskCompleted(RespondActivityTaskCompletedRequest completeRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, TException { - ActivityId activityId = ActivityId.fromBytes(completeRequest.getTaskToken()); - TestWorkflowMutableState mutableState = getMutableState(activityId.getExecutionId()); - mutableState.completeActivityTask(activityId.getId(), completeRequest); - } - - @Override - public void RespondActivityTaskCompletedByID( - RespondActivityTaskCompletedByIDRequest completeRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, TException { - ActivityId activityId = - new ActivityId( - completeRequest.getDomain(), - completeRequest.getWorkflowID(), - completeRequest.getRunID(), - completeRequest.getActivityID()); - TestWorkflowMutableState mutableState = getMutableState(activityId.getWorkflowId()); - mutableState.completeActivityTaskById(activityId.getId(), completeRequest); - } - @Override - public void RespondActivityTaskFailed(RespondActivityTaskFailedRequest failRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, TException { - ActivityId activityId = ActivityId.fromBytes(failRequest.getTaskToken()); - TestWorkflowMutableState mutableState = getMutableState(activityId.getExecutionId()); - mutableState.failActivityTask(activityId.getId(), failRequest); - } - - @Override - public void RespondActivityTaskFailedByID(RespondActivityTaskFailedByIDRequest failRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, TException { - ActivityId activityId = - new ActivityId( - failRequest.getDomain(), - failRequest.getWorkflowID(), - failRequest.getRunID(), - failRequest.getActivityID()); - TestWorkflowMutableState mutableState = getMutableState(activityId.getWorkflowId()); - mutableState.failActivityTaskById(activityId.getId(), failRequest); - } + @Override + public RecordActivityTaskHeartbeatResponse recordActivityTaskHeartbeat( + RecordActivityTaskHeartbeatRequest heartbeatRequest, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceClientException { + ActivityId activityId = ActivityId.fromBytes(heartbeatRequest.getTaskToken().toByteArray()); + TestWorkflowMutableState mutableState = getMutableState(activityId.getExecutionId()); + return mutableState.heartbeatActivityTask( + activityId.getId(), heartbeatRequest.getDetails().toByteArray()); + } - @Override - public void RespondActivityTaskCanceled(RespondActivityTaskCanceledRequest canceledRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, TException { - ActivityId activityId = ActivityId.fromBytes(canceledRequest.getTaskToken()); - TestWorkflowMutableState mutableState = getMutableState(activityId.getExecutionId()); - mutableState.cancelActivityTask(activityId.getId(), canceledRequest); - } + @Override + public RespondActivityTaskCompletedResponse respondActivityTaskCompleted( + RespondActivityTaskCompletedRequest completeRequest, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceClientException { + ActivityId activityId = ActivityId.fromBytes(completeRequest.getTaskToken().toByteArray()); + TestWorkflowMutableState mutableState = getMutableState(activityId.getExecutionId()); + mutableState.completeActivityTask(activityId.getId(), completeRequest); + } - @Override - public void RespondActivityTaskCanceledByID( - RespondActivityTaskCanceledByIDRequest canceledRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, TException { - ActivityId activityId = - new ActivityId( - canceledRequest.getDomain(), - canceledRequest.getWorkflowID(), - canceledRequest.getRunID(), - canceledRequest.getActivityID()); - TestWorkflowMutableState mutableState = getMutableState(activityId.getWorkflowId()); - mutableState.cancelActivityTaskById(activityId.getId(), canceledRequest); - } + @Override + public RespondActivityTaskFailedResponse respondActivityTaskFailed( + RespondActivityTaskFailedRequest failRequest, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceClientException { + ActivityId activityId = ActivityId.fromBytes(failRequest.getTaskToken().toByteArray()); + TestWorkflowMutableState mutableState = getMutableState(activityId.getExecutionId()); + mutableState.failActivityTask(activityId.getId(), failRequest); + } - @Override - public void RequestCancelWorkflowExecution(RequestCancelWorkflowExecutionRequest cancelRequest) - throws TException { - ExecutionId executionId = - new ExecutionId(cancelRequest.getDomain(), cancelRequest.getWorkflowExecution()); - TestWorkflowMutableState mutableState = getMutableState(executionId); - mutableState.requestCancelWorkflowExecution(cancelRequest); - } + @Override + public RespondActivityTaskCanceledResponse respondActivityTaskCanceled( + RespondActivityTaskCanceledRequest canceledRequest, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceClientException { + ActivityId activityId = ActivityId.fromBytes(canceledRequest.getTaskToken().toByteArray()); + TestWorkflowMutableState mutableState = getMutableState(activityId.getExecutionId()); + mutableState.cancelActivityTask(activityId.getId(), canceledRequest); + return RespondActivityTaskCanceledResponse.getDefaultInstance(); + } - @Override - public void SignalWorkflowExecution(SignalWorkflowExecutionRequest signalRequest) - throws TException { - ExecutionId executionId = - new ExecutionId(signalRequest.getDomain(), signalRequest.getWorkflowExecution()); - TestWorkflowMutableState mutableState = getMutableState(executionId); - mutableState.signal(signalRequest); - } + @Override + public RespondActivityTaskCanceledByIDResponse respondActivityTaskCanceledByID( + RespondActivityTaskCanceledByIDRequest canceledRequest, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceClientException { + ActivityId activityId = + new ActivityId( + canceledRequest.getDomain(), + canceledRequest.getWorkflowExecution().getWorkflowId(), + canceledRequest.getWorkflowExecution().getRunId(), + canceledRequest.getActivityId()); + TestWorkflowMutableState mutableState = getMutableState(activityId.getWorkflowId()); + mutableState.cancelActivityTaskById(activityId.getId(), canceledRequest); + return RespondActivityTaskCanceledByIDResponse.getDefaultInstance(); + } - @Override - public StartWorkflowExecutionResponse SignalWithStartWorkflowExecution( - SignalWithStartWorkflowExecutionRequest r) - throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError, - DomainNotActiveError, LimitExceededError, WorkflowExecutionAlreadyStartedError, - TException { - ExecutionId executionId = new ExecutionId(r.getDomain(), r.getWorkflowId(), null); - TestWorkflowMutableState mutableState = getMutableState(executionId, false); - SignalWorkflowExecutionRequest signalRequest = - new SignalWorkflowExecutionRequest() - .setInput(r.getSignalInput()) - .setSignalName(r.getSignalName()) - .setControl(r.getControl()) - .setDomain(r.getDomain()) - .setWorkflowExecution(executionId.getExecution()) - .setRequestId(r.getRequestId()) - .setIdentity(r.getIdentity()); - if (mutableState != null) { - mutableState.signal(signalRequest); - return new StartWorkflowExecutionResponse() - .setRunId(mutableState.getExecutionId().getExecution().getRunId()); - } - StartWorkflowExecutionRequest startRequest = - new StartWorkflowExecutionRequest() - .setInput(r.getInput()) - .setExecutionStartToCloseTimeoutSeconds(r.getExecutionStartToCloseTimeoutSeconds()) - .setTaskStartToCloseTimeoutSeconds(r.getTaskStartToCloseTimeoutSeconds()) - .setDomain(r.getDomain()) - .setRetryPolicy(r.getRetryPolicy()) - .setTaskList(r.getTaskList()) - .setWorkflowId(r.getWorkflowId()) - .setWorkflowIdReusePolicy(r.getWorkflowIdReusePolicy()) - .setWorkflowType(r.getWorkflowType()) - .setCronSchedule(r.getCronSchedule()) - .setRequestId(r.getRequestId()) - .setIdentity(r.getIdentity()); - return startWorkflowExecutionImpl( - startRequest, 0, Optional.empty(), OptionalLong.empty(), Optional.of(signalRequest)); - } + @Override + public RequestCancelWorkflowExecutionResponse requestCancelWorkflowExecution( + RequestCancelWorkflowExecutionRequest cancelRequest, @Nullable CallMetaData meta) + throws ServiceClientException { + ExecutionId executionId = + new ExecutionId(cancelRequest.getDomain(), cancelRequest.getWorkflowExecution()); + TestWorkflowMutableState mutableState = getMutableState(executionId); + mutableState.requestCancelWorkflowExecution(cancelRequest); + return RequestCancelWorkflowExecutionResponse.getDefaultInstance(); + } - @Override - public SignalWithStartWorkflowExecutionAsyncResponse SignalWithStartWorkflowExecutionAsync( - SignalWithStartWorkflowExecutionAsyncRequest signalWithStartRequest) - throws BadRequestError, WorkflowExecutionAlreadyStartedError, ServiceBusyError, - DomainNotActiveError, LimitExceededError, EntityNotExistsError, - ClientVersionNotSupportedError, TException { - SignalWithStartWorkflowExecution(signalWithStartRequest.getRequest()); - return new SignalWithStartWorkflowExecutionAsyncResponse(); - } + @Override + public SignalWorkflowExecutionResponse signalWorkflowExecution( + SignalWorkflowExecutionRequest signalRequest, @Nullable CallMetaData meta) + throws ServiceClientException { + ExecutionId executionId = + new ExecutionId(signalRequest.getDomain(), signalRequest.getWorkflowExecution()); + TestWorkflowMutableState mutableState = getMutableState(executionId); + mutableState.signal(signalRequest); + return SignalWorkflowExecutionResponse.getDefaultInstance(); + } - // TODO: https://github.com/uber/cadence-java-client/issues/359 - @Override - public ResetWorkflowExecutionResponse ResetWorkflowExecution( - ResetWorkflowExecutionRequest resetRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError, - DomainNotActiveError, LimitExceededError, ClientVersionNotSupportedError, TException { - return null; - } + @Override + public SignalWithStartWorkflowExecutionResponse signalWithStartWorkflowExecution( + SignalWithStartWorkflowExecutionRequest r, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceBusyException, DomainNotActiveException, LimitExceededException, + WorkflowExecutionAlreadyStartedException, ServiceClientException { + ExecutionId executionId = + new ExecutionId( + r.getStartRequest().getDomain(), r.getStartRequest().getWorkflowId(), null); + TestWorkflowMutableState mutableState = getMutableState(executionId, false); + SignalWorkflowExecutionRequest signalRequest = + SignalWorkflowExecutionRequest.newBuilder() + .setSignalInput(r.getSignalInput()) + .setSignalName(r.getSignalName()) + .setControl(r.getControl()) + .setDomain(r.getStartRequest().getDomain()) + .setWorkflowExecution(executionId.getExecution()) + .setRequestId(r.getRequestId()) + .setIdentity(r.getIdentity()) + .build(); + if (mutableState != null) { + mutableState.signal(signalRequest); + return SignalWithStartWorkflowExecutionResponse.newBuilder() + .setRunId(mutableState.getExecutionId().getExecution().getRunId()) + .build(); + } + StartWorkflowExecutionRequest startRequest = r.getStartRequest(); + return startWorkflowExecutionImpl( + startRequest, 0, Optional.empty(), OptionalLong.empty(), Optional.of(signalRequest)); + } - public void signalExternalWorkflowExecution( - String signalId, - SignalExternalWorkflowExecutionDecisionAttributes a, - TestWorkflowMutableState source) - throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError, - BadRequestError { - ExecutionId executionId = new ExecutionId(a.getDomain(), a.getExecution()); - TestWorkflowMutableState mutableState = null; - try { - mutableState = getMutableState(executionId); - mutableState.signalFromWorkflow(a); - source.completeSignalExternalWorkflowExecution( - signalId, mutableState.getExecutionId().getExecution().getRunId()); - } catch (EntityNotExistsError entityNotExistsError) { - source.failSignalExternalWorkflowExecution( - signalId, SignalExternalWorkflowExecutionFailedCause.UNKNOWN_EXTERNAL_WORKFLOW_EXECUTION); - } - } + @Override + public SignalWithStartWorkflowExecutionAsyncResponse signalWithStartWorkflowExecutionAsync( + SignalWithStartWorkflowExecutionAsyncRequest signalWithStartRequest, + @Nullable CallMetaData meta) + throws BadRequestException, WorkflowExecutionAlreadyStartedException, + ServiceBusyException, DomainNotActiveException, LimitExceededException, + EntityNotExistsException, ClientVersionNotSupportedException, ServiceClientException { + signalWithStartWorkflowExecution(signalWithStartRequest.getRequest(), meta); + return SignalWithStartWorkflowExecutionAsyncResponse.getDefaultInstance(); + } - @Override - public void TerminateWorkflowExecution(TerminateWorkflowExecutionRequest terminateRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError, - TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public ListOpenWorkflowExecutionsResponse listOpenWorkflowExecutions( + ListOpenWorkflowExecutionsRequest listRequest, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceBusyException, ServiceClientException { + Optional workflowIdFilter; + WorkflowExecutionFilter executionFilter = listRequest.getExecutionFilter(); + if (executionFilter != null + && executionFilter.isSetWorkflowId() + && !executionFilter.getWorkflowId().isEmpty()) { + workflowIdFilter = Optional.of(executionFilter.getWorkflowId()); + } else { + workflowIdFilter = Optional.empty(); + } + List result = + store.listWorkflows(WorkflowState.OPEN, workflowIdFilter); + return ListOpenWorkflowExecutionsResponse.newBuilder().addAllExecutions(result).build(); + } - /** - * Creates next run of a workflow execution - * - * @return RunId - */ - public String continueAsNew( - StartWorkflowExecutionRequest previousRunStartRequest, - WorkflowExecutionContinuedAsNewEventAttributes a, - Optional retryState, - String identity, - ExecutionId executionId, - Optional parent, - OptionalLong parentChildInitiatedEventId) - throws InternalServiceError, BadRequestError { - StartWorkflowExecutionRequest startRequest = - new StartWorkflowExecutionRequest() - .setWorkflowType(a.getWorkflowType()) - .setExecutionStartToCloseTimeoutSeconds(a.getExecutionStartToCloseTimeoutSeconds()) - .setTaskStartToCloseTimeoutSeconds(a.getTaskStartToCloseTimeoutSeconds()) - .setDomain(executionId.getDomain()) - .setTaskList(a.getTaskList()) - .setWorkflowId(executionId.getWorkflowId().getWorkflowId()) - .setWorkflowIdReusePolicy(previousRunStartRequest.getWorkflowIdReusePolicy()) - .setIdentity(identity) - .setRetryPolicy(previousRunStartRequest.getRetryPolicy()) - .setCronSchedule(previousRunStartRequest.getCronSchedule()); - if (a.isSetInput()) { - startRequest.setInput(a.getInput()); - } - lock.lock(); - try { - StartWorkflowExecutionResponse response = - startWorkflowExecutionNoRunningCheckLocked( - startRequest, - Optional.of(executionId.getExecution().getRunId()), - retryState, - a.getBackoffStartIntervalInSeconds(), - a.getLastCompletionResult(), - parent, - parentChildInitiatedEventId, - Optional.empty(), - executionId.getWorkflowId()); - return response.getRunId(); - } finally { - lock.unlock(); - } - } + @Override + public ListClosedWorkflowExecutionsResponse listClosedWorkflowExecutions( + ListClosedWorkflowExecutionsRequest listRequest, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceBusyException, ServiceClientException { + Optional workflowIdFilter; + WorkflowExecutionFilter executionFilter = listRequest.getExecutionFilter(); + if (executionFilter != null + && executionFilter.isSetWorkflowId() + && !executionFilter.getWorkflowId().isEmpty()) { + workflowIdFilter = Optional.of(executionFilter.getWorkflowId()); + } else { + workflowIdFilter = Optional.empty(); + } + List result = + store.listWorkflows(WorkflowState.CLOSED, workflowIdFilter); + return ListClosedWorkflowExecutionsResponse.newBuilder().setExecutions(result); + } - @Override - public ListOpenWorkflowExecutionsResponse ListOpenWorkflowExecutions( - ListOpenWorkflowExecutionsRequest listRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError, - TException { - Optional workflowIdFilter; - WorkflowExecutionFilter executionFilter = listRequest.getExecutionFilter(); - if (executionFilter != null - && executionFilter.isSetWorkflowId() - && !executionFilter.getWorkflowId().isEmpty()) { - workflowIdFilter = Optional.of(executionFilter.getWorkflowId()); - } else { - workflowIdFilter = Optional.empty(); - } - List result = store.listWorkflows(WorkflowState.OPEN, workflowIdFilter); - return new ListOpenWorkflowExecutionsResponse().setExecutions(result); - } + @Override + public ListWorkflowExecutionsResponse listWorkflowExecutions( + ListWorkflowExecutionsRequest listRequest, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceBusyException, ClientVersionNotSupportedException, ServiceClientException { + throw new UnsupportedOperationException("not implemented"); + } - @Override - public ListClosedWorkflowExecutionsResponse ListClosedWorkflowExecutions( - ListClosedWorkflowExecutionsRequest listRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError, - TException { - Optional workflowIdFilter; - WorkflowExecutionFilter executionFilter = listRequest.getExecutionFilter(); - if (executionFilter != null - && executionFilter.isSetWorkflowId() - && !executionFilter.getWorkflowId().isEmpty()) { - workflowIdFilter = Optional.of(executionFilter.getWorkflowId()); - } else { - workflowIdFilter = Optional.empty(); - } - List result = - store.listWorkflows(WorkflowState.CLOSED, workflowIdFilter); - return new ListClosedWorkflowExecutionsResponse().setExecutions(result); - } + @Override + public ListArchivedWorkflowExecutionsResponse listArchivedWorkflowExecutions( + ListArchivedWorkflowExecutionsRequest listRequest, @Nullable CallMetaData meta) + throws BadRequestException, EntityNotExistsException, ServiceBusyException, + ClientVersionNotSupportedException, ServiceClientException { + throw new UnsupportedOperationException("not implemented"); + } - @Override - public ListWorkflowExecutionsResponse ListWorkflowExecutions( - ListWorkflowExecutionsRequest listRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError, - ClientVersionNotSupportedError, TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public ScanWorkflowExecutionsResponse scanWorkflowExecutions( + ScanWorkflowExecutionsRequest listRequest, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceBusyException, ClientVersionNotSupportedException, ServiceClientException { + throw new UnsupportedOperationException("not implemented"); + } - @Override - public ListArchivedWorkflowExecutionsResponse ListArchivedWorkflowExecutions( - ListArchivedWorkflowExecutionsRequest listRequest) - throws BadRequestError, EntityNotExistsError, ServiceBusyError, - ClientVersionNotSupportedError, TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public CountWorkflowExecutionsResponse countWorkflowExecutions( + CountWorkflowExecutionsRequest countRequest, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceBusyException, ClientVersionNotSupportedException, ServiceClientException { + throw new UnsupportedOperationException("not implemented"); + } - @Override - public ListWorkflowExecutionsResponse ScanWorkflowExecutions( - ListWorkflowExecutionsRequest listRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError, - ClientVersionNotSupportedError, TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public RespondQueryTaskCompletedResponse respondQueryTaskCompleted( + RespondQueryTaskCompletedRequest completeRequest, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceClientException { + QueryId queryId = QueryId.fromBytes(completeRequest.getTaskToken()); + TestWorkflowMutableState mutableState = getMutableState(queryId.getExecutionId()); + mutableState.completeQuery(queryId, completeRequest); + } - @Override - public CountWorkflowExecutionsResponse CountWorkflowExecutions( - CountWorkflowExecutionsRequest countRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError, - ClientVersionNotSupportedError, TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public ResetStickyTaskListResponse resetStickyTaskList( + ResetStickyTaskListRequest resetRequest, @Nullable CallMetaData meta) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + LimitExceededException, ServiceBusyException, DomainNotActiveException, + ServiceClientException { + throw new UnsupportedOperationException("not implemented"); + } - @Override - public GetSearchAttributesResponse GetSearchAttributes() - throws InternalServiceError, ServiceBusyError, ClientVersionNotSupportedError, TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public QueryWorkflowResponse QueryWorkflow(QueryWorkflowRequest queryRequest) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + QueryFailedError, ServiceClientException { + ExecutionId executionId = + new ExecutionId(queryRequest.getDomain(), queryRequest.getExecution()); + TestWorkflowMutableState mutableState = getMutableState(executionId); + return mutableState.query(queryRequest); + } - @Override - public void RespondQueryTaskCompleted(RespondQueryTaskCompletedRequest completeRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, TException { - QueryId queryId = QueryId.fromBytes(completeRequest.getTaskToken()); - TestWorkflowMutableState mutableState = getMutableState(queryId.getExecutionId()); - mutableState.completeQuery(queryId, completeRequest); - } + @Override + public DescribeWorkflowExecutionResponse DescribeWorkflowExecution( + DescribeWorkflowExecutionRequest describeRequest) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceClientException { + throw new UnsupportedOperationException("not implemented"); + } - @Override - public ResetStickyTaskListResponse ResetStickyTaskList(ResetStickyTaskListRequest resetRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, LimitExceededError, - ServiceBusyError, DomainNotActiveError, TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public DescribeTaskListResponse DescribeTaskList(DescribeTaskListRequest request) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceClientException { + throw new UnsupportedOperationException("not implemented"); + } - @Override - public QueryWorkflowResponse QueryWorkflow(QueryWorkflowRequest queryRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, QueryFailedError, - TException { - ExecutionId executionId = - new ExecutionId(queryRequest.getDomain(), queryRequest.getExecution()); - TestWorkflowMutableState mutableState = getMutableState(executionId); - return mutableState.query(queryRequest); - } + @Override + public ClusterInfo GetClusterInfo() + throws InternalServiceException, ServiceBusyException, ServiceClientException { + throw new UnsupportedOperationException("not implemented"); + } - @Override - public DescribeWorkflowExecutionResponse DescribeWorkflowExecution( - DescribeWorkflowExecutionRequest describeRequest) - throws BadRequestError, InternalServiceError, EntityNotExistsError, TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public ListTaskListPartitionsResponse ListTaskListPartitions( + ListTaskListPartitionsRequest request) + throws BadRequestException, EntityNotExistsException, LimitExceededException, + ServiceBusyException, ServiceClientException { + throw new UnsupportedOperationException("not implemented"); + } - @Override - public DescribeTaskListResponse DescribeTaskList(DescribeTaskListRequest request) - throws BadRequestError, InternalServiceError, EntityNotExistsError, TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public void RefreshWorkflowTasks(RefreshWorkflowTasksRequest request) + throws BadRequestException, DomainNotActiveException, ServiceBusyException, + EntityNotExistsException, ServiceClientException { + throw new UnsupportedOperationException("not implemented"); + } - @Override - public ClusterInfo GetClusterInfo() throws InternalServiceError, ServiceBusyError, TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public void RegisterDomain( + RegisterDomainRequest registerRequest, AsyncMethodCallback resultHandler) + throws ServiceClientException { + throw new UnsupportedOperationException("not implemented"); + } - @Override - public ListTaskListPartitionsResponse ListTaskListPartitions( - ListTaskListPartitionsRequest request) - throws BadRequestError, EntityNotExistsError, LimitExceededError, ServiceBusyError, - TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public void DescribeDomain( + DescribeDomainRequest describeRequest, AsyncMethodCallback resultHandler) + throws ServiceClientException { + throw new UnsupportedOperationException("not implemented"); + } - @Override - public void RefreshWorkflowTasks(RefreshWorkflowTasksRequest request) - throws BadRequestError, DomainNotActiveError, ServiceBusyError, EntityNotExistsError, - TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public void ListDomains(ListDomainsRequest listRequest, AsyncMethodCallback resultHandler) + throws ServiceClientException { + throw new UnsupportedOperationException("not implemented"); + } - @Override - public void RegisterDomain( - RegisterDomainRequest registerRequest, AsyncMethodCallback resultHandler) throws TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public void UpdateDomain(UpdateDomainRequest updateRequest, AsyncMethodCallback resultHandler) + throws ServiceClientException { + throw new UnsupportedOperationException("not implemented"); + } - @Override - public void DescribeDomain( - DescribeDomainRequest describeRequest, AsyncMethodCallback resultHandler) throws TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public void DeprecateDomain( + DeprecateDomainRequest deprecateRequest, AsyncMethodCallback resultHandler) + throws ServiceClientException { + throw new UnsupportedOperationException("not implemented"); + } - @Override - public void ListDomains(ListDomainsRequest listRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public void RestartWorkflowExecution( + RestartWorkflowExecutionRequest restartRequest, AsyncMethodCallback resultHandler) + throws ServiceClientException { + throw new UnsupportedOperationException("not implemented"); + } - @Override - public void UpdateDomain(UpdateDomainRequest updateRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public void GetTaskListsByDomain( + GetTaskListsByDomainRequest request, AsyncMethodCallback resultHandler) + throws org.apache.thrift.TException { + throw new UnsupportedOperationException("not implemented"); + } - @Override - public void DeprecateDomain( - DeprecateDomainRequest deprecateRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public void StartWorkflowExecution( + StartWorkflowExecutionRequest startRequest, AsyncMethodCallback resultHandler) + throws ServiceClientException { + StartWorkflowExecutionWithTimeout(startRequest, resultHandler, null); + } - @Override - public void RestartWorkflowExecution( - RestartWorkflowExecutionRequest restartRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public void StartWorkflowExecutionWithTimeout( + StartWorkflowExecutionRequest startRequest, + AsyncMethodCallback resultHandler, + Long timeoutInMillis) + throws ServiceClientException { + forkJoinPool.execute( + () -> { + try { + StartWorkflowExecutionResponse result = StartWorkflowExecution(startRequest); + resultHandler.onComplete(result); + } catch (TException e) { + resultHandler.onError(e); + } + }); + } - @Override - public void GetTaskListsByDomain( - GetTaskListsByDomainRequest request, AsyncMethodCallback resultHandler) - throws org.apache.thrift.TException { - throw new UnsupportedOperationException("not implemented"); - } + @Override + public void StartWorkflowExecutionAsync( + StartWorkflowExecutionAsyncRequest startRequest, AsyncMethodCallback resultHandler) + throws ServiceClientException { + StartWorkflowExecutionAsyncWithTimeout(startRequest, resultHandler, null); + } - @Override - public void StartWorkflowExecution( - StartWorkflowExecutionRequest startRequest, AsyncMethodCallback resultHandler) - throws TException { - StartWorkflowExecutionWithTimeout(startRequest, resultHandler, null); - } + @SuppressWarnings("unchecked") // Generator ignores that AsyncMethodCallback is generic + @Override + public void GetWorkflowExecutionHistory( + GetWorkflowExecutionHistoryRequest getRequest, AsyncMethodCallback resultHandler) + throws ServiceClientException { + forkJoinPool.execute( + () -> { + try { + GetWorkflowExecutionHistoryResponse result = + GetWorkflowExecutionHistory(getRequest); + resultHandler.onComplete(result); + } catch (TException e) { + resultHandler.onError(e); + } + }); + } - @Override - public void StartWorkflowExecutionWithTimeout( - StartWorkflowExecutionRequest startRequest, - AsyncMethodCallback resultHandler, - Long timeoutInMillis) - throws TException { - forkJoinPool.execute( - () -> { - try { - StartWorkflowExecutionResponse result = StartWorkflowExecution(startRequest); - resultHandler.onComplete(result); - } catch (TException e) { - resultHandler.onError(e); - } - }); - } + @SuppressWarnings("unchecked") // Generator ignores that AsyncMethodCallback is generic + @Override + public void GetWorkflowExecutionHistoryWithTimeout( + GetWorkflowExecutionHistoryRequest getRequest, + AsyncMethodCallback resultHandler, + Long timeoutInMillis) + throws ServiceClientException { + GetWorkflowExecutionHistory(getRequest, resultHandler); + } - @Override - public void StartWorkflowExecutionAsync( - StartWorkflowExecutionAsyncRequest startRequest, AsyncMethodCallback resultHandler) - throws TException { - StartWorkflowExecutionAsyncWithTimeout(startRequest, resultHandler, null); - } + @Override + public void SignalWorkflowExecution( + SignalWorkflowExecutionRequest signalRequest, AsyncMethodCallback resultHandler) + throws ServiceClientException { + SignalWorkflowExecutionWithTimeout(signalRequest, resultHandler, null); + } - @Override - public void StartWorkflowExecutionAsyncWithTimeout( - StartWorkflowExecutionAsyncRequest startAsyncRequest, - AsyncMethodCallback resultHandler, - Long timeoutInMillis) - throws TException { - // Treat it like a synchronous call but ignore the result - StartWorkflowExecutionWithTimeout( - startAsyncRequest.getRequest(), - new AsyncMethodCallback() { - @Override - public void onComplete(Object response) { - // Noop - } + @Override + public void SignalWorkflowExecutionWithTimeout( + SignalWorkflowExecutionRequest signalRequest, + AsyncMethodCallback resultHandler, + Long timeoutInMillis) + throws ServiceClientException { + forkJoinPool.execute( + () -> { + try { + SignalWorkflowExecution(signalRequest); + resultHandler.onComplete(null); + } catch (TException e) { + resultHandler.onError(e); + } + }); + } - @Override - public void onError(Exception exception) { - // Noop - } - }, - timeoutInMillis); - resultHandler.onComplete(new StartWorkflowExecutionAsyncResponse()); + @Override + public void TerminateWorkflowExecution(TerminateWorkflowExecutionRequest terminateRequest) + throws BadRequestException, InternalServiceException, EntityNotExistsException, + ServiceBusyException, ServiceClientException { + throw new UnsupportedOperationException("not implemented"); + } + }; } - @SuppressWarnings("unchecked") // Generator ignores that AsyncMethodCallback is generic @Override - public void GetWorkflowExecutionHistory( - GetWorkflowExecutionHistoryRequest getRequest, AsyncMethodCallback resultHandler) - throws TException { - forkJoinPool.execute( - () -> { - try { - GetWorkflowExecutionHistoryResponse result = GetWorkflowExecutionHistory(getRequest); - resultHandler.onComplete(result); - } catch (TException e) { - resultHandler.onError(e); - } - }); + public Future futureStub() { + return null; } - @SuppressWarnings("unchecked") // Generator ignores that AsyncMethodCallback is generic @Override - public void GetWorkflowExecutionHistoryWithTimeout( - GetWorkflowExecutionHistoryRequest getRequest, - AsyncMethodCallback resultHandler, - Long timeoutInMillis) - throws TException { - GetWorkflowExecutionHistory(getRequest, resultHandler); + public ClientOptions getOptions() { + return ClientOptions.defaultInstance(); } @Override public CompletableFuture isHealthy() { - CompletableFuture rval = new CompletableFuture<>(); - rval.complete(Boolean.TRUE); - return rval; - } - - @Override - public void PollForDecisionTask( - PollForDecisionTaskRequest pollRequest, AsyncMethodCallback resultHandler) throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void RespondDecisionTaskCompleted( - RespondDecisionTaskCompletedRequest completeRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void RespondDecisionTaskFailed( - RespondDecisionTaskFailedRequest failedRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void PollForActivityTask( - PollForActivityTaskRequest pollRequest, AsyncMethodCallback resultHandler) throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void RecordActivityTaskHeartbeat( - RecordActivityTaskHeartbeatRequest heartbeatRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void RecordActivityTaskHeartbeatByID( - RecordActivityTaskHeartbeatByIDRequest heartbeatRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void RespondActivityTaskCompleted( - RespondActivityTaskCompletedRequest completeRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void RespondActivityTaskCompletedByID( - RespondActivityTaskCompletedByIDRequest completeRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void RespondActivityTaskFailed( - RespondActivityTaskFailedRequest failRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void RespondActivityTaskFailedByID( - RespondActivityTaskFailedByIDRequest failRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void RespondActivityTaskCanceled( - RespondActivityTaskCanceledRequest canceledRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void RespondActivityTaskCanceledByID( - RespondActivityTaskCanceledByIDRequest canceledRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void RequestCancelWorkflowExecution( - RequestCancelWorkflowExecutionRequest cancelRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void SignalWorkflowExecution( - SignalWorkflowExecutionRequest signalRequest, AsyncMethodCallback resultHandler) - throws TException { - SignalWorkflowExecutionWithTimeout(signalRequest, resultHandler, null); - } - - @Override - public void SignalWorkflowExecutionWithTimeout( - SignalWorkflowExecutionRequest signalRequest, - AsyncMethodCallback resultHandler, - Long timeoutInMillis) - throws TException { - forkJoinPool.execute( - () -> { - try { - SignalWorkflowExecution(signalRequest); - resultHandler.onComplete(null); - } catch (TException e) { - resultHandler.onError(e); - } - }); - } - - @Override - public void SignalWithStartWorkflowExecution( - SignalWithStartWorkflowExecutionRequest signalWithStartRequest, - AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void SignalWithStartWorkflowExecutionAsync( - SignalWithStartWorkflowExecutionAsyncRequest signalWithStartRequest, - AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void ResetWorkflowExecution( - ResetWorkflowExecutionRequest resetRequest, AsyncMethodCallback resultHandler) - throws TException {} - - @Override - public void TerminateWorkflowExecution( - TerminateWorkflowExecutionRequest terminateRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void ListOpenWorkflowExecutions( - ListOpenWorkflowExecutionsRequest listRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void ListClosedWorkflowExecutions( - ListClosedWorkflowExecutionsRequest listRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void ListWorkflowExecutions( - ListWorkflowExecutionsRequest listRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void ListArchivedWorkflowExecutions( - ListArchivedWorkflowExecutionsRequest listRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void ScanWorkflowExecutions( - ListWorkflowExecutionsRequest listRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void CountWorkflowExecutions( - CountWorkflowExecutionsRequest countRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void GetSearchAttributes(AsyncMethodCallback resultHandler) throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void RespondQueryTaskCompleted( - RespondQueryTaskCompletedRequest completeRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void ResetStickyTaskList( - ResetStickyTaskListRequest resetRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void QueryWorkflow(QueryWorkflowRequest queryRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void DescribeWorkflowExecution( - DescribeWorkflowExecutionRequest describeRequest, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void DescribeTaskList(DescribeTaskListRequest request, AsyncMethodCallback resultHandler) - throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void GetClusterInfo(AsyncMethodCallback resultHandler) throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void ListTaskListPartitions( - ListTaskListPartitionsRequest request, AsyncMethodCallback resultHandler) throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - @Override - public void RefreshWorkflowTasks( - RefreshWorkflowTasksRequest request, AsyncMethodCallback resultHandler) throws TException { - throw new UnsupportedOperationException("not implemented"); - } - - private R requireNotNull(String fieldName, R value) throws BadRequestError { - if (value == null) { - throw new BadRequestError("Missing requried field \"" + fieldName + "\"."); - } - return value; - } - - /** - * Adds diagnostic data about internal service state to the provided {@link StringBuilder}. - * Currently includes histories of all workflow instances stored in the service. - */ - public void getDiagnostics(StringBuilder result) { - store.getDiagnostics(result); - } - - public long currentTimeMillis() { - return store.getTimer().getClock().getAsLong(); - } - - /** Invokes callback after the specified delay according to internal service clock. */ - public void registerDelayedCallback(Duration delay, Runnable r) { - store.registerDelayedCallback(delay, r); - } - - /** - * Disables time skipping. To enable back call {@link #unlockTimeSkipping(String)}. These calls - * are counted, so calling unlock does not guarantee that time is going to be skipped immediately - * as another lock can be holding it. - */ - public void lockTimeSkipping(String caller) { - store.getTimer().lockTimeSkipping(caller); - } - - public void unlockTimeSkipping(String caller) { - store.getTimer().unlockTimeSkipping(caller); - } - - /** - * Blocks calling thread until internal clock doesn't pass the current + duration time. Might not - * block at all due to time skipping. - */ - public void sleep(Duration duration) { - CompletableFuture result = new CompletableFuture<>(); - store - .getTimer() - .schedule( - duration, - () -> { - store.getTimer().lockTimeSkipping("TestWorkflowService sleep"); - result.complete(null); - }, - "workflow sleep"); - store.getTimer().unlockTimeSkipping("TestWorkflowService sleep"); - try { - result.get(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } catch (ExecutionException e) { - throw new RuntimeException(e); - } + return null; } } diff --git a/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowStore.java b/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowStore.java index d5672617e..0fd569f16 100644 --- a/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowStore.java +++ b/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowStore.java @@ -17,16 +17,10 @@ package com.uber.cadence.internal.testservice; -import com.uber.cadence.BadRequestError; -import com.uber.cadence.EntityNotExistsError; -import com.uber.cadence.GetWorkflowExecutionHistoryRequest; -import com.uber.cadence.GetWorkflowExecutionHistoryResponse; -import com.uber.cadence.InternalServiceError; -import com.uber.cadence.PollForActivityTaskRequest; -import com.uber.cadence.PollForActivityTaskResponse; -import com.uber.cadence.PollForDecisionTaskRequest; -import com.uber.cadence.PollForDecisionTaskResponse; -import com.uber.cadence.WorkflowExecutionInfo; +import com.uber.cadence.api.v1.*; +import com.uber.cadence.serviceclient.exceptions.BadRequestException; +import com.uber.cadence.serviceclient.exceptions.EntityNotExistsException; +import com.uber.cadence.serviceclient.exceptions.InternalServiceException; import java.time.Duration; import java.util.List; import java.util.Objects; @@ -138,7 +132,7 @@ public PollForActivityTaskResponse getTask() { long currentTimeMillis(); long save(RequestContext requestContext) - throws InternalServiceError, EntityNotExistsError, BadRequestError; + throws InternalServiceException, EntityNotExistsException, BadRequestException; void applyTimersAndLocks(RequestContext ctx); @@ -152,11 +146,11 @@ PollForActivityTaskResponse pollForActivityTask(PollForActivityTaskRequest pollR /** @return queryId */ void sendQueryTask(ExecutionId executionId, TaskListId taskList, PollForDecisionTaskResponse task) - throws EntityNotExistsError; + throws EntityNotExistsException; GetWorkflowExecutionHistoryResponse getWorkflowExecutionHistory( ExecutionId executionId, GetWorkflowExecutionHistoryRequest getRequest) - throws EntityNotExistsError; + throws EntityNotExistsException; void getDiagnostics(StringBuilder result); diff --git a/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowStoreImpl.java b/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowStoreImpl.java index 5759f4562..9fd23a7f6 100644 --- a/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowStoreImpl.java +++ b/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowStoreImpl.java @@ -17,27 +17,16 @@ package com.uber.cadence.internal.testservice; -import com.uber.cadence.BadRequestError; -import com.uber.cadence.DataBlob; -import com.uber.cadence.EntityNotExistsError; -import com.uber.cadence.EventType; -import com.uber.cadence.GetWorkflowExecutionHistoryRequest; -import com.uber.cadence.GetWorkflowExecutionHistoryResponse; -import com.uber.cadence.History; -import com.uber.cadence.HistoryEvent; -import com.uber.cadence.HistoryEventFilterType; -import com.uber.cadence.InternalServiceError; -import com.uber.cadence.PollForActivityTaskRequest; -import com.uber.cadence.PollForActivityTaskResponse; -import com.uber.cadence.PollForDecisionTaskRequest; -import com.uber.cadence.PollForDecisionTaskResponse; -import com.uber.cadence.StickyExecutionAttributes; -import com.uber.cadence.WorkflowExecution; -import com.uber.cadence.WorkflowExecutionInfo; +import com.google.protobuf.Timestamp; +import com.uber.cadence.api.v1.*; import com.uber.cadence.internal.common.InternalUtils; import com.uber.cadence.internal.common.WorkflowExecutionUtils; import com.uber.cadence.internal.testservice.RequestContext.Timer; +import com.uber.cadence.serviceclient.exceptions.BadRequestException; +import com.uber.cadence.serviceclient.exceptions.EntityNotExistsException; +import com.uber.cadence.serviceclient.exceptions.InternalServiceException; import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -81,17 +70,21 @@ private void checkNextEventId(long nextEventId) { } } - void addAllLocked(List events, long timeInNanos) throws EntityNotExistsError { + void addAllLocked(List events, long timeInNanos) throws EntityNotExistsException { for (HistoryEvent event : events) { if (completed) { - throw new EntityNotExistsError( - "Attempt to add an event after a completion event: " - + WorkflowExecutionUtils.prettyPrintHistoryEvent(event)); + throw new EntityNotExistsException( + "Attempt to add an event after a completion event: " + event); // TODO pretty print } - event.setEventId(history.size() + 1L); + HistoryEvent.Builder eventBuilder = event.toBuilder().setEventId(history.size() + 1L); // It can be set in StateMachines.startActivityTask - if (!event.isSetTimestamp()) { - event.setTimestamp(timeInNanos); + if (!eventBuilder.hasEventTime()) { + Instant timestamp = Instant.ofEpochSecond(0, timeInNanos); + eventBuilder.setEventTime( + Timestamp.newBuilder() + .setSeconds(timestamp.getEpochSecond()) + .setNanos(timestamp.getNano()) + .build()); } history.add(event); completed = completed || WorkflowExecutionUtils.isWorkflowExecutionCompletedEvent(event); @@ -107,13 +100,12 @@ List getEventsLocked() { return history; } - List waitForNewEvents( - long expectedNextEventId, HistoryEventFilterType filterType) { + List waitForNewEvents(long expectedNextEventId, EventFilterType filterType) { lock.lock(); try { while (true) { if (completed || getNextEventIdLocked() > expectedNextEventId) { - if (filterType == HistoryEventFilterType.CLOSE_EVENT) { + if (filterType == EventFilterType.EVENT_FILTER_TYPE_CLOSE_EVENT) { if (completed) { List result = new ArrayList<>(1); result.add(history.get(history.size() - 1)); @@ -171,7 +163,7 @@ public long currentTimeMillis() { @Override public long save(RequestContext ctx) - throws InternalServiceError, EntityNotExistsError, BadRequestError { + throws InternalServiceException, EntityNotExistsException, BadRequestException { long result; lock.lock(); boolean historiesEmpty = histories.isEmpty(); @@ -181,7 +173,8 @@ public long save(RequestContext ctx) List events = ctx.getEvents(); if (history == null) { if (events.isEmpty() - || events.get(0).getEventType() != EventType.WorkflowExecutionStarted) { + || events.get(0).getAttributesCase() + == HistoryEvent.AttributesCase.WORKFLOW_EXECUTION_STARTED_EVENT_ATTRIBUTES) { throw new IllegalStateException("No history found for " + executionId); } history = new HistoryStore(executionId, lock); @@ -316,18 +309,16 @@ public PollForActivityTaskResponse pollForActivityTask(PollForActivityTaskReques @Override public void sendQueryTask( ExecutionId executionId, TaskListId taskList, PollForDecisionTaskResponse task) - throws EntityNotExistsError { + throws EntityNotExistsException { lock.lock(); try { HistoryStore historyStore = getHistoryStore(executionId); List events = new ArrayList<>(historyStore.getEventsLocked()); - History history = new History(); + History.Builder history = History.newBuilder(); if (taskList.getTaskListName().equals(task.getWorkflowExecutionTaskList().getName())) { - history.setEvents(events); - } else { - history.setEvents(new ArrayList<>()); + history.addAllEvents(events); } - task.setHistory(history); + task = task.toBuilder().setHistory(history).build(); } finally { lock.unlock(); } @@ -338,22 +329,24 @@ public void sendQueryTask( @Override public GetWorkflowExecutionHistoryResponse getWorkflowExecutionHistory( ExecutionId executionId, GetWorkflowExecutionHistoryRequest getRequest) - throws EntityNotExistsError { + throws EntityNotExistsException { HistoryStore history; // Used to eliminate the race condition on waitForNewEvents long expectedNextEventId; lock.lock(); try { history = getHistoryStore(executionId); - if (!getRequest.isWaitForNewEvent() - && getRequest.getHistoryEventFilterType() != HistoryEventFilterType.CLOSE_EVENT) { + if (!getRequest.getWaitForNewEvent() + && getRequest.getHistoryEventFilterType() + != EventFilterType.EVENT_FILTER_TYPE_CLOSE_EVENT) { List events = history.getEventsLocked(); List blobs = InternalUtils.SerializeFromHistoryEventToBlobData(events); // Copy the list as it is mutable. Individual events assumed immutable. ArrayList eventsCopy = new ArrayList<>(events); - return new GetWorkflowExecutionHistoryResponse() - .setHistory(new History().setEvents(eventsCopy)) - .setRawHistory(blobs); + return GetWorkflowExecutionHistoryResponse.newBuilder() + .setHistory(History.newBuilder().addAllEvents(eventsCopy).build()) + .addAllRawHistory(blobs) + .build(); } expectedNextEventId = history.getNextEventIdLocked(); } finally { @@ -362,19 +355,20 @@ public GetWorkflowExecutionHistoryResponse getWorkflowExecutionHistory( List events = history.waitForNewEvents(expectedNextEventId, getRequest.getHistoryEventFilterType()); List blobs = InternalUtils.SerializeFromHistoryEventToBlobData(events); - GetWorkflowExecutionHistoryResponse result = new GetWorkflowExecutionHistoryResponse(); + GetWorkflowExecutionHistoryResponse.Builder result = + GetWorkflowExecutionHistoryResponse.newBuilder(); if (events != null) { - result.setHistory(new History().setEvents(events)); - result.setRawHistory(blobs); + result.setHistory(History.newBuilder().addAllEvents(events)); + result.addAllRawHistory(blobs); } - return result; + return result.build(); } - private HistoryStore getHistoryStore(ExecutionId executionId) throws EntityNotExistsError { + private HistoryStore getHistoryStore(ExecutionId executionId) throws EntityNotExistsException { HistoryStore result = histories.get(executionId); if (result == null) { WorkflowExecution execution = executionId.getExecution(); - throw new EntityNotExistsError( + throw new EntityNotExistsException( String.format( "Workflow execution result not found. " + "WorkflowId: %s, RunId: %s", execution.getWorkflowId(), execution.getRunId())); @@ -391,9 +385,7 @@ public void getDiagnostics(StringBuilder result) { for (Entry entry : this.histories.entrySet()) { result.append(entry.getKey()); result.append("\n"); - result.append( - WorkflowExecutionUtils.prettyPrintHistory( - entry.getValue().getEventsLocked().iterator(), true)); + result.append(entry.getValue()); // TODO pretty print result.append("\n"); } } @@ -423,20 +415,19 @@ public List listWorkflows( } List history = entry.getValue().getHistory(); WorkflowExecutionInfo info = - new WorkflowExecutionInfo() - .setExecution(executionId.getExecution()) + WorkflowExecutionInfo.newBuilder() + .setWorkflowExecution(executionId.getExecution()) .setHistoryLength(history.size()) - .setStartTime(history.get(0).getTimestamp()) + .setStartTime(history.get(0).getEventTime()) .setIsCron( - history + !history .get(0) .getWorkflowExecutionStartedEventAttributes() - .isSetCronSchedule()) + .getCronSchedule() + .isEmpty()) .setType( - history - .get(0) - .getWorkflowExecutionStartedEventAttributes() - .getWorkflowType()); + history.get(0).getWorkflowExecutionStartedEventAttributes().getWorkflowType()) + .build(); result.add(info); } else { if (!entry.getValue().isCompleted()) { @@ -449,19 +440,21 @@ public List listWorkflows( } List history = entry.getValue().getHistory(); WorkflowExecutionInfo info = - new WorkflowExecutionInfo() - .setExecution(executionId.getExecution()) + WorkflowExecutionInfo.newBuilder() + .setWorkflowExecution(executionId.getExecution()) .setHistoryLength(history.size()) - .setStartTime(history.get(0).getTimestamp()) + .setStartTime(history.get(0).getEventTime()) .setIsCron( - history + !history .get(0) .getWorkflowExecutionStartedEventAttributes() - .isSetCronSchedule()) + .getCronSchedule() + .isEmpty()) .setType( history.get(0).getWorkflowExecutionStartedEventAttributes().getWorkflowType()) .setCloseStatus( - WorkflowExecutionUtils.getCloseStatus(history.get(history.size() - 1))); + WorkflowExecutionUtils.getCloseStatus(history.get(history.size() - 1))) + .build(); result.add(info); } } diff --git a/src/main/java/com/uber/cadence/serviceclient/IWorkflowServiceV4.java b/src/main/java/com/uber/cadence/serviceclient/IWorkflowServiceV4.java index e142eaa10..3b2dcb837 100644 --- a/src/main/java/com/uber/cadence/serviceclient/IWorkflowServiceV4.java +++ b/src/main/java/com/uber/cadence/serviceclient/IWorkflowServiceV4.java @@ -23,8 +23,11 @@ public interface IWorkflowServiceV4 { Blocking blockingStub(); + Future futureStub(); + ClientOptions getOptions(); + CompletableFuture isHealthy(); interface Blocking { @@ -61,7 +64,7 @@ ListWorkflowExecutionsResponse listWorkflowExecutions( ListWorkflowExecutionsRequest request, @Nullable CallMetaData meta); ListArchivedWorkflowExecutionsResponse listArchivedWorkflowExecutions( - ListArchivedWorkflowExecutionsRequest listRequest, @Nullable CallMetaData meta); + ListArchivedWorkflowExecutionsRequest listRequest, @Nullable CallMetaData meta); ScanWorkflowExecutionsResponse scanWorkflowExecutions( ScanWorkflowExecutionsRequest request, @Nullable CallMetaData meta); @@ -108,6 +111,12 @@ RespondDecisionTaskFailedResponse respondDecisionTaskFailed( RespondDecisionTaskCompletedResponse respondDecisionTaskCompleted( RespondDecisionTaskCompletedRequest request, @Nullable CallMetaData meta); + RespondQueryTaskCompletedResponse respondQueryTaskCompleted( + RespondQueryTaskCompletedRequest request, @Nullable CallMetaData meta); + + ResetStickyTaskListResponse resetStickyTaskList( + ResetStickyTaskListRequest resetRequest, @Nullable CallMetaData meta); + RefreshWorkflowTasksResponse refreshWorkflowTasks( RefreshWorkflowTasksRequest request, @Nullable CallMetaData meta); } @@ -158,7 +167,7 @@ CompletableFuture listClosedWorkflowExecut ListClosedWorkflowExecutionsRequest request, @Nullable CallMetaData meta); CompletableFuture listArchivedWorkflowExecutions( - ListArchivedWorkflowExecutionsRequest listRequest, @Nullable CallMetaData meta); + ListArchivedWorkflowExecutionsRequest listRequest, @Nullable CallMetaData meta); CompletableFuture countWorkflowExecutions( CountWorkflowExecutionsRequest request, @Nullable CallMetaData meta); @@ -197,6 +206,6 @@ CompletableFuture respondDecisionTaskCompl RespondDecisionTaskCompletedRequest request, @Nullable CallMetaData meta); CompletableFuture refreshWorkflowTasks( - RefreshWorkflowTasksRequest request, @Nullable CallMetaData meta); + RefreshWorkflowTasksRequest request, @Nullable CallMetaData meta); } } diff --git a/src/main/java/com/uber/cadence/serviceclient/WorkflowServiceGrpc.java b/src/main/java/com/uber/cadence/serviceclient/WorkflowServiceGrpc.java index 122a7dbb7..1f6c361a8 100644 --- a/src/main/java/com/uber/cadence/serviceclient/WorkflowServiceGrpc.java +++ b/src/main/java/com/uber/cadence/serviceclient/WorkflowServiceGrpc.java @@ -25,11 +25,9 @@ import com.uber.cadence.internal.compatibility.proto.ErrorMapper; import com.uber.cadence.internal.compatibility.proto.serviceclient.IGrpcServiceStubs; import com.uber.cadence.serviceclient.exceptions.ServiceClientException; -import com.uber.cadence.workflow.Functions; import io.grpc.*; import java.time.Duration; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; @@ -50,11 +48,10 @@ public ClientOptions getOptions() { public CompletableFuture isHealthy() { return toCompletableFuture( - grpcServiceStubs - .metaFutureStub() - .health(HealthRequest.getDefaultInstance())) - .thenApply(HealthResponse::getOk) - .exceptionally( throwable -> { + grpcServiceStubs.metaFutureStub().health(HealthRequest.getDefaultInstance())) + .thenApply(HealthResponse::getOk) + .exceptionally( + throwable -> { throw toServiceClientException(throwable); }); } @@ -64,12 +61,12 @@ public Blocking blockingStub() { return new Blocking() { @Override public StartWorkflowExecutionResponse startWorkflowExecution( - StartWorkflowExecutionRequest request, @Nullable CallMetaData meta) { + StartWorkflowExecutionRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workflowBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .startWorkflowExecution(request); + return grpcServiceStubs + .workflowBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .startWorkflowExecution(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -77,12 +74,12 @@ public StartWorkflowExecutionResponse startWorkflowExecution( @Override public StartWorkflowExecutionAsyncResponse startWorkflowExecutionAsync( - StartWorkflowExecutionAsyncRequest request, @Nullable CallMetaData meta) { + StartWorkflowExecutionAsyncRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workflowBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .startWorkflowExecutionAsync(request); + return grpcServiceStubs + .workflowBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .startWorkflowExecutionAsync(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -90,12 +87,12 @@ public StartWorkflowExecutionAsyncResponse startWorkflowExecutionAsync( @Override public SignalWorkflowExecutionResponse signalWorkflowExecution( - SignalWorkflowExecutionRequest request, @Nullable CallMetaData meta) { + SignalWorkflowExecutionRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workflowBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .signalWorkflowExecution(request); + return grpcServiceStubs + .workflowBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .signalWorkflowExecution(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -103,12 +100,12 @@ public SignalWorkflowExecutionResponse signalWorkflowExecution( @Override public SignalWithStartWorkflowExecutionResponse signalWithStartWorkflowExecution( - SignalWithStartWorkflowExecutionRequest request, @Nullable CallMetaData meta) { + SignalWithStartWorkflowExecutionRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workflowBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .signalWithStartWorkflowExecution(request); + return grpcServiceStubs + .workflowBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .signalWithStartWorkflowExecution(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -116,12 +113,12 @@ public SignalWithStartWorkflowExecutionResponse signalWithStartWorkflowExecution @Override public SignalWithStartWorkflowExecutionAsyncResponse signalWithStartWorkflowExecutionAsync( - SignalWithStartWorkflowExecutionAsyncRequest request, @Nullable CallMetaData meta) { + SignalWithStartWorkflowExecutionAsyncRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workflowBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .signalWithStartWorkflowExecutionAsync(request); + return grpcServiceStubs + .workflowBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .signalWithStartWorkflowExecutionAsync(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -129,12 +126,12 @@ public SignalWithStartWorkflowExecutionAsyncResponse signalWithStartWorkflowExec @Override public GetWorkflowExecutionHistoryResponse getWorkflowExecutionHistory( - GetWorkflowExecutionHistoryRequest request, @Nullable CallMetaData meta) { + GetWorkflowExecutionHistoryRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workflowBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .getWorkflowExecutionHistory(request); + return grpcServiceStubs + .workflowBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .getWorkflowExecutionHistory(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -142,12 +139,12 @@ public GetWorkflowExecutionHistoryResponse getWorkflowExecutionHistory( @Override public QueryWorkflowResponse queryWorkflow( - QueryWorkflowRequest request, @Nullable CallMetaData meta) { + QueryWorkflowRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workflowBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .queryWorkflow(request); + return grpcServiceStubs + .workflowBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .queryWorkflow(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -155,12 +152,12 @@ public QueryWorkflowResponse queryWorkflow( @Override public RequestCancelWorkflowExecutionResponse requestCancelWorkflowExecution( - RequestCancelWorkflowExecutionRequest request, @Nullable CallMetaData meta) { + RequestCancelWorkflowExecutionRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workflowBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .requestCancelWorkflowExecution(request); + return grpcServiceStubs + .workflowBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .requestCancelWorkflowExecution(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -168,12 +165,12 @@ public RequestCancelWorkflowExecutionResponse requestCancelWorkflowExecution( @Override public TerminateWorkflowExecutionResponse terminateWorkflowExecution( - TerminateWorkflowExecutionRequest request, @Nullable CallMetaData meta) { + TerminateWorkflowExecutionRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workflowBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .terminateWorkflowExecution(request); + return grpcServiceStubs + .workflowBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .terminateWorkflowExecution(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -181,12 +178,12 @@ public TerminateWorkflowExecutionResponse terminateWorkflowExecution( @Override public RestartWorkflowExecutionResponse restartWorkflowExecution( - RestartWorkflowExecutionRequest request, @Nullable CallMetaData meta) { + RestartWorkflowExecutionRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workflowBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .restartWorkflowExecution(request); + return grpcServiceStubs + .workflowBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .restartWorkflowExecution(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -194,24 +191,25 @@ public RestartWorkflowExecutionResponse restartWorkflowExecution( @Override public ListWorkflowExecutionsResponse listWorkflowExecutions( - ListWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { + ListWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .visibilityBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .listWorkflowExecutions(request); + return grpcServiceStubs + .visibilityBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .listWorkflowExecutions(request); } catch (Exception e) { throw toServiceClientException(e); } } @Override - public ListArchivedWorkflowExecutionsResponse listArchivedWorkflowExecutions(ListArchivedWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { + public ListArchivedWorkflowExecutionsResponse listArchivedWorkflowExecutions( + ListArchivedWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .visibilityBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .listArchivedWorkflowExecutions(request); + return grpcServiceStubs + .visibilityBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .listArchivedWorkflowExecutions(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -219,12 +217,12 @@ public ListArchivedWorkflowExecutionsResponse listArchivedWorkflowExecutions(Lis @Override public ScanWorkflowExecutionsResponse scanWorkflowExecutions( - ScanWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { + ScanWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .visibilityBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .scanWorkflowExecutions(request); + return grpcServiceStubs + .visibilityBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .scanWorkflowExecutions(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -232,12 +230,12 @@ public ScanWorkflowExecutionsResponse scanWorkflowExecutions( @Override public ListOpenWorkflowExecutionsResponse listOpenWorkflowExecutions( - ListOpenWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { + ListOpenWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .visibilityBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .listOpenWorkflowExecutions(request); + return grpcServiceStubs + .visibilityBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .listOpenWorkflowExecutions(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -245,12 +243,12 @@ public ListOpenWorkflowExecutionsResponse listOpenWorkflowExecutions( @Override public ListClosedWorkflowExecutionsResponse listClosedWorkflowExecutions( - ListClosedWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { + ListClosedWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .visibilityBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .listClosedWorkflowExecutions(request); + return grpcServiceStubs + .visibilityBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .listClosedWorkflowExecutions(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -258,12 +256,12 @@ public ListClosedWorkflowExecutionsResponse listClosedWorkflowExecutions( @Override public CountWorkflowExecutionsResponse countWorkflowExecutions( - CountWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { + CountWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .visibilityBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .countWorkflowExecutions(request); + return grpcServiceStubs + .visibilityBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .countWorkflowExecutions(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -271,12 +269,12 @@ public CountWorkflowExecutionsResponse countWorkflowExecutions( @Override public PollForActivityTaskResponse pollForActivityTask( - PollForActivityTaskRequest request, @Nullable CallMetaData meta) { + PollForActivityTaskRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workerBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .pollForActivityTask(request); + return grpcServiceStubs + .workerBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .pollForActivityTask(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -284,12 +282,12 @@ public PollForActivityTaskResponse pollForActivityTask( @Override public RecordActivityTaskHeartbeatResponse recordActivityTaskHeartbeat( - RecordActivityTaskHeartbeatRequest request, @Nullable CallMetaData meta) { + RecordActivityTaskHeartbeatRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workerBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .recordActivityTaskHeartbeat(request); + return grpcServiceStubs + .workerBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .recordActivityTaskHeartbeat(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -297,12 +295,12 @@ public RecordActivityTaskHeartbeatResponse recordActivityTaskHeartbeat( @Override public RespondActivityTaskCanceledResponse respondActivityTaskCanceled( - RespondActivityTaskCanceledRequest request, @Nullable CallMetaData meta) { + RespondActivityTaskCanceledRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workerBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .respondActivityTaskCanceled(request); + return grpcServiceStubs + .workerBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .respondActivityTaskCanceled(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -310,12 +308,12 @@ public RespondActivityTaskCanceledResponse respondActivityTaskCanceled( @Override public RespondActivityTaskCanceledByIDResponse respondActivityTaskCanceledByID( - RespondActivityTaskCanceledByIDRequest request, @Nullable CallMetaData meta) { + RespondActivityTaskCanceledByIDRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workerBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .respondActivityTaskCanceledByID(request); + return grpcServiceStubs + .workerBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .respondActivityTaskCanceledByID(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -323,12 +321,12 @@ public RespondActivityTaskCanceledByIDResponse respondActivityTaskCanceledByID( @Override public RespondActivityTaskFailedResponse respondActivityTaskFailed( - RespondActivityTaskFailedRequest request, @Nullable CallMetaData meta) { + RespondActivityTaskFailedRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workerBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .respondActivityTaskFailed(request); + return grpcServiceStubs + .workerBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .respondActivityTaskFailed(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -336,12 +334,12 @@ public RespondActivityTaskFailedResponse respondActivityTaskFailed( @Override public RespondActivityTaskFailedByIDResponse respondActivityTaskFailedByID( - RespondActivityTaskFailedByIDRequest request, @Nullable CallMetaData meta) { + RespondActivityTaskFailedByIDRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workerBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .respondActivityTaskFailedByID(request); + return grpcServiceStubs + .workerBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .respondActivityTaskFailedByID(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -349,12 +347,12 @@ public RespondActivityTaskFailedByIDResponse respondActivityTaskFailedByID( @Override public RespondActivityTaskCompletedResponse respondActivityTaskCompleted( - RespondActivityTaskCompletedRequest request, @Nullable CallMetaData meta) { + RespondActivityTaskCompletedRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workerBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .respondActivityTaskCompleted(request); + return grpcServiceStubs + .workerBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .respondActivityTaskCompleted(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -362,12 +360,12 @@ public RespondActivityTaskCompletedResponse respondActivityTaskCompleted( @Override public RespondActivityTaskCompletedByIDResponse respondActivityTaskCompletedByID( - RespondActivityTaskCompletedByIDRequest request, @Nullable CallMetaData meta) { + RespondActivityTaskCompletedByIDRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workerBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .respondActivityTaskCompletedByID(request); + return grpcServiceStubs + .workerBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .respondActivityTaskCompletedByID(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -375,12 +373,12 @@ public RespondActivityTaskCompletedByIDResponse respondActivityTaskCompletedByID @Override public PollForDecisionTaskResponse pollForDecisionTask( - PollForDecisionTaskRequest request, @Nullable CallMetaData meta) { + PollForDecisionTaskRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workerBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .pollForDecisionTask(request); + return grpcServiceStubs + .workerBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .pollForDecisionTask(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -388,12 +386,12 @@ public PollForDecisionTaskResponse pollForDecisionTask( @Override public RespondDecisionTaskFailedResponse respondDecisionTaskFailed( - RespondDecisionTaskFailedRequest request, @Nullable CallMetaData meta) { + RespondDecisionTaskFailedRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workerBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .respondDecisionTaskFailed(request); + return grpcServiceStubs + .workerBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .respondDecisionTaskFailed(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -401,24 +399,25 @@ public RespondDecisionTaskFailedResponse respondDecisionTaskFailed( @Override public RespondDecisionTaskCompletedResponse respondDecisionTaskCompleted( - RespondDecisionTaskCompletedRequest request, @Nullable CallMetaData meta) { + RespondDecisionTaskCompletedRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workerBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .respondDecisionTaskCompleted(request); + return grpcServiceStubs + .workerBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .respondDecisionTaskCompleted(request); } catch (Exception e) { throw toServiceClientException(e); } } @Override - public RefreshWorkflowTasksResponse refreshWorkflowTasks(RefreshWorkflowTasksRequest request, @Nullable CallMetaData meta) { + public RefreshWorkflowTasksResponse refreshWorkflowTasks( + RefreshWorkflowTasksRequest request, @Nullable CallMetaData meta) { try { - return grpcServiceStubs - .workflowBlockingStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .refreshWorkflowTasks(request); + return grpcServiceStubs + .workflowBlockingStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .refreshWorkflowTasks(request); } catch (Exception e) { throw toServiceClientException(e); } @@ -431,286 +430,289 @@ public Future futureStub() { return new Future() { @Override public CompletableFuture startWorkflowExecution( - StartWorkflowExecutionRequest request, @Nullable CallMetaData meta) { + StartWorkflowExecutionRequest request, @Nullable CallMetaData meta) { return toCompletableFuture( - grpcServiceStubs - .workflowFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .startWorkflowExecution(request)); + grpcServiceStubs + .workflowFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .startWorkflowExecution(request)); } @Override public CompletableFuture startWorkflowExecutionAsync( - StartWorkflowExecutionAsyncRequest request, @Nullable CallMetaData meta) { + StartWorkflowExecutionAsyncRequest request, @Nullable CallMetaData meta) { return toCompletableFuture( - grpcServiceStubs - .workflowFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .startWorkflowExecutionAsync(request)); + grpcServiceStubs + .workflowFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .startWorkflowExecutionAsync(request)); } @Override public CompletableFuture signalWorkflowExecution( - SignalWorkflowExecutionRequest request, @Nullable CallMetaData meta) { + SignalWorkflowExecutionRequest request, @Nullable CallMetaData meta) { return toCompletableFuture( - grpcServiceStubs - .workflowFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .signalWorkflowExecution(request)); + grpcServiceStubs + .workflowFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .signalWorkflowExecution(request)); } @Override public CompletableFuture - signalWithStartWorkflowExecution( + signalWithStartWorkflowExecution( SignalWithStartWorkflowExecutionRequest request, @Nullable CallMetaData meta) { return toCompletableFuture( - grpcServiceStubs - .workflowFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .signalWithStartWorkflowExecution(request)); + grpcServiceStubs + .workflowFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .signalWithStartWorkflowExecution(request)); } @Override public CompletableFuture - signalWithStartWorkflowExecutionAsync( + signalWithStartWorkflowExecutionAsync( SignalWithStartWorkflowExecutionAsyncRequest request, @Nullable CallMetaData meta) { return toCompletableFuture( - grpcServiceStubs - .workflowFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .signalWithStartWorkflowExecutionAsync(request)); + grpcServiceStubs + .workflowFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .signalWithStartWorkflowExecutionAsync(request)); } @Override public CompletableFuture getWorkflowExecutionHistory( - GetWorkflowExecutionHistoryRequest request, @Nullable CallMetaData meta) { + GetWorkflowExecutionHistoryRequest request, @Nullable CallMetaData meta) { return toCompletableFuture( - grpcServiceStubs - .workflowFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .getWorkflowExecutionHistory(request)); + grpcServiceStubs + .workflowFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .getWorkflowExecutionHistory(request)); } @Override public CompletableFuture queryWorkflow( - QueryWorkflowRequest request, @Nullable CallMetaData meta) { + QueryWorkflowRequest request, @Nullable CallMetaData meta) { return toCompletableFuture( - grpcServiceStubs - .workflowFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .queryWorkflow(request)); + grpcServiceStubs + .workflowFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .queryWorkflow(request)); } @Override public CompletableFuture - requestCancelWorkflowExecution( + requestCancelWorkflowExecution( RequestCancelWorkflowExecutionRequest request, @Nullable CallMetaData meta) { return toCompletableFuture( - grpcServiceStubs - .workflowFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .requestCancelWorkflowExecution(request)); + grpcServiceStubs + .workflowFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .requestCancelWorkflowExecution(request)); } @Override public CompletableFuture terminateWorkflowExecution( - TerminateWorkflowExecutionRequest request, @Nullable CallMetaData meta) { + TerminateWorkflowExecutionRequest request, @Nullable CallMetaData meta) { return toCompletableFuture( - grpcServiceStubs - .workflowFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .terminateWorkflowExecution(request)); + grpcServiceStubs + .workflowFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .terminateWorkflowExecution(request)); } @Override public CompletableFuture restartWorkflowExecution( - RestartWorkflowExecutionRequest request, @Nullable CallMetaData meta) { + RestartWorkflowExecutionRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .workflowFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .restartWorkflowExecution(request)); + } + + @Override + public CompletableFuture listWorkflowExecutions( + ListWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .visibilityFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .listWorkflowExecutions(request)); + } + + @Override + public CompletableFuture scanWorkflowExecutions( + ScanWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .visibilityFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .scanWorkflowExecutions(request)); + } + + @Override + public CompletableFuture listOpenWorkflowExecutions( + ListOpenWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .visibilityFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .listOpenWorkflowExecutions(request)); + } + + @Override + public CompletableFuture listClosedWorkflowExecutions( + ListClosedWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .visibilityFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .listClosedWorkflowExecutions(request)); + } + + @Override + public CompletableFuture + listArchivedWorkflowExecutions( + ListArchivedWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .visibilityFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .listArchivedWorkflowExecutions(request)); + } + + @Override + public CompletableFuture countWorkflowExecutions( + CountWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .visibilityFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .countWorkflowExecutions(request)); + } + + @Override + public CompletableFuture pollForActivityTask( + PollForActivityTaskRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .workerFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .pollForActivityTask(request)); + } + + @Override + public CompletableFuture recordActivityTaskHeartbeat( + RecordActivityTaskHeartbeatRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .workerFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .recordActivityTaskHeartbeat(request)); + } + + @Override + public CompletableFuture respondActivityTaskCanceled( + RespondActivityTaskCanceledRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .workerFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .respondActivityTaskCanceled(request)); + } + + @Override + public CompletableFuture + respondActivityTaskCanceledByID( + RespondActivityTaskCanceledByIDRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .workerFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .respondActivityTaskCanceledByID(request)); + } + + @Override + public CompletableFuture respondActivityTaskFailed( + RespondActivityTaskFailedRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .workerFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .respondActivityTaskFailed(request)); + } + + @Override + public CompletableFuture respondActivityTaskFailedByID( + RespondActivityTaskFailedByIDRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .workerFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .respondActivityTaskFailedByID(request)); + } + + @Override + public CompletableFuture respondActivityTaskCompleted( + RespondActivityTaskCompletedRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .workerFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .respondActivityTaskCompleted(request)); + } + + @Override + public CompletableFuture + respondActivityTaskCompletedByID( + RespondActivityTaskCompletedByIDRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .workerFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .respondActivityTaskCompletedByID(request)); + } + + @Override + public CompletableFuture pollForDecisionTask( + PollForDecisionTaskRequest request, @Nullable CallMetaData meta) { return toCompletableFuture( - grpcServiceStubs - .workflowFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .restartWorkflowExecution(request)); - } - - @Override - public CompletableFuture listWorkflowExecutions( - ListWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .visibilityFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .listWorkflowExecutions(request)); - } - - @Override - public CompletableFuture scanWorkflowExecutions( - ScanWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .visibilityFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .scanWorkflowExecutions(request)); - } - - @Override - public CompletableFuture listOpenWorkflowExecutions( - ListOpenWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .visibilityFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .listOpenWorkflowExecutions(request)); - } - - @Override - public CompletableFuture listClosedWorkflowExecutions( - ListClosedWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .visibilityFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .listClosedWorkflowExecutions(request)); - } - - @Override - public CompletableFuture listArchivedWorkflowExecutions( - ListArchivedWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .visibilityFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .listArchivedWorkflowExecutions(request)); - } - - @Override - public CompletableFuture countWorkflowExecutions( - CountWorkflowExecutionsRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .visibilityFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .countWorkflowExecutions(request)); - } - - @Override - public CompletableFuture pollForActivityTask( - PollForActivityTaskRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .workerFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .pollForActivityTask(request)); - } - - @Override - public CompletableFuture recordActivityTaskHeartbeat( - RecordActivityTaskHeartbeatRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .workerFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .recordActivityTaskHeartbeat(request)); - } - - @Override - public CompletableFuture respondActivityTaskCanceled( - RespondActivityTaskCanceledRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .workerFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .respondActivityTaskCanceled(request)); - } - - @Override - public CompletableFuture respondActivityTaskCanceledByID( - RespondActivityTaskCanceledByIDRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .workerFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .respondActivityTaskCanceledByID(request)); - } - - @Override - public CompletableFuture respondActivityTaskFailed( - RespondActivityTaskFailedRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .workerFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .respondActivityTaskFailed(request)); - } - - @Override - public CompletableFuture respondActivityTaskFailedByID( - RespondActivityTaskFailedByIDRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .workerFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .respondActivityTaskFailedByID(request)); - } - - @Override - public CompletableFuture respondActivityTaskCompleted( - RespondActivityTaskCompletedRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .workerFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .respondActivityTaskCompleted(request)); - } - - @Override - public CompletableFuture respondActivityTaskCompletedByID( - RespondActivityTaskCompletedByIDRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .workerFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .respondActivityTaskCompletedByID(request)); - } - - @Override - public CompletableFuture pollForDecisionTask( - PollForDecisionTaskRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .workerFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .pollForDecisionTask(request)); - } - - @Override - public CompletableFuture respondDecisionTaskFailed( - RespondDecisionTaskFailedRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .workerFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .respondDecisionTaskFailed(request)); - } - - @Override - public CompletableFuture respondDecisionTaskCompleted( - RespondDecisionTaskCompletedRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .workerFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .respondDecisionTaskCompleted(request)); - } - - @Override - public CompletableFuture refreshWorkflowTasks( - RefreshWorkflowTasksRequest request, @Nullable CallMetaData meta) { - return toCompletableFuture( - grpcServiceStubs - .workflowFutureStub() - .withInterceptors(new CallMetadataClientInterceptor(meta)) - .refreshWorkflowTasks(request)); - } + grpcServiceStubs + .workerFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .pollForDecisionTask(request)); + } + + @Override + public CompletableFuture respondDecisionTaskFailed( + RespondDecisionTaskFailedRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .workerFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .respondDecisionTaskFailed(request)); + } + + @Override + public CompletableFuture respondDecisionTaskCompleted( + RespondDecisionTaskCompletedRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .workerFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .respondDecisionTaskCompleted(request)); + } + + @Override + public CompletableFuture refreshWorkflowTasks( + RefreshWorkflowTasksRequest request, @Nullable CallMetaData meta) { + return toCompletableFuture( + grpcServiceStubs + .workflowFutureStub() + .withInterceptors(new CallMetadataClientInterceptor(meta)) + .refreshWorkflowTasks(request)); + } }; } diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/BadRequestException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/BadRequestException.java new file mode 100644 index 000000000..2c2602ad8 --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/BadRequestException.java @@ -0,0 +1,28 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.uber.cadence.serviceclient.exceptions; + +public class BadRequestException extends ServiceClientException { + public BadRequestException(String message) { + super(message); + } + + public BadRequestException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/EntityNotExistsException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/EntityNotExistsException.java index 9553a0d8e..8b472d209 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/EntityNotExistsException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/EntityNotExistsException.java @@ -18,8 +18,31 @@ package com.uber.cadence.serviceclient.exceptions; public class EntityNotExistsException extends ServiceClientException { + private final String currentCluster; + private final String activeCluster; public EntityNotExistsException(Throwable cause) { super(cause); + currentCluster = null; + activeCluster = null; + } + + public EntityNotExistsException(String message) { + super(message); + currentCluster = null; + activeCluster = null; + } + + public EntityNotExistsException(String currentCluster, String activeCluster) { + this.currentCluster = currentCluster; + this.activeCluster = activeCluster; + } + + public String getCurrentCluster() { + return currentCluster; + } + + public String getActiveCluster() { + return activeCluster; } } diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalServiceException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalServiceException.java index 17915be6b..f52fd4d01 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalServiceException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalServiceException.java @@ -18,6 +18,10 @@ package com.uber.cadence.serviceclient.exceptions; public class InternalServiceException extends ServiceClientException { + public InternalServiceException(String message) { + super(message); + } + public InternalServiceException(Throwable cause) { super(cause); } diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/QueryFailedException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/QueryFailedException.java new file mode 100644 index 000000000..ace351c6a --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/QueryFailedException.java @@ -0,0 +1,25 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.uber.cadence.serviceclient.exceptions; + +public class QueryFailedException extends ServiceClientException { + + public QueryFailedException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceClientException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceClientException.java index f28de9469..87ea7fd3d 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceClientException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceClientException.java @@ -27,6 +27,10 @@ public class ServiceClientException extends RuntimeException { super(); } + public ServiceClientException(String message) { + super(message); + } + public ServiceClientException(String message, Throwable cause) { super(message, cause); } diff --git a/src/test/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateAttrUtil_validateScheduleActivityTaskTest.java b/src/test/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateAttrUtil_validateScheduleActivityTaskTest.java index 2156979fc..bda208c26 100644 --- a/src/test/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateAttrUtil_validateScheduleActivityTaskTest.java +++ b/src/test/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateAttrUtil_validateScheduleActivityTaskTest.java @@ -19,9 +19,10 @@ package com.uber.cadence.internal.testservice; -import com.uber.cadence.ActivityType; -import com.uber.cadence.ScheduleActivityTaskDecisionAttributes; -import com.uber.cadence.TaskList; +import com.google.protobuf.Duration; +import com.uber.cadence.api.v1.ActivityType; +import com.uber.cadence.api.v1.ScheduleActivityTaskDecisionAttributes; +import com.uber.cadence.api.v1.TaskList; import java.util.Arrays; import java.util.Collection; import junit.framework.TestCase; @@ -47,10 +48,10 @@ public static Collection data() { new Object[][] { {"valid", createAtt(), null}, {"null", null, "ScheduleActivityTaskDecisionAttributes is not set on decision."}, - {"task list null", createAtt().setTaskList(null), "TaskList is not set on decision."}, + {"task list null", createAtt().clearTaskList(), "TaskList is not set on decision."}, { "task list no name", - createAtt().setTaskList(new TaskList().setName("")), + createAtt().setTaskList(TaskList.newBuilder().setName("")), "TaskList is not set on decision." }, { @@ -63,37 +64,37 @@ public static Collection data() { }, { "activity type null", - createAtt().setActivityType(null), + createAtt().clearActivityType(), "ActivityType is not set on decision." }, { "activity type name null", - createAtt().setActivityType(new ActivityType().setName(null)), + createAtt().setActivityType(ActivityType.newBuilder()), "ActivityType is not set on decision." }, { "activity type name empty", - createAtt().setActivityType(new ActivityType().setName("")), + createAtt().setActivityType(ActivityType.newBuilder().setName("")), "ActivityType is not set on decision." }, { "start to close <= 0", - createAtt().setStartToCloseTimeoutSeconds(0), + createAtt().setStartToCloseTimeout(Duration.newBuilder().setSeconds(0)), "A valid StartToCloseTimeoutSeconds is not set on decision." }, { "schedule to start <= 0", - createAtt().setScheduleToStartTimeoutSeconds(0), + createAtt().setScheduleToStartTimeout(Duration.newBuilder().setSeconds(0)), "A valid ScheduleToStartTimeoutSeconds is not set on decision." }, { "schedule to close <= 0", - createAtt().setScheduleToCloseTimeoutSeconds(0), + createAtt().setScheduleToCloseTimeout(Duration.newBuilder().setSeconds(0)), "A valid ScheduleToCloseTimeoutSeconds is not set on decision." }, { "heartbeat < 0", - createAtt().setHeartbeatTimeoutSeconds(-1), + createAtt().setHeartbeatTimeout(Duration.newBuilder().setSeconds(-1)), "Ac valid HeartbeatTimeoutSeconds is not set on decision." }, }); @@ -111,14 +112,14 @@ public void testValidateScheduleActivityTask() { } } - private static ScheduleActivityTaskDecisionAttributes createAtt() { - return new ScheduleActivityTaskDecisionAttributes() - .setTaskList(new TaskList().setName("testTaskList")) + private static ScheduleActivityTaskDecisionAttributes.Builder createAtt() { + return ScheduleActivityTaskDecisionAttributes.newBuilder() + .setTaskList(TaskList.newBuilder().setName("testTaskList")) .setActivityId("testActivityId") - .setActivityType(new ActivityType().setName("testActivityType")) - .setStartToCloseTimeoutSeconds(12) - .setScheduleToStartTimeoutSeconds(34) - .setScheduleToCloseTimeoutSeconds(45) - .setHeartbeatTimeoutSeconds(78); + .setActivityType(ActivityType.newBuilder().setName("testActivityType")) + .setStartToCloseTimeout(Duration.newBuilder().setSeconds(12)) + .setScheduleToStartTimeout(Duration.newBuilder().setSeconds(34)) + .setScheduleToCloseTimeout(Duration.newBuilder().setSeconds(45)) + .setHeartbeatTimeout(Duration.newBuilder().setSeconds(78)); } } diff --git a/src/test/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateAttrUtil_validateStartChildExecutionAttributes.java b/src/test/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateAttrUtil_validateStartChildExecutionAttributes.java index 43776b1be..8a5ee95cd 100644 --- a/src/test/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateAttrUtil_validateStartChildExecutionAttributes.java +++ b/src/test/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateAttrUtil_validateStartChildExecutionAttributes.java @@ -21,7 +21,8 @@ import static com.uber.cadence.internal.testservice.TestWorkflowMutableStateAttrUtil.inheritUnsetPropertiesFromParentWorkflow; -import com.uber.cadence.*; +import com.google.protobuf.Duration; +import com.uber.cadence.api.v1.*; import java.util.Arrays; import java.util.Collection; import junit.framework.TestCase; @@ -51,7 +52,7 @@ public static Collection data() { {"all set", createAtt(), createAtt()}, { "empty", - new StartChildWorkflowExecutionDecisionAttributes(), + StartChildWorkflowExecutionDecisionAttributes.getDefaultInstance(), createAtt() .setTaskList(new TaskList().setName("testTaskListFromParent")) .setExecutionStartToCloseTimeoutSeconds(21) @@ -60,7 +61,7 @@ public static Collection data() { { "taskList null", createAtt().setTaskList(null), - createAtt().setTaskList(new TaskList().setName("testTaskListFromParent")) + createAtt().setTaskList(TaskList.newBuilder().setName("testTaskListFromParent").build()) }, { "taskList name empty", @@ -83,19 +84,20 @@ public static Collection data() { @Test public void testValidateScheduleActivityTask() { StartWorkflowExecutionRequest startRequest = - new StartWorkflowExecutionRequest() - .setTaskList(new TaskList().setName("testTaskListFromParent")) - .setExecutionStartToCloseTimeoutSeconds(21) - .setTaskStartToCloseTimeoutSeconds(22); + StartWorkflowExecutionRequest.newBuilder() + .setTaskList(TaskList.newBuilder().setName("testTaskListFromParent")) + .setExecutionStartToCloseTimeout(Duration.newBuilder().setSeconds(21)) + .setTaskStartToCloseTimeout(Duration.newBuilder().setSeconds(22)) + .build(); - inheritUnsetPropertiesFromParentWorkflow(startRequest, attributes); + attributes = inheritUnsetPropertiesFromParentWorkflow(startRequest, attributes); assertEquals(expectedAttributes, attributes); } - private static StartChildWorkflowExecutionDecisionAttributes createAtt() { - return new StartChildWorkflowExecutionDecisionAttributes() - .setTaskList(new TaskList().setName("testTaskList")) - .setExecutionStartToCloseTimeoutSeconds(11) - .setTaskStartToCloseTimeoutSeconds(12); + private static StartChildWorkflowExecutionDecisionAttributes.Builder createAtt() { + return StartChildWorkflowExecutionDecisionAttributes.newBuilder() + .setTaskList(TaskList.newBuilder().setName("testTaskList")) + .setExecutionStartToCloseTimeout(Duration.newBuilder().setSeconds(11)) + .setTaskStartToCloseTimeout(Duration.newBuilder().setSeconds(12)); } }