From 52c42d0bbe105f17259fe431f37d86fa610c3c91 Mon Sep 17 00:00:00 2001 From: Nate Mortensen Date: Wed, 23 Oct 2024 16:42:17 -0700 Subject: [PATCH] Add tests for HistoryMapper event attributes conversions --- .../internal/compatibility/ProtoObjects.java | 474 +++++++++++++++++- .../internal/compatibility/ThriftObjects.java | 410 ++++++++++++++- .../thrift/HistoryMapperEventTest.java | 325 ++++++++++++ 3 files changed, 1207 insertions(+), 2 deletions(-) create mode 100644 src/test/java/com/uber/cadence/internal/compatibility/thrift/HistoryMapperEventTest.java diff --git a/src/test/java/com/uber/cadence/internal/compatibility/ProtoObjects.java b/src/test/java/com/uber/cadence/internal/compatibility/ProtoObjects.java index 3c029b8e7..b8391e794 100644 --- a/src/test/java/com/uber/cadence/internal/compatibility/ProtoObjects.java +++ b/src/test/java/com/uber/cadence/internal/compatibility/ProtoObjects.java @@ -44,8 +44,15 @@ public final class ProtoObjects { .addNonRetryableErrorReasons("error") .setExpirationInterval(seconds(14)) .build(); + public static final String WORKFLOW_ID = "workflowId"; public static final WorkflowExecution WORKFLOW_EXECUTION = WorkflowExecution.newBuilder().setWorkflowId("workflowId").setRunId("runId").build(); + public static final WorkflowExecution PARENT_WORKFLOW_EXECUTION = + WorkflowExecution.newBuilder() + .setWorkflowId("parentWorkflowId") + .setRunId("parentRunId") + .build(); + public static final Failure FAILURE = Failure.newBuilder().setDetails(utf8("details")).setReason("reason").build(); public static final StickyExecutionAttributes STICKY_EXECUTION_ATTRIBUTES = @@ -70,7 +77,17 @@ public final class ProtoObjects { public static final SearchAttributes SEARCH_ATTRIBUTES = SearchAttributes.newBuilder().putIndexedFields("search", payload("attributes")).build(); public static final Map DATA = ImmutableMap.of("dataKey", "dataValue"); - + public static final ResetPointInfo RESET_POINT_INFO = + ResetPointInfo.newBuilder() + .setBinaryChecksum("binaryChecksum") + .setRunId("runId") + .setCreatedTime(timestampNanos(1)) + .setResettable(true) + .setExpiringTime(timestampNanos(2)) + .setFirstDecisionCompletedId(3) + .build(); + public static final ResetPoints RESET_POINTS = + ResetPoints.newBuilder().addPoints(RESET_POINT_INFO).build(); public static final ClusterReplicationConfiguration CLUSTER_REPLICATION_CONFIGURATION = ClusterReplicationConfiguration.newBuilder().setClusterName("cluster").build(); @@ -197,6 +214,461 @@ public final class ProtoObjects { .setDetails(payload("details")) .setHeader(HEADER)) .build(); + + public static final WorkflowExecutionStartedEventAttributes + WORKFLOW_EXECUTION_STARTED_EVENT_ATTRIBUTES = + WorkflowExecutionStartedEventAttributes.newBuilder() + .setWorkflowType(WORKFLOW_TYPE) + .setParentExecutionInfo( + ParentExecutionInfo.newBuilder() + .setDomainName("parentDomainName") + .setWorkflowExecution(PARENT_WORKFLOW_EXECUTION) + .setInitiatedId(1) + .build()) + .setTaskList(TASK_LIST) + .setInput(payload("input")) + .setExecutionStartToCloseTimeout(seconds(2)) + .setTaskStartToCloseTimeout(seconds(3)) + .setContinuedExecutionRunId("continuedExecutionRunId") + .setInitiator(ContinueAsNewInitiator.CONTINUE_AS_NEW_INITIATOR_RETRY_POLICY) + .setContinuedFailure( + Failure.newBuilder() + .setReason("continuedFailureReason") + .setDetails(utf8("continuedFailureDetails")) + .build()) + .setLastCompletionResult(payload("lastCompletionResult")) + .setOriginalExecutionRunId("originalExecutionRunId") + .setIdentity("identity") + .setFirstExecutionRunId("firstExecutionRunId") + .setRetryPolicy(RETRY_POLICY) + .setAttempt(4) + .setExpirationTime(timestampNanos(5)) + .setCronSchedule("cronSchedule") + .setFirstDecisionTaskBackoff(seconds(6)) + .setMemo(MEMO) + .setSearchAttributes(SEARCH_ATTRIBUTES) + .setPrevAutoResetPoints(RESET_POINTS) + .setHeader(HEADER) + .build(); + + public static final WorkflowExecutionCompletedEventAttributes + WORKFLOW_EXECUTION_COMPLETED_EVENT_ATTRIBUTES = + WorkflowExecutionCompletedEventAttributes.newBuilder() + .setResult(payload("result")) + .setDecisionTaskCompletedEventId(1) + .build(); + + public static final WorkflowExecutionFailedEventAttributes + WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES = + WorkflowExecutionFailedEventAttributes.newBuilder() + .setFailure(FAILURE) + .setDecisionTaskCompletedEventId(1) + .build(); + + public static final WorkflowExecutionTimedOutEventAttributes + WORKFLOW_EXECUTION_TIMED_OUT_EVENT_ATTRIBUTES = + WorkflowExecutionTimedOutEventAttributes.newBuilder() + .setTimeoutType(TimeoutType.TIMEOUT_TYPE_SCHEDULE_TO_CLOSE) + .build(); + + public static final DecisionTaskScheduledEventAttributes + DECISION_TASK_SCHEDULED_EVENT_ATTRIBUTES = + DecisionTaskScheduledEventAttributes.newBuilder() + .setTaskList(TASK_LIST) + .setStartToCloseTimeout(seconds(1)) + .setAttempt(2) + .build(); + + public static final DecisionTaskStartedEventAttributes DECISION_TASK_STARTED_EVENT_ATTRIBUTES = + DecisionTaskStartedEventAttributes.newBuilder() + .setScheduledEventId(1) + .setIdentity("identity") + .setRequestId("requestId") + .build(); + + public static final DecisionTaskCompletedEventAttributes + DECISION_TASK_COMPLETED_EVENT_ATTRIBUTES = + DecisionTaskCompletedEventAttributes.newBuilder() + .setScheduledEventId(1) + .setStartedEventId(2) + .setIdentity("identity") + .setBinaryChecksum("binaryChecksum") + .setExecutionContext(utf8("executionContext")) + .build(); + + public static final DecisionTaskTimedOutEventAttributes DECISION_TASK_TIMED_OUT_EVENT_ATTRIBUTES = + DecisionTaskTimedOutEventAttributes.newBuilder() + .setScheduledEventId(1) + .setStartedEventId(2) + .setTimeoutType(TimeoutType.TIMEOUT_TYPE_SCHEDULE_TO_CLOSE) + .setBaseRunId("baseRunId") + .setNewRunId("newRunId") + .setForkEventVersion(3) + .setReason("reason") + .setCause(DecisionTaskTimedOutCause.DECISION_TASK_TIMED_OUT_CAUSE_RESET) + .build(); + + public static final DecisionTaskFailedEventAttributes DECISION_TASK_FAILED_EVENT_ATTRIBUTES = + DecisionTaskFailedEventAttributes.newBuilder() + .setScheduledEventId(1) + .setStartedEventId(2) + .setCause(DecisionTaskFailedCause.DECISION_TASK_FAILED_CAUSE_BAD_BINARY) + .setFailure(FAILURE) + .setIdentity("identity") + .setBaseRunId("baseRun") + .setNewRunId("newRun") + .setForkEventVersion(3) + .setBinaryChecksum("binaryChecksum") + .build(); + + public static final ActivityTaskScheduledEventAttributes + ACTIVITY_TASK_SCHEDULED_EVENT_ATTRIBUTES = + ActivityTaskScheduledEventAttributes.newBuilder() + .setActivityId("activityId") + .setActivityType(ACTIVITY_TYPE) + .setDomain("domain") + .setTaskList(TASK_LIST) + .setInput(payload("input")) + .setScheduleToCloseTimeout(seconds(1)) + .setScheduleToStartTimeout(seconds(2)) + .setStartToCloseTimeout(seconds(3)) + .setHeartbeatTimeout(seconds(4)) + .setDecisionTaskCompletedEventId(5) + .setRetryPolicy(RETRY_POLICY) + .setHeader(HEADER) + .build(); + + public static final ActivityTaskStartedEventAttributes ACTIVITY_TASK_STARTED_EVENT_ATTRIBUTES = + ActivityTaskStartedEventAttributes.newBuilder() + .setScheduledEventId(1) + .setIdentity("identity") + .setRequestId("requestId") + .setAttempt(2) + .setLastFailure( + Failure.newBuilder() + .setReason("failureReason") + .setDetails(utf8("failureDetails")) + .build()) + .build(); + + public static final ActivityTaskCompletedEventAttributes + ACTIVITY_TASK_COMPLETED_EVENT_ATTRIBUTES = + ActivityTaskCompletedEventAttributes.newBuilder() + .setResult(payload("result")) + .setScheduledEventId(1) + .setStartedEventId(2) + .setIdentity("identity") + .build(); + + public static final ActivityTaskFailedEventAttributes ACTIVITY_TASK_FAILED_EVENT_ATTRIBUTES = + ActivityTaskFailedEventAttributes.newBuilder() + .setFailure(FAILURE) + .setScheduledEventId(1) + .setStartedEventId(2) + .setIdentity("identity") + .build(); + + public static final ActivityTaskTimedOutEventAttributes ACTIVITY_TASK_TIMED_OUT_EVENT_ATTRIBUTES = + ActivityTaskTimedOutEventAttributes.newBuilder() + .setDetails(payload("details")) + .setScheduledEventId(1) + .setStartedEventId(2) + .setTimeoutType(TimeoutType.TIMEOUT_TYPE_SCHEDULE_TO_CLOSE) + .setLastFailure( + Failure.newBuilder() + .setReason("failureReason") + .setDetails(utf8("failureDetails")) + .build()) + .build(); + + public static final ActivityTaskCancelRequestedEventAttributes + ACTIVITY_TASK_CANCEL_REQUESTED_EVENT_ATTRIBUTES = + ActivityTaskCancelRequestedEventAttributes.newBuilder() + .setActivityId("activityId") + .setDecisionTaskCompletedEventId(1) + .build(); + + public static final ActivityTaskCanceledEventAttributes ACTIVITY_TASK_CANCELED_EVENT_ATTRIBUTES = + ActivityTaskCanceledEventAttributes.newBuilder() + .setDetails(payload("details")) + .setLatestCancelRequestedEventId(1) + .setScheduledEventId(2) + .setStartedEventId(3) + .setIdentity("identity") + .build(); + + public static final RequestCancelActivityTaskFailedEventAttributes + REQUEST_CANCEL_ACTIVITY_TASK_FAILED_EVENT_ATTRIBUTES = + RequestCancelActivityTaskFailedEventAttributes.newBuilder() + .setActivityId("activityId") + .setCause("cause") + .setDecisionTaskCompletedEventId(1) + .build(); + + public static final MarkerRecordedEventAttributes MARKER_RECORDED_EVENT_ATTRIBUTES = + MarkerRecordedEventAttributes.newBuilder() + .setMarkerName("markerName") + .setDetails(payload("details")) + .setDecisionTaskCompletedEventId(1) + .setHeader(HEADER) + .build(); + + public static final TimerCanceledEventAttributes TIMER_CANCELED_EVENT_ATTRIBUTES = + TimerCanceledEventAttributes.newBuilder() + .setTimerId("timerId") + .setStartedEventId(1) + .setDecisionTaskCompletedEventId(2) + .setIdentity("identity") + .build(); + + public static final CancelTimerFailedEventAttributes CANCEL_TIMER_FAILED_EVENT_ATTRIBUTES = + CancelTimerFailedEventAttributes.newBuilder() + .setTimerId("timerId") + .setCause("cause") + .setDecisionTaskCompletedEventId(1) + .setIdentity("identity") + .build(); + + public static final TimerFiredEventAttributes TIMER_FIRED_EVENT_ATTRIBUTES = + TimerFiredEventAttributes.newBuilder().setTimerId("timerId").setStartedEventId(1).build(); + + public static final TimerStartedEventAttributes TIMER_STARTED_EVENT_ATTRIBUTES = + TimerStartedEventAttributes.newBuilder() + .setTimerId("timerId") + .setStartToFireTimeout(seconds(1)) + .setDecisionTaskCompletedEventId(2) + .build(); + + public static final UpsertWorkflowSearchAttributesEventAttributes + UPSERT_WORKFLOW_SEARCH_ATTRIBUTES_EVENT_ATTRIBUTES = + UpsertWorkflowSearchAttributesEventAttributes.newBuilder() + .setDecisionTaskCompletedEventId(1) + .setSearchAttributes(SEARCH_ATTRIBUTES) + .build(); + + public static final StartChildWorkflowExecutionInitiatedEventAttributes + START_CHILD_WORKFLOW_EXECUTION_INITIATED_EVENT_ATTRIBUTES = + StartChildWorkflowExecutionInitiatedEventAttributes.newBuilder() + .setDomain("domain") + .setWorkflowId(WORKFLOW_ID) + .setWorkflowType(WORKFLOW_TYPE) + .setTaskList(TASK_LIST) + .setInput(payload("input")) + .setExecutionStartToCloseTimeout(seconds(1)) + .setTaskStartToCloseTimeout(seconds(2)) + .setParentClosePolicy(ParentClosePolicy.PARENT_CLOSE_POLICY_REQUEST_CANCEL) + .setControl(utf8("control")) + .setDecisionTaskCompletedEventId(3) + .setWorkflowIdReusePolicy( + WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE) + .setRetryPolicy(RETRY_POLICY) + .setCronSchedule("cron") + .setHeader(HEADER) + .setMemo(MEMO) + .setSearchAttributes(SEARCH_ATTRIBUTES) + .setDelayStart(seconds(4)) + .build(); + + public static final StartChildWorkflowExecutionFailedEventAttributes + START_CHILD_WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES = + StartChildWorkflowExecutionFailedEventAttributes.newBuilder() + .setDomain("domain") + .setWorkflowId(WORKFLOW_ID) + .setWorkflowType(WORKFLOW_TYPE) + .setCause( + ChildWorkflowExecutionFailedCause + .CHILD_WORKFLOW_EXECUTION_FAILED_CAUSE_WORKFLOW_ALREADY_RUNNING) + .setControl(utf8("control")) + .setInitiatedEventId(1) + .setDecisionTaskCompletedEventId(2) + .build(); + + public static final ChildWorkflowExecutionCanceledEventAttributes + CHILD_WORKFLOW_EXECUTION_CANCELED_EVENT_ATTRIBUTES = + ChildWorkflowExecutionCanceledEventAttributes.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setWorkflowType(WORKFLOW_TYPE) + .setInitiatedEventId(1) + .setStartedEventId(2) + .setDetails(payload("details")) + .build(); + + public static final ChildWorkflowExecutionCompletedEventAttributes + CHILD_WORKFLOW_EXECUTION_COMPLETED_EVENT_ATTRIBUTES = + ChildWorkflowExecutionCompletedEventAttributes.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setWorkflowType(WORKFLOW_TYPE) + .setInitiatedEventId(1) + .setStartedEventId(2) + .setResult(payload("result")) + .build(); + + public static final ChildWorkflowExecutionFailedEventAttributes + CHILD_WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES = + ChildWorkflowExecutionFailedEventAttributes.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setWorkflowType(WORKFLOW_TYPE) + .setInitiatedEventId(1) + .setStartedEventId(2) + .setFailure(FAILURE) + .build(); + + public static final ChildWorkflowExecutionStartedEventAttributes + CHILD_WORKFLOW_EXECUTION_STARTED_EVENT_ATTRIBUTES = + ChildWorkflowExecutionStartedEventAttributes.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setWorkflowType(WORKFLOW_TYPE) + .setInitiatedEventId(1) + .setHeader(HEADER) + .build(); + + public static final ChildWorkflowExecutionTerminatedEventAttributes + CHILD_WORKFLOW_EXECUTION_TERMINATED_EVENT_ATTRIBUTES = + ChildWorkflowExecutionTerminatedEventAttributes.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setWorkflowType(WORKFLOW_TYPE) + .setInitiatedEventId(1) + .setStartedEventId(2) + .build(); + + public static final ChildWorkflowExecutionTimedOutEventAttributes + CHILD_WORKFLOW_EXECUTION_TIMED_OUT_EVENT_ATTRIBUTES = + ChildWorkflowExecutionTimedOutEventAttributes.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setWorkflowType(WORKFLOW_TYPE) + .setInitiatedEventId(1) + .setStartedEventId(2) + .setTimeoutType(TimeoutType.TIMEOUT_TYPE_SCHEDULE_TO_CLOSE) + .build(); + + public static final WorkflowExecutionTerminatedEventAttributes + WORKFLOW_EXECUTION_TERMINATED_EVENT_ATTRIBUTES = + WorkflowExecutionTerminatedEventAttributes.newBuilder() + .setReason("reason") + .setDetails(payload("details")) + .setIdentity("identity") + .build(); + + public static final WorkflowExecutionCancelRequestedEventAttributes + WORKFLOW_EXECUTION_CANCEL_REQUESTED_EVENT_ATTRIBUTES = + WorkflowExecutionCancelRequestedEventAttributes.newBuilder() + .setCause("cause") + .setExternalExecutionInfo( + ExternalExecutionInfo.newBuilder() + .setInitiatedId(1) + .setWorkflowExecution(WORKFLOW_EXECUTION) + .build()) + .setIdentity("identity") + .build(); + + public static final WorkflowExecutionCanceledEventAttributes + WORKFLOW_EXECUTION_CANCELED_EVENT_ATTRIBUTES = + WorkflowExecutionCanceledEventAttributes.newBuilder() + .setDecisionTaskCompletedEventId(1) + .setDetails(payload("details")) + .build(); + + public static final RequestCancelExternalWorkflowExecutionInitiatedEventAttributes + REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_INITIATED_EVENT_ATTRIBUTES = + RequestCancelExternalWorkflowExecutionInitiatedEventAttributes.newBuilder() + .setDecisionTaskCompletedEventId(1) + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setControl(utf8("control")) + .setChildWorkflowOnly(true) + .build(); + + public static final RequestCancelExternalWorkflowExecutionFailedEventAttributes + REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES = + RequestCancelExternalWorkflowExecutionFailedEventAttributes.newBuilder() + .setCause( + CancelExternalWorkflowExecutionFailedCause + .CANCEL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_WORKFLOW_ALREADY_COMPLETED) + .setDecisionTaskCompletedEventId(1) + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setInitiatedEventId(2) + .setControl(utf8("control")) + .build(); + + public static final ExternalWorkflowExecutionCancelRequestedEventAttributes + EXTERNAL_WORKFLOW_EXECUTION_CANCEL_REQUESTED_EVENT_ATTRIBUTES = + ExternalWorkflowExecutionCancelRequestedEventAttributes.newBuilder() + .setInitiatedEventId(1) + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .build(); + + public static final WorkflowExecutionContinuedAsNewEventAttributes + WORKFLOW_EXECUTION_CONTINUED_AS_NEW_EVENT_ATTRIBUTES = + WorkflowExecutionContinuedAsNewEventAttributes.newBuilder() + .setNewExecutionRunId("newRunId") + .setWorkflowType(WORKFLOW_TYPE) + .setTaskList(TASK_LIST) + .setInput(payload("input")) + .setExecutionStartToCloseTimeout(seconds(1)) + .setTaskStartToCloseTimeout(seconds(2)) + .setDecisionTaskCompletedEventId(3) + .setBackoffStartInterval(seconds(4)) + .setInitiator(ContinueAsNewInitiator.CONTINUE_AS_NEW_INITIATOR_RETRY_POLICY) + .setFailure( + Failure.newBuilder() + .setReason("failureReason") + .setDetails(utf8("failureDetails")) + .build()) + .setLastCompletionResult(payload("lastCompletionResult")) + .setHeader(HEADER) + .setMemo(MEMO) + .setSearchAttributes(SEARCH_ATTRIBUTES) + .build(); + + public static final SignalExternalWorkflowExecutionInitiatedEventAttributes + SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_INITIATED_EVENT_ATTRIBUTES = + SignalExternalWorkflowExecutionInitiatedEventAttributes.newBuilder() + .setDecisionTaskCompletedEventId(1) + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setSignalName("signalName") + .setInput(payload("input")) + .setControl(utf8("control")) + .setChildWorkflowOnly(true) + .build(); + + public static final SignalExternalWorkflowExecutionFailedEventAttributes + SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES = + SignalExternalWorkflowExecutionFailedEventAttributes.newBuilder() + .setCause( + SignalExternalWorkflowExecutionFailedCause + .SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_WORKFLOW_ALREADY_COMPLETED) + .setDecisionTaskCompletedEventId(1) + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setInitiatedEventId(2) + .setControl(utf8("control")) + .build(); + + public static final WorkflowExecutionSignaledEventAttributes + WORKFLOW_EXECUTION_SIGNALED_EVENT_ATTRIBUTES = + WorkflowExecutionSignaledEventAttributes.newBuilder() + .setSignalName("signalName") + .setInput(payload("input")) + .setIdentity("identity") + .build(); + + public static final ExternalWorkflowExecutionSignaledEventAttributes + EXTERNAL_WORKFLOW_EXECUTION_SIGNALED_EVENT_ATTRIBUTES = + ExternalWorkflowExecutionSignaledEventAttributes.newBuilder() + .setInitiatedEventId(1) + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setControl(utf8("control")) + .build(); public static final CountWorkflowExecutionsRequest COUNT_WORKFLOW_EXECUTIONS_REQUEST = CountWorkflowExecutionsRequest.newBuilder().setDomain("domain").setQuery("query").build(); public static final DescribeTaskListRequest DESCRIBE_TASK_LIST_REQUEST = diff --git a/src/test/java/com/uber/cadence/internal/compatibility/ThriftObjects.java b/src/test/java/com/uber/cadence/internal/compatibility/ThriftObjects.java index 5c7e7308a..deee5799c 100644 --- a/src/test/java/com/uber/cadence/internal/compatibility/ThriftObjects.java +++ b/src/test/java/com/uber/cadence/internal/compatibility/ThriftObjects.java @@ -19,6 +19,7 @@ import com.uber.cadence.*; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; +import java.util.Collections; import java.util.Map; public final class ThriftObjects { @@ -43,6 +44,10 @@ public final class ThriftObjects { public static final String RUN_ID = "runId"; public static final WorkflowExecution WORKFLOW_EXECUTION = new WorkflowExecution().setWorkflowId(WORKFLOW_ID).setRunId(RUN_ID); + public static final String PARENT_WORkFLOW_ID = "parentWorkflowId"; + public static final String PARENT_RUN_ID = "parentRunId"; + public static final WorkflowExecution PARENT_WORKFLOW_EXECUTION = + new WorkflowExecution().setWorkflowId(PARENT_WORkFLOW_ID).setRunId(PARENT_RUN_ID); public static final StickyExecutionAttributes STICKY_EXECUTION_ATTRIBUTES = new StickyExecutionAttributes() .setWorkerTaskList(TASK_LIST) @@ -59,7 +64,16 @@ public final class ThriftObjects { public static final SearchAttributes SEARCH_ATTRIBUTES = new SearchAttributes().setIndexedFields(ImmutableMap.of("search", utf8("attributes"))); public static final Map DATA = ImmutableMap.of("dataKey", "dataValue"); - + public static final ResetPointInfo RESET_POINT_INFO = + new ResetPointInfo() + .setBinaryChecksum("binaryChecksum") + .setRunId("runId") + .setCreatedTimeNano(1) + .setResettable(true) + .setExpiringTimeNano(2) + .setFirstDecisionCompletedId(3); + public static final ResetPoints RESET_POINTS = + new ResetPoints().setPoints(Collections.singletonList(RESET_POINT_INFO)); public static final ClusterReplicationConfiguration CLUSTER_REPLICATION_CONFIGURATION = new ClusterReplicationConfiguration().setClusterName("cluster"); @@ -189,6 +203,400 @@ public final class ThriftObjects { .setMarkerName("markerName") .setDetails(utf8("details")) .setHeader(HEADER)); + + public static final WorkflowExecutionStartedEventAttributes + WORKFLOW_EXECUTION_STARTED_EVENT_ATTRIBUTES = + new WorkflowExecutionStartedEventAttributes() + .setWorkflowType(WORKFLOW_TYPE) + .setParentWorkflowDomain("parentDomainName") + .setParentWorkflowExecution(PARENT_WORKFLOW_EXECUTION) + .setParentInitiatedEventId(1) + .setTaskList(TASK_LIST) + .setInput(utf8("input")) + .setExecutionStartToCloseTimeoutSeconds(2) + .setTaskStartToCloseTimeoutSeconds(3) + .setContinuedExecutionRunId("continuedExecutionRunId") + .setInitiator(ContinueAsNewInitiator.RetryPolicy) + .setContinuedFailureReason("continuedFailureReason") + .setContinuedFailureDetails(utf8("continuedFailureDetails")) + .setLastCompletionResult(utf8("lastCompletionResult")) + .setOriginalExecutionRunId("originalExecutionRunId") + .setIdentity("identity") + .setFirstExecutionRunId("firstExecutionRunId") + .setRetryPolicy(RETRY_POLICY) + .setAttempt(4) + .setExpirationTimestamp(5) + .setCronSchedule("cronSchedule") + .setFirstDecisionTaskBackoffSeconds(6) + .setMemo(MEMO) + .setSearchAttributes(SEARCH_ATTRIBUTES) + .setPrevAutoResetPoints(RESET_POINTS) + .setHeader(HEADER); + + public static final WorkflowExecutionCompletedEventAttributes + WORKFLOW_EXECUTION_COMPLETED_EVENT_ATTRIBUTES = + new WorkflowExecutionCompletedEventAttributes() + .setResult(utf8("result")) + .setDecisionTaskCompletedEventId(1); + + public static final WorkflowExecutionFailedEventAttributes + WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES = + new WorkflowExecutionFailedEventAttributes() + .setReason("reason") + .setDetails(utf8("details")) + .setDecisionTaskCompletedEventId(1); + + public static final WorkflowExecutionTimedOutEventAttributes + WORKFLOW_EXECUTION_TIMED_OUT_EVENT_ATTRIBUTES = + new WorkflowExecutionTimedOutEventAttributes() + .setTimeoutType(TimeoutType.SCHEDULE_TO_CLOSE); + + public static final DecisionTaskScheduledEventAttributes + DECISION_TASK_SCHEDULED_EVENT_ATTRIBUTES = + new DecisionTaskScheduledEventAttributes() + .setTaskList(TASK_LIST) + .setStartToCloseTimeoutSeconds(1) + .setAttempt(2); + + public static final DecisionTaskStartedEventAttributes DECISION_TASK_STARTED_EVENT_ATTRIBUTES = + new DecisionTaskStartedEventAttributes() + .setScheduledEventId(1) + .setIdentity("identity") + .setRequestId("requestId"); + + public static final DecisionTaskCompletedEventAttributes + DECISION_TASK_COMPLETED_EVENT_ATTRIBUTES = + new DecisionTaskCompletedEventAttributes() + .setScheduledEventId(1) + .setStartedEventId(2) + .setIdentity("identity") + .setBinaryChecksum("binaryChecksum") + .setExecutionContext(utf8("executionContext")); + + public static final DecisionTaskTimedOutEventAttributes DECISION_TASK_TIMED_OUT_EVENT_ATTRIBUTES = + new DecisionTaskTimedOutEventAttributes() + .setScheduledEventId(1) + .setStartedEventId(2) + .setTimeoutType(TimeoutType.SCHEDULE_TO_CLOSE) + .setBaseRunId("baseRunId") + .setNewRunId("newRunId") + .setForkEventVersion(3) + .setReason("reason") + .setCause(DecisionTaskTimedOutCause.RESET); + + public static final DecisionTaskFailedEventAttributes DECISION_TASK_FAILED_EVENT_ATTRIBUTES = + new DecisionTaskFailedEventAttributes() + .setScheduledEventId(1) + .setStartedEventId(2) + .setCause(DecisionTaskFailedCause.BAD_BINARY) + .setReason("reason") + .setDetails(utf8("details")) + .setIdentity("identity") + .setBaseRunId("baseRun") + .setNewRunId("newRun") + .setForkEventVersion(3) + .setBinaryChecksum("binaryChecksum"); + + public static final ActivityTaskScheduledEventAttributes + ACTIVITY_TASK_SCHEDULED_EVENT_ATTRIBUTES = + new ActivityTaskScheduledEventAttributes() + .setActivityId("activityId") + .setActivityType(ACTIVITY_TYPE) + .setDomain("domain") + .setTaskList(TASK_LIST) + .setInput(utf8("input")) + .setScheduleToCloseTimeoutSeconds(1) + .setScheduleToStartTimeoutSeconds(2) + .setStartToCloseTimeoutSeconds(3) + .setHeartbeatTimeoutSeconds(4) + .setDecisionTaskCompletedEventId(5) + .setRetryPolicy(RETRY_POLICY) + .setHeader(HEADER); + + public static final ActivityTaskStartedEventAttributes ACTIVITY_TASK_STARTED_EVENT_ATTRIBUTES = + new ActivityTaskStartedEventAttributes() + .setScheduledEventId(1) + .setIdentity("identity") + .setRequestId("requestId") + .setAttempt(2) + .setLastFailureReason("failureReason") + .setLastFailureDetails(utf8("failureDetails")); + + public static final ActivityTaskCompletedEventAttributes + ACTIVITY_TASK_COMPLETED_EVENT_ATTRIBUTES = + new ActivityTaskCompletedEventAttributes() + .setResult(utf8("result")) + .setScheduledEventId(1) + .setStartedEventId(2) + .setIdentity("identity"); + + public static final ActivityTaskFailedEventAttributes ACTIVITY_TASK_FAILED_EVENT_ATTRIBUTES = + new ActivityTaskFailedEventAttributes() + .setReason("reason") + .setDetails(utf8("details")) + .setScheduledEventId(1) + .setStartedEventId(2) + .setIdentity("identity"); + + public static final ActivityTaskTimedOutEventAttributes ACTIVITY_TASK_TIMED_OUT_EVENT_ATTRIBUTES = + new ActivityTaskTimedOutEventAttributes() + .setDetails(utf8("details")) + .setScheduledEventId(1) + .setStartedEventId(2) + .setTimeoutType(TimeoutType.SCHEDULE_TO_CLOSE) + .setLastFailureReason("failureReason") + .setLastFailureDetails(utf8("failureDetails")); + + public static final ActivityTaskCancelRequestedEventAttributes + ACTIVITY_TASK_CANCEL_REQUESTED_EVENT_ATTRIBUTES = + new ActivityTaskCancelRequestedEventAttributes() + .setActivityId("activityId") + .setDecisionTaskCompletedEventId(1); + + public static final ActivityTaskCanceledEventAttributes ACTIVITY_TASK_CANCELED_EVENT_ATTRIBUTES = + new ActivityTaskCanceledEventAttributes() + .setDetails(utf8("details")) + .setLatestCancelRequestedEventId(1) + .setScheduledEventId(2) + .setStartedEventId(3) + .setIdentity("identity"); + + public static final RequestCancelActivityTaskFailedEventAttributes + REQUEST_CANCEL_ACTIVITY_TASK_FAILED_EVENT_ATTRIBUTES = + new RequestCancelActivityTaskFailedEventAttributes() + .setActivityId("activityId") + .setCause("cause") + .setDecisionTaskCompletedEventId(1); + + public static final MarkerRecordedEventAttributes MARKER_RECORDED_EVENT_ATTRIBUTES = + new MarkerRecordedEventAttributes() + .setMarkerName("markerName") + .setDetails(utf8("details")) + .setDecisionTaskCompletedEventId(1) + .setHeader(HEADER); + + public static final TimerCanceledEventAttributes TIMER_CANCELED_EVENT_ATTRIBUTES = + new TimerCanceledEventAttributes() + .setTimerId("timerId") + .setStartedEventId(1) + .setDecisionTaskCompletedEventId(2) + .setIdentity("identity"); + + public static final CancelTimerFailedEventAttributes CANCEL_TIMER_FAILED_EVENT_ATTRIBUTES = + new CancelTimerFailedEventAttributes() + .setTimerId("timerId") + .setCause("cause") + .setDecisionTaskCompletedEventId(1) + .setIdentity("identity"); + + public static final TimerFiredEventAttributes TIMER_FIRED_EVENT_ATTRIBUTES = + new TimerFiredEventAttributes().setTimerId("timerId").setStartedEventId(1); + + public static final TimerStartedEventAttributes TIMER_STARTED_EVENT_ATTRIBUTES = + new TimerStartedEventAttributes() + .setTimerId("timerId") + .setStartToFireTimeoutSeconds(1) + .setDecisionTaskCompletedEventId(2); + + public static final UpsertWorkflowSearchAttributesEventAttributes + UPSERT_WORKFLOW_SEARCH_ATTRIBUTES_EVENT_ATTRIBUTES = + new UpsertWorkflowSearchAttributesEventAttributes() + .setDecisionTaskCompletedEventId(1) + .setSearchAttributes(SEARCH_ATTRIBUTES); + + public static final StartChildWorkflowExecutionInitiatedEventAttributes + START_CHILD_WORKFLOW_EXECUTION_INITIATED_EVENT_ATTRIBUTES = + new StartChildWorkflowExecutionInitiatedEventAttributes() + .setDomain("domain") + .setWorkflowId(WORKFLOW_ID) + .setWorkflowType(WORKFLOW_TYPE) + .setTaskList(TASK_LIST) + .setInput(utf8("input")) + .setExecutionStartToCloseTimeoutSeconds(1) + .setTaskStartToCloseTimeoutSeconds(2) + .setParentClosePolicy(ParentClosePolicy.REQUEST_CANCEL) + .setControl(utf8("control")) + .setDecisionTaskCompletedEventId(3) + .setWorkflowIdReusePolicy(WorkflowIdReusePolicy.AllowDuplicate) + .setRetryPolicy(RETRY_POLICY) + .setCronSchedule("cron") + .setHeader(HEADER) + .setMemo(MEMO) + .setSearchAttributes(SEARCH_ATTRIBUTES) + .setDelayStartSeconds(4); + + public static final StartChildWorkflowExecutionFailedEventAttributes + START_CHILD_WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES = + new StartChildWorkflowExecutionFailedEventAttributes() + .setDomain("domain") + .setWorkflowId(WORKFLOW_ID) + .setWorkflowType(WORKFLOW_TYPE) + .setCause(ChildWorkflowExecutionFailedCause.WORKFLOW_ALREADY_RUNNING) + .setControl(utf8("control")) + .setInitiatedEventId(1) + .setDecisionTaskCompletedEventId(2); + + public static final ChildWorkflowExecutionCanceledEventAttributes + CHILD_WORKFLOW_EXECUTION_CANCELED_EVENT_ATTRIBUTES = + new ChildWorkflowExecutionCanceledEventAttributes() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setWorkflowType(WORKFLOW_TYPE) + .setInitiatedEventId(1) + .setStartedEventId(2) + .setDetails(utf8("details")); + + public static final ChildWorkflowExecutionCompletedEventAttributes + CHILD_WORKFLOW_EXECUTION_COMPLETED_EVENT_ATTRIBUTES = + new ChildWorkflowExecutionCompletedEventAttributes() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setWorkflowType(WORKFLOW_TYPE) + .setInitiatedEventId(1) + .setStartedEventId(2) + .setResult(utf8("result")); + + public static final ChildWorkflowExecutionFailedEventAttributes + CHILD_WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES = + new ChildWorkflowExecutionFailedEventAttributes() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setWorkflowType(WORKFLOW_TYPE) + .setInitiatedEventId(1) + .setStartedEventId(2) + .setReason("reason") + .setDetails(utf8("details")); + + public static final ChildWorkflowExecutionStartedEventAttributes + CHILD_WORKFLOW_EXECUTION_STARTED_EVENT_ATTRIBUTES = + new ChildWorkflowExecutionStartedEventAttributes() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setWorkflowType(WORKFLOW_TYPE) + .setInitiatedEventId(1) + .setHeader(HEADER); + + public static final ChildWorkflowExecutionTerminatedEventAttributes + CHILD_WORKFLOW_EXECUTION_TERMINATED_EVENT_ATTRIBUTES = + new ChildWorkflowExecutionTerminatedEventAttributes() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setWorkflowType(WORKFLOW_TYPE) + .setInitiatedEventId(1) + .setStartedEventId(2); + + public static final ChildWorkflowExecutionTimedOutEventAttributes + CHILD_WORKFLOW_EXECUTION_TIMED_OUT_EVENT_ATTRIBUTES = + new ChildWorkflowExecutionTimedOutEventAttributes() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setWorkflowType(WORKFLOW_TYPE) + .setInitiatedEventId(1) + .setStartedEventId(2) + .setTimeoutType(TimeoutType.SCHEDULE_TO_CLOSE); + + public static final WorkflowExecutionTerminatedEventAttributes + WORKFLOW_EXECUTION_TERMINATED_EVENT_ATTRIBUTES = + new WorkflowExecutionTerminatedEventAttributes() + .setReason("reason") + .setDetails(utf8("details")) + .setIdentity("identity"); + + public static final WorkflowExecutionCancelRequestedEventAttributes + WORKFLOW_EXECUTION_CANCEL_REQUESTED_EVENT_ATTRIBUTES = + new WorkflowExecutionCancelRequestedEventAttributes() + .setCause("cause") + .setExternalInitiatedEventId(1) + .setExternalWorkflowExecution(WORKFLOW_EXECUTION) + .setIdentity("identity"); + + public static final WorkflowExecutionCanceledEventAttributes + WORKFLOW_EXECUTION_CANCELED_EVENT_ATTRIBUTES = + new WorkflowExecutionCanceledEventAttributes() + .setDecisionTaskCompletedEventId(1) + .setDetails(utf8("details")); + + public static final RequestCancelExternalWorkflowExecutionInitiatedEventAttributes + REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_INITIATED_EVENT_ATTRIBUTES = + new RequestCancelExternalWorkflowExecutionInitiatedEventAttributes() + .setDecisionTaskCompletedEventId(1) + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setControl(utf8("control")) + .setChildWorkflowOnly(true); + + public static final RequestCancelExternalWorkflowExecutionFailedEventAttributes + REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES = + new RequestCancelExternalWorkflowExecutionFailedEventAttributes() + .setCause(CancelExternalWorkflowExecutionFailedCause.WORKFLOW_ALREADY_COMPLETED) + .setDecisionTaskCompletedEventId(1) + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setInitiatedEventId(2) + .setControl(utf8("control")); + + public static final ExternalWorkflowExecutionCancelRequestedEventAttributes + EXTERNAL_WORKFLOW_EXECUTION_CANCEL_REQUESTED_EVENT_ATTRIBUTES = + new ExternalWorkflowExecutionCancelRequestedEventAttributes() + .setInitiatedEventId(1) + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION); + + public static final WorkflowExecutionContinuedAsNewEventAttributes + WORKFLOW_EXECUTION_CONTINUED_AS_NEW_EVENT_ATTRIBUTES = + new WorkflowExecutionContinuedAsNewEventAttributes() + .setNewExecutionRunId("newRunId") + .setWorkflowType(WORKFLOW_TYPE) + .setTaskList(TASK_LIST) + .setInput(utf8("input")) + .setExecutionStartToCloseTimeoutSeconds(1) + .setTaskStartToCloseTimeoutSeconds(2) + .setDecisionTaskCompletedEventId(3) + .setBackoffStartIntervalInSeconds(4) + .setInitiator(ContinueAsNewInitiator.RetryPolicy) + .setFailureReason("failureReason") + .setFailureDetails(utf8("failureDetails")) + .setLastCompletionResult(utf8("lastCompletionResult")) + .setHeader(HEADER) + .setMemo(MEMO) + .setSearchAttributes(SEARCH_ATTRIBUTES); + + public static final SignalExternalWorkflowExecutionInitiatedEventAttributes + SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_INITIATED_EVENT_ATTRIBUTES = + new SignalExternalWorkflowExecutionInitiatedEventAttributes() + .setDecisionTaskCompletedEventId(1) + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setSignalName("signalName") + .setInput(utf8("input")) + .setControl(utf8("control")) + .setChildWorkflowOnly(true); + + public static final SignalExternalWorkflowExecutionFailedEventAttributes + SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES = + new SignalExternalWorkflowExecutionFailedEventAttributes() + .setCause(SignalExternalWorkflowExecutionFailedCause.WORKFLOW_ALREADY_COMPLETED) + .setDecisionTaskCompletedEventId(1) + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setInitiatedEventId(2) + .setControl(utf8("control")); + + public static final WorkflowExecutionSignaledEventAttributes + WORKFLOW_EXECUTION_SIGNALED_EVENT_ATTRIBUTES = + new WorkflowExecutionSignaledEventAttributes() + .setSignalName("signalName") + .setInput(utf8("input")) + .setIdentity("identity"); + + public static final ExternalWorkflowExecutionSignaledEventAttributes + EXTERNAL_WORKFLOW_EXECUTION_SIGNALED_EVENT_ATTRIBUTES = + new ExternalWorkflowExecutionSignaledEventAttributes() + .setInitiatedEventId(1) + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setControl(utf8("control")); + public static final CountWorkflowExecutionsRequest COUNT_WORKFLOW_EXECUTIONS_REQUEST = new CountWorkflowExecutionsRequest().setDomain("domain").setQuery("query"); public static final DescribeTaskListRequest DESCRIBE_TASK_LIST_REQUEST = diff --git a/src/test/java/com/uber/cadence/internal/compatibility/thrift/HistoryMapperEventTest.java b/src/test/java/com/uber/cadence/internal/compatibility/thrift/HistoryMapperEventTest.java new file mode 100644 index 000000000..52d80c191 --- /dev/null +++ b/src/test/java/com/uber/cadence/internal/compatibility/thrift/HistoryMapperEventTest.java @@ -0,0 +1,325 @@ +package com.uber.cadence.internal.compatibility.thrift; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableSet; +import com.google.protobuf.Message; +import com.google.protobuf.Timestamp; +import com.uber.cadence.EventType; +import com.uber.cadence.HistoryEvent; +import com.uber.cadence.internal.compatibility.MapperTestUtil; +import com.uber.cadence.internal.compatibility.ProtoObjects; +import com.uber.cadence.internal.compatibility.ThriftObjects; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import org.apache.thrift.TBase; +import org.apache.thrift.TFieldIdEnum; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) +public class HistoryMapperEventTest< + F extends Message, E extends Enum & TFieldIdEnum, T extends TBase> { + private static final Map, Method> ATTRIBUTE_CONVERTERS = + indexSingleParameterMethods(HistoryMapper.class, Message.class); + private static final long EVENT_ID = 1; + private static final int TIMESTAMP_NANOS = 100; + private static final Timestamp TIMESTAMP = + Timestamp.newBuilder().setNanos(TIMESTAMP_NANOS).build(); + private static final long VERSION = 2; + private static final long TASK_ID = 3; + + @Parameterized.Parameter public EventType eventType; + + @Parameterized.Parameter(1) + public F from; + + @Parameterized.Parameter(2) + public T to; + + @Parameterized.Parameter(3) + public Set missingFields; + + @Test + public void testHistoryEvent() { + HistoryEvent thriftEvent = createThriftHistoryEvent(); + assertEquals(thriftEvent, HistoryMapper.historyEvent(createProtoHistoryEvent())); + } + + @Test + public void testConverter() { + assertEquals(to, convertToThrift(from)); + } + + @Test + public void testConverterWithNull() { + assertNull("Passing null should return null", convertToThrift(null)); + } + + @Test + public void testAllFieldsPresent() { + if (missingFields.isEmpty()) { + MapperTestUtil.assertNoMissingFields(to); + } else { + MapperTestUtil.assertMissingFields(to, missingFields); + } + } + + private com.uber.cadence.api.v1.HistoryEvent createProtoHistoryEvent() { + com.uber.cadence.api.v1.HistoryEvent.Builder eventBuilder = + com.uber.cadence.api.v1.HistoryEvent.newBuilder() + .setEventId(EVENT_ID) + .setEventTime(TIMESTAMP) + .setVersion(VERSION) + .setTaskId(TASK_ID); + // Apply the attributes + callSetter(eventBuilder, from); + return eventBuilder.build(); + } + + private HistoryEvent createThriftHistoryEvent() { + HistoryEvent event = + new HistoryEvent() + .setEventId(EVENT_ID) + .setEventType(eventType) + .setTimestamp(TIMESTAMP_NANOS) + .setVersion(VERSION) + .setTaskId(TASK_ID); + // Apply the attributes + callSetter(event, to); + return event; + } + + private Object convertToThrift(F proto) { + Method converter = ATTRIBUTE_CONVERTERS.get(from.getClass()); + Preconditions.checkState( + converter != null, "failed to find converter for %s", from.getClass().getSimpleName()); + try { + return converter.invoke(null, proto); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } + + private static void callSetter(Object target, Object toSet) { + for (Method method : target.getClass().getDeclaredMethods()) { + Class[] params = method.getParameterTypes(); + if (method.getName().startsWith("set") + && params.length == 1 + && toSet.getClass().isAssignableFrom(params[0])) { + try { + method.invoke(target, toSet); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } + } + } + + // Index all the functions in HistoryMapper by parameter type so we can find them dynamically + private static Map, Method> indexSingleParameterMethods( + Class target, Class parameterType) { + Map, Method> byParameterType = new HashMap<>(); + for (Method method : target.getDeclaredMethods()) { + Class[] params = method.getParameterTypes(); + if (params.length == 1 && parameterType.isAssignableFrom(params[0])) { + Class protoType = (Class) params[0]; + byParameterType.put(protoType, method); + } + } + return byParameterType; + } + + @Parameterized.Parameters(name = "{0}") + public static Object[][] cases() { + return new Object[][] { + testCase( + EventType.WorkflowExecutionStarted, + ProtoObjects.WORKFLOW_EXECUTION_STARTED_EVENT_ATTRIBUTES, + ThriftObjects.WORKFLOW_EXECUTION_STARTED_EVENT_ATTRIBUTES, + "firstScheduledTimeNano", + "partitionConfig", + "requestId"), + testCase( + EventType.WorkflowExecutionCompleted, + ProtoObjects.WORKFLOW_EXECUTION_COMPLETED_EVENT_ATTRIBUTES, + ThriftObjects.WORKFLOW_EXECUTION_COMPLETED_EVENT_ATTRIBUTES), + testCase( + EventType.WorkflowExecutionFailed, + ProtoObjects.WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES, + ThriftObjects.WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES), + testCase( + EventType.WorkflowExecutionTimedOut, + ProtoObjects.WORKFLOW_EXECUTION_TIMED_OUT_EVENT_ATTRIBUTES, + ThriftObjects.WORKFLOW_EXECUTION_TIMED_OUT_EVENT_ATTRIBUTES), + testCase( + EventType.DecisionTaskScheduled, + ProtoObjects.DECISION_TASK_SCHEDULED_EVENT_ATTRIBUTES, + ThriftObjects.DECISION_TASK_SCHEDULED_EVENT_ATTRIBUTES), + testCase( + EventType.DecisionTaskStarted, + ProtoObjects.DECISION_TASK_STARTED_EVENT_ATTRIBUTES, + ThriftObjects.DECISION_TASK_STARTED_EVENT_ATTRIBUTES), + testCase( + EventType.DecisionTaskCompleted, + ProtoObjects.DECISION_TASK_COMPLETED_EVENT_ATTRIBUTES, + ThriftObjects.DECISION_TASK_COMPLETED_EVENT_ATTRIBUTES), + testCase( + EventType.DecisionTaskTimedOut, + ProtoObjects.DECISION_TASK_TIMED_OUT_EVENT_ATTRIBUTES, + ThriftObjects.DECISION_TASK_TIMED_OUT_EVENT_ATTRIBUTES, + "requestId"), + testCase( + EventType.DecisionTaskFailed, + ProtoObjects.DECISION_TASK_FAILED_EVENT_ATTRIBUTES, + ThriftObjects.DECISION_TASK_FAILED_EVENT_ATTRIBUTES, + "requestId"), + testCase( + EventType.ActivityTaskScheduled, + ProtoObjects.ACTIVITY_TASK_SCHEDULED_EVENT_ATTRIBUTES, + ThriftObjects.ACTIVITY_TASK_SCHEDULED_EVENT_ATTRIBUTES), + testCase( + EventType.ActivityTaskStarted, + ProtoObjects.ACTIVITY_TASK_STARTED_EVENT_ATTRIBUTES, + ThriftObjects.ACTIVITY_TASK_STARTED_EVENT_ATTRIBUTES), + testCase( + EventType.ActivityTaskCompleted, + ProtoObjects.ACTIVITY_TASK_COMPLETED_EVENT_ATTRIBUTES, + ThriftObjects.ACTIVITY_TASK_COMPLETED_EVENT_ATTRIBUTES), + testCase( + EventType.ActivityTaskFailed, + ProtoObjects.ACTIVITY_TASK_FAILED_EVENT_ATTRIBUTES, + ThriftObjects.ACTIVITY_TASK_FAILED_EVENT_ATTRIBUTES), + testCase( + EventType.ActivityTaskTimedOut, + ProtoObjects.ACTIVITY_TASK_TIMED_OUT_EVENT_ATTRIBUTES, + ThriftObjects.ACTIVITY_TASK_TIMED_OUT_EVENT_ATTRIBUTES), + testCase( + EventType.ActivityTaskCancelRequested, + ProtoObjects.ACTIVITY_TASK_CANCEL_REQUESTED_EVENT_ATTRIBUTES, + ThriftObjects.ACTIVITY_TASK_CANCEL_REQUESTED_EVENT_ATTRIBUTES), + testCase( + EventType.RequestCancelActivityTaskFailed, + ProtoObjects.REQUEST_CANCEL_ACTIVITY_TASK_FAILED_EVENT_ATTRIBUTES, + ThriftObjects.REQUEST_CANCEL_ACTIVITY_TASK_FAILED_EVENT_ATTRIBUTES), + testCase( + EventType.ActivityTaskCanceled, + ProtoObjects.ACTIVITY_TASK_CANCELED_EVENT_ATTRIBUTES, + ThriftObjects.ACTIVITY_TASK_CANCELED_EVENT_ATTRIBUTES), + testCase( + EventType.TimerStarted, + ProtoObjects.TIMER_STARTED_EVENT_ATTRIBUTES, + ThriftObjects.TIMER_STARTED_EVENT_ATTRIBUTES), + testCase( + EventType.TimerFired, + ProtoObjects.TIMER_FIRED_EVENT_ATTRIBUTES, + ThriftObjects.TIMER_FIRED_EVENT_ATTRIBUTES), + testCase( + EventType.CancelTimerFailed, + ProtoObjects.CANCEL_TIMER_FAILED_EVENT_ATTRIBUTES, + ThriftObjects.CANCEL_TIMER_FAILED_EVENT_ATTRIBUTES), + testCase( + EventType.TimerCanceled, + ProtoObjects.TIMER_CANCELED_EVENT_ATTRIBUTES, + ThriftObjects.TIMER_CANCELED_EVENT_ATTRIBUTES), + testCase( + EventType.WorkflowExecutionCancelRequested, + ProtoObjects.WORKFLOW_EXECUTION_CANCEL_REQUESTED_EVENT_ATTRIBUTES, + ThriftObjects.WORKFLOW_EXECUTION_CANCEL_REQUESTED_EVENT_ATTRIBUTES, + "requestId"), + testCase( + EventType.WorkflowExecutionCanceled, + ProtoObjects.WORKFLOW_EXECUTION_CANCELED_EVENT_ATTRIBUTES, + ThriftObjects.WORKFLOW_EXECUTION_CANCELED_EVENT_ATTRIBUTES), + testCase( + EventType.RequestCancelExternalWorkflowExecutionInitiated, + ProtoObjects.REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_INITIATED_EVENT_ATTRIBUTES, + ThriftObjects.REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_INITIATED_EVENT_ATTRIBUTES), + testCase( + EventType.RequestCancelExternalWorkflowExecutionFailed, + ProtoObjects.REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES, + ThriftObjects.REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES), + testCase( + EventType.ExternalWorkflowExecutionCancelRequested, + ProtoObjects.EXTERNAL_WORKFLOW_EXECUTION_CANCEL_REQUESTED_EVENT_ATTRIBUTES, + ThriftObjects.EXTERNAL_WORKFLOW_EXECUTION_CANCEL_REQUESTED_EVENT_ATTRIBUTES), + testCase( + EventType.MarkerRecorded, + ProtoObjects.MARKER_RECORDED_EVENT_ATTRIBUTES, + ThriftObjects.MARKER_RECORDED_EVENT_ATTRIBUTES), + testCase( + EventType.WorkflowExecutionSignaled, + ProtoObjects.WORKFLOW_EXECUTION_SIGNALED_EVENT_ATTRIBUTES, + ThriftObjects.WORKFLOW_EXECUTION_SIGNALED_EVENT_ATTRIBUTES, + "requestId"), + testCase( + EventType.WorkflowExecutionTerminated, + ProtoObjects.WORKFLOW_EXECUTION_TERMINATED_EVENT_ATTRIBUTES, + ThriftObjects.WORKFLOW_EXECUTION_TERMINATED_EVENT_ATTRIBUTES), + testCase( + EventType.WorkflowExecutionContinuedAsNew, + ProtoObjects.WORKFLOW_EXECUTION_CONTINUED_AS_NEW_EVENT_ATTRIBUTES, + ThriftObjects.WORKFLOW_EXECUTION_CONTINUED_AS_NEW_EVENT_ATTRIBUTES), + testCase( + EventType.StartChildWorkflowExecutionInitiated, + ProtoObjects.START_CHILD_WORKFLOW_EXECUTION_INITIATED_EVENT_ATTRIBUTES, + ThriftObjects.START_CHILD_WORKFLOW_EXECUTION_INITIATED_EVENT_ATTRIBUTES, + "jitterStartSeconds"), + testCase( + EventType.StartChildWorkflowExecutionFailed, + ProtoObjects.START_CHILD_WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES, + ThriftObjects.START_CHILD_WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES), + testCase( + EventType.ChildWorkflowExecutionStarted, + ProtoObjects.CHILD_WORKFLOW_EXECUTION_STARTED_EVENT_ATTRIBUTES, + ThriftObjects.CHILD_WORKFLOW_EXECUTION_STARTED_EVENT_ATTRIBUTES), + testCase( + EventType.ChildWorkflowExecutionCompleted, + ProtoObjects.CHILD_WORKFLOW_EXECUTION_COMPLETED_EVENT_ATTRIBUTES, + ThriftObjects.CHILD_WORKFLOW_EXECUTION_COMPLETED_EVENT_ATTRIBUTES), + testCase( + EventType.ChildWorkflowExecutionFailed, + ProtoObjects.CHILD_WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES, + ThriftObjects.CHILD_WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES), + testCase( + EventType.ChildWorkflowExecutionCanceled, + ProtoObjects.CHILD_WORKFLOW_EXECUTION_CANCELED_EVENT_ATTRIBUTES, + ThriftObjects.CHILD_WORKFLOW_EXECUTION_CANCELED_EVENT_ATTRIBUTES), + testCase( + EventType.ChildWorkflowExecutionTimedOut, + ProtoObjects.CHILD_WORKFLOW_EXECUTION_TIMED_OUT_EVENT_ATTRIBUTES, + ThriftObjects.CHILD_WORKFLOW_EXECUTION_TIMED_OUT_EVENT_ATTRIBUTES), + testCase( + EventType.ChildWorkflowExecutionTerminated, + ProtoObjects.CHILD_WORKFLOW_EXECUTION_TERMINATED_EVENT_ATTRIBUTES, + ThriftObjects.CHILD_WORKFLOW_EXECUTION_TERMINATED_EVENT_ATTRIBUTES), + testCase( + EventType.SignalExternalWorkflowExecutionInitiated, + ProtoObjects.SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_INITIATED_EVENT_ATTRIBUTES, + ThriftObjects.SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_INITIATED_EVENT_ATTRIBUTES), + testCase( + EventType.SignalExternalWorkflowExecutionFailed, + ProtoObjects.SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES, + ThriftObjects.SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_EVENT_ATTRIBUTES), + testCase( + EventType.ExternalWorkflowExecutionSignaled, + ProtoObjects.EXTERNAL_WORKFLOW_EXECUTION_SIGNALED_EVENT_ATTRIBUTES, + ThriftObjects.EXTERNAL_WORKFLOW_EXECUTION_SIGNALED_EVENT_ATTRIBUTES), + testCase( + EventType.UpsertWorkflowSearchAttributes, + ProtoObjects.UPSERT_WORKFLOW_SEARCH_ATTRIBUTES_EVENT_ATTRIBUTES, + ThriftObjects.UPSERT_WORKFLOW_SEARCH_ATTRIBUTES_EVENT_ATTRIBUTES), + }; + } + + private static Object[] testCase( + EventType type, Message proto, TBase thrift, String... expectedMissingFields) { + return new Object[] {type, proto, thrift, ImmutableSet.copyOf(expectedMissingFields)}; + } +}