diff --git a/src/test/java/com/uber/cadence/internal/compatibility/MapperTestUtil.java b/src/test/java/com/uber/cadence/internal/compatibility/MapperTestUtil.java index 890528629..96e3df2ad 100644 --- a/src/test/java/com/uber/cadence/internal/compatibility/MapperTestUtil.java +++ b/src/test/java/com/uber/cadence/internal/compatibility/MapperTestUtil.java @@ -33,10 +33,27 @@ */ public class MapperTestUtil { + public static & TFieldIdEnum, M extends TBase> + void assertNoMissingFields(M message) { + assertNoMissingFields(message, findFieldsEnum(message)); + } + public static & TFieldIdEnum, M extends TBase> void assertNoMissingFields(M message, Class fields) { Assert.assertEquals( - "All fields expected to be set", Collections.emptySet(), getUnsetFields(message, fields)); + "All fields expected to be set in " + message.getClass().getSimpleName(), + Collections.emptySet(), + getUnsetFields(message, fields)); + } + + public static & TFieldIdEnum, M extends TBase> void assertMissingFields( + M message, String... values) { + assertMissingFields(message, findFieldsEnum(message), ImmutableSet.copyOf(values)); + } + + public static & TFieldIdEnum, M extends TBase> void assertMissingFields( + M message, Set values) { + assertMissingFields(message, findFieldsEnum(message), values); } public static & TFieldIdEnum, M extends TBase> void assertMissingFields( @@ -47,7 +64,9 @@ public static & TFieldIdEnum, M extends TBase> void ass public static & TFieldIdEnum, M extends TBase> void assertMissingFields( M message, Class fields, Set expected) { Assert.assertEquals( - "Additional fields are unexpectedly not set", expected, getUnsetFields(message, fields)); + "Additional fields are unexpectedly not set in " + message.getClass().getSimpleName(), + expected, + getUnsetFields(message, fields)); } private static & TFieldIdEnum, M extends TBase> @@ -57,4 +76,16 @@ Set getUnsetFields(M message, Class fields) { .map(TFieldIdEnum::getFieldName) .collect(Collectors.toSet()); } + + @SuppressWarnings("unchecked") + private static & TFieldIdEnum, M extends TBase> Class findFieldsEnum( + M message) { + for (Class declaredClass : message.getClass().getDeclaredClasses()) { + if ("_Fields".equals(declaredClass.getSimpleName())) { + return (Class) declaredClass; + } + } + throw new IllegalStateException( + "Failed to find _Fields enum for " + message.getClass().getCanonicalName()); + } } diff --git a/src/test/java/com/uber/cadence/internal/compatibility/ProtoObjects.java b/src/test/java/com/uber/cadence/internal/compatibility/ProtoObjects.java new file mode 100644 index 000000000..30c9100cb --- /dev/null +++ b/src/test/java/com/uber/cadence/internal/compatibility/ProtoObjects.java @@ -0,0 +1,564 @@ +package com.uber.cadence.internal.compatibility; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.protobuf.ByteString; +import com.google.protobuf.DoubleValue; +import com.google.protobuf.Duration; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import com.uber.cadence.api.v1.*; +import java.util.Map; + +public final class ProtoObjects { + public static final WorkflowType WORKFLOW_TYPE = + WorkflowType.newBuilder().setName("workflowType").build(); + public static final ActivityType ACTIVITY_TYPE = + ActivityType.newBuilder().setName("activityName").build(); + public static final TaskList TASK_LIST = + TaskList.newBuilder().setName("taskList").setKind(TaskListKind.TASK_LIST_KIND_NORMAL).build(); + public static final TaskListMetadata TASK_LIST_METADATA = + TaskListMetadata.newBuilder() + .setMaxTasksPerSecond(DoubleValue.newBuilder().setValue(10.0).build()) + .build(); + public static final RetryPolicy RETRY_POLICY = + RetryPolicy.newBuilder() + .setInitialInterval(seconds(11)) + .setBackoffCoefficient(0.5) + .setMaximumInterval(seconds(12)) + .setMaximumAttempts(13) + .addNonRetryableErrorReasons("error") + .setExpirationInterval(seconds(14)) + .build(); + public static final WorkflowExecution WORKFLOW_EXECUTION = + WorkflowExecution.newBuilder().setWorkflowId("workflowId").setRunId("runId").build(); + public static final Failure FAILURE = + Failure.newBuilder().setDetails(utf8("details")).setReason("reason").build(); + public static final StickyExecutionAttributes STICKY_EXECUTION_ATTRIBUTES = + StickyExecutionAttributes.newBuilder() + .setWorkerTaskList(TASK_LIST) + .setScheduleToStartTimeout(seconds(1)) + .build(); + public static final WorkflowQuery WORKFLOW_QUERY = + WorkflowQuery.newBuilder() + .setQueryType("queryType") + .setQueryArgs(payload("queryArgs")) + .build(); + public static final WorkflowQueryResult WORKFLOW_QUERY_RESULT = + WorkflowQueryResult.newBuilder() + .setResultType(QueryResultType.QUERY_RESULT_TYPE_ANSWERED) + .setAnswer(payload("answer")) + .setErrorMessage("error") + .build(); + public static final Header HEADER = + Header.newBuilder().putFields("key", payload("value")).build(); + public static final Memo MEMO = Memo.newBuilder().putFields("memo", payload("memoValue")).build(); + 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 ClusterReplicationConfiguration CLUSTER_REPLICATION_CONFIGURATION = + ClusterReplicationConfiguration.newBuilder().setClusterName("cluster").build(); + + public static Decision DECISION_SCHEDULE_ACTIVITY_TASK = + Decision.newBuilder() + .setScheduleActivityTaskDecisionAttributes( + ScheduleActivityTaskDecisionAttributes.newBuilder() + .setActivityId("activityId") + .setActivityType(ACTIVITY_TYPE) + .setTaskList(TASK_LIST) + .setInput(payload("input")) + .setScheduleToCloseTimeout(seconds(1)) + .setScheduleToStartTimeout(seconds(2)) + .setStartToCloseTimeout(seconds(3)) + .setHeartbeatTimeout(seconds(4)) + .setHeader(HEADER) + .setRequestLocalDispatch(true) + .setRetryPolicy(RETRY_POLICY) + .setDomain("domain")) + .build(); + public static Decision DECISION_REQUEST_CANCEL_ACTIVITY_TASK = + Decision.newBuilder() + .setRequestCancelActivityTaskDecisionAttributes( + RequestCancelActivityTaskDecisionAttributes.newBuilder().setActivityId("activityId")) + .build(); + public static Decision DECISION_START_TIMER = + Decision.newBuilder() + .setStartTimerDecisionAttributes( + StartTimerDecisionAttributes.newBuilder() + .setTimerId("timerId") + .setStartToFireTimeout(seconds(2))) + .build(); + public static Decision DECISION_COMPLETE_WORKFLOW_EXECUTION = + Decision.newBuilder() + .setCompleteWorkflowExecutionDecisionAttributes( + CompleteWorkflowExecutionDecisionAttributes.newBuilder().setResult(payload("result"))) + .build(); + public static Decision DECISION_FAIL_WORKFLOW_EXECUTION = + Decision.newBuilder() + .setFailWorkflowExecutionDecisionAttributes( + FailWorkflowExecutionDecisionAttributes.newBuilder().setFailure(FAILURE)) + .build(); + public static Decision DECISION_CANCEL_TIMER = + Decision.newBuilder() + .setCancelTimerDecisionAttributes( + CancelTimerDecisionAttributes.newBuilder().setTimerId("timerId")) + .build(); + public static Decision DECISION_CANCEL_WORKFLOW = + Decision.newBuilder() + .setCancelWorkflowExecutionDecisionAttributes( + CancelWorkflowExecutionDecisionAttributes.newBuilder().setDetails(payload("details"))) + .build(); + public static Decision DECISION_REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION = + Decision.newBuilder() + .setRequestCancelExternalWorkflowExecutionDecisionAttributes( + RequestCancelExternalWorkflowExecutionDecisionAttributes.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setChildWorkflowOnly(true) + .setControl(utf8("control"))) + .build(); + public static Decision DECISION_CONTINUE_AS_NEW_WORKFLOW_EXECUTION = + Decision.newBuilder() + .setContinueAsNewWorkflowExecutionDecisionAttributes( + ContinueAsNewWorkflowExecutionDecisionAttributes.newBuilder() + .setWorkflowType(WORKFLOW_TYPE) + .setTaskList(TASK_LIST) + .setInput(payload("input")) + .setExecutionStartToCloseTimeout(seconds(1)) + .setTaskStartToCloseTimeout(seconds(2)) + .setBackoffStartInterval(seconds(3)) + .setInitiator(ContinueAsNewInitiator.CONTINUE_AS_NEW_INITIATOR_DECIDER) + .setFailure(FAILURE) + .setLastCompletionResult(payload("lastCompletionResult")) + .setHeader(HEADER) + .setMemo(MEMO) + .setSearchAttributes(SEARCH_ATTRIBUTES) + .setRetryPolicy(RETRY_POLICY) + .setCronSchedule("cron")) + .build(); + public static Decision DECISION_START_CHILD_WORKFLOW_EXECUTION = + Decision.newBuilder() + .setStartChildWorkflowExecutionDecisionAttributes( + StartChildWorkflowExecutionDecisionAttributes.newBuilder() + .setDomain("domain") + .setWorkflowId("workflowId") + .setWorkflowType(WORKFLOW_TYPE) + .setTaskList(TASK_LIST) + .setInput(payload("input")) + .setExecutionStartToCloseTimeout(seconds(1)) + .setTaskStartToCloseTimeout(seconds(2)) + .setHeader(HEADER) + .setMemo(MEMO) + .setSearchAttributes(SEARCH_ATTRIBUTES) + .setRetryPolicy(RETRY_POLICY) + .setCronSchedule("cron") + .setControl(utf8("control")) + .setParentClosePolicy(ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON) + .setWorkflowIdReusePolicy( + WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE)) + .build(); + public static Decision DECISION_SIGNAL_EXTERNAL_WORKFLOW_EXECUTION = + Decision.newBuilder() + .setSignalExternalWorkflowExecutionDecisionAttributes( + SignalExternalWorkflowExecutionDecisionAttributes.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setSignalName("signalName") + .setInput(payload("input")) + .setChildWorkflowOnly(true) + .setControl(utf8("control"))) + .build(); + public static Decision DECISION_UPSERT_WORKFLOW_SEARCH_ATTRIBUTES = + Decision.newBuilder() + .setUpsertWorkflowSearchAttributesDecisionAttributes( + UpsertWorkflowSearchAttributesDecisionAttributes.newBuilder() + .setSearchAttributes(SEARCH_ATTRIBUTES)) + .build(); + public static Decision DECISION_RECORD_MARKER = + Decision.newBuilder() + .setRecordMarkerDecisionAttributes( + RecordMarkerDecisionAttributes.newBuilder() + .setMarkerName("markerName") + .setDetails(payload("details")) + .setHeader(HEADER)) + .build(); + public static final CountWorkflowExecutionsRequest COUNT_WORKFLOW_EXECUTIONS_REQUEST = + CountWorkflowExecutionsRequest.newBuilder().setDomain("domain").setQuery("query").build(); + public static final DescribeTaskListRequest DESCRIBE_TASK_LIST_REQUEST = + DescribeTaskListRequest.newBuilder() + .setDomain("domain") + .setTaskList(TASK_LIST) + .setTaskListType(TaskListType.TASK_LIST_TYPE_ACTIVITY) + .setIncludeTaskListStatus(true) + .build(); + public static final ListArchivedWorkflowExecutionsRequest + LIST_ARCHIVED_WORKFLOW_EXECUTIONS_REQUEST = + ListArchivedWorkflowExecutionsRequest.newBuilder() + .setDomain("domain") + .setPageSize(1) + .setNextPageToken(utf8("pageToken")) + .setQuery("query") + .build(); + public static final RequestCancelWorkflowExecutionRequest + REQUEST_CANCEL_WORKFLOW_EXECUTION_REQUEST = + RequestCancelWorkflowExecutionRequest.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setRequestId("requestId") + .setIdentity("identity") + .build(); + public static final ResetStickyTaskListRequest RESET_STICKY_TASK_LIST_REQUEST = + ResetStickyTaskListRequest.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .build(); + public static final ResetWorkflowExecutionRequest RESET_WORKFLOW_EXECUTION_REQUEST = + ResetWorkflowExecutionRequest.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setReason("reason") + .setDecisionFinishEventId(1) + .setRequestId("requestId") + .setSkipSignalReapply(true) + .build(); + public static final RespondActivityTaskCanceledByIDRequest + RESPOND_ACTIVITY_TASK_CANCELED_BY_ID_REQUEST = + RespondActivityTaskCanceledByIDRequest.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setActivityId("activityId") + .setDetails(payload("details")) + .setIdentity("identity") + .build(); + public static final RespondActivityTaskCanceledRequest RESPOND_ACTIVITY_TASK_CANCELED_REQUEST = + RespondActivityTaskCanceledRequest.newBuilder() + .setTaskToken(utf8("taskToken")) + .setIdentity("identity") + .setDetails(payload("details")) + .build(); + public static final RespondActivityTaskCompletedByIDRequest + RESPOND_ACTIVITY_TASK_COMPLETED_BY_ID_REQUEST = + RespondActivityTaskCompletedByIDRequest.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setActivityId("activityId") + .setResult(payload("result")) + .setIdentity("identity") + .build(); + public static final RespondActivityTaskCompletedRequest RESPOND_ACTIVITY_TASK_COMPLETED_REQUEST = + RespondActivityTaskCompletedRequest.newBuilder() + .setTaskToken(utf8("taskToken")) + .setIdentity("identity") + .setResult(payload("result")) + .build(); + public static final RespondActivityTaskFailedByIDRequest + RESPOND_ACTIVITY_TASK_FAILED_BY_ID_REQUEST = + RespondActivityTaskFailedByIDRequest.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setActivityId("activityId") + .setFailure(FAILURE) + .setIdentity("identity") + .build(); + public static final RespondActivityTaskFailedRequest RESPOND_ACTIVITY_TASK_FAILED_REQUEST = + RespondActivityTaskFailedRequest.newBuilder() + .setTaskToken(utf8("taskToken")) + .setFailure(FAILURE) + .setIdentity("identity") + .build(); + public static final RespondDecisionTaskCompletedRequest RESPOND_DECISION_TASK_COMPLETED_REQUEST = + RespondDecisionTaskCompletedRequest.newBuilder() + .addAllDecisions(ImmutableList.of(DECISION_COMPLETE_WORKFLOW_EXECUTION)) + .setStickyAttributes(STICKY_EXECUTION_ATTRIBUTES) + .setReturnNewDecisionTask(true) + .setForceCreateNewDecisionTask(false) + .putAllQueryResults(ImmutableMap.of("query", WORKFLOW_QUERY_RESULT)) + .setExecutionContext(utf8("executionContext")) + .setBinaryChecksum("binaryChecksum") + .setTaskToken(utf8("taskToken")) + .setIdentity("identity") + .build(); + public static final RespondDecisionTaskFailedRequest RESPOND_DECISION_TASK_FAILED_REQUEST = + RespondDecisionTaskFailedRequest.newBuilder() + .setCause(DecisionTaskFailedCause.DECISION_TASK_FAILED_CAUSE_BAD_BINARY) + .setDetails(payload("details")) + .setBinaryChecksum("binaryChecksum") + .setTaskToken(utf8("taskToken")) + .setIdentity("identity") + .build(); + public static final RespondQueryTaskCompletedRequest RESPOND_QUERY_TASK_COMPLETED_REQUEST = + RespondQueryTaskCompletedRequest.newBuilder() + .setResult( + WorkflowQueryResult.newBuilder() + .setResultType(QueryResultType.QUERY_RESULT_TYPE_ANSWERED) + .setAnswer(payload("queryResult")) + .setErrorMessage("errorMessage")) + .setWorkerVersionInfo( + WorkerVersionInfo.newBuilder().setFeatureVersion("featureVersion").setImpl("impl")) + .setTaskToken(utf8("taskToken")) + .build(); + public static final ScanWorkflowExecutionsRequest SCAN_WORKFLOW_EXECUTIONS_REQUEST = + ScanWorkflowExecutionsRequest.newBuilder() + .setDomain("domain") + .setPageSize(1) + .setNextPageToken(utf8("nextPageToken")) + .setQuery("query") + .build(); + public static final DescribeWorkflowExecutionRequest DESCRIBE_WORKFLOW_EXECUTION_REQUEST = + DescribeWorkflowExecutionRequest.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .build(); + + public static final GetWorkflowExecutionHistoryRequest GET_WORKFLOW_EXECUTION_HISTORY_REQUEST = + GetWorkflowExecutionHistoryRequest.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setPageSize(1) + .setWaitForNewEvent(true) + .setHistoryEventFilterType(EventFilterType.EVENT_FILTER_TYPE_CLOSE_EVENT) + .setSkipArchival(true) + .setNextPageToken(utf8("nextPageToken")) + .build(); + + public static final StartWorkflowExecutionRequest START_WORKFLOW_EXECUTION = + StartWorkflowExecutionRequest.newBuilder() + .setDomain("domain") + .setWorkflowId("workflowId") + .setWorkflowType(WorkflowType.newBuilder().setName("workflowType")) + .setTaskList(TASK_LIST) + .setInput(payload("input")) + .setExecutionStartToCloseTimeout(seconds(1)) + .setTaskStartToCloseTimeout(seconds(2)) + .setIdentity("identity") + .setRequestId("requestId") + .setWorkflowIdReusePolicy(WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE) + .setRetryPolicy(RETRY_POLICY) + .setCronSchedule("cronSchedule") + .setMemo(MEMO) + .setSearchAttributes(SEARCH_ATTRIBUTES) + .setHeader(HEADER) + .setDelayStart(seconds(3)) + .build(); + + public static final SignalWithStartWorkflowExecutionRequest SIGNAL_WITH_START_WORKFLOW_EXECUTION = + com.uber.cadence.api.v1.SignalWithStartWorkflowExecutionRequest.newBuilder() + .setStartRequest(START_WORKFLOW_EXECUTION) + .setSignalInput(payload("signalInput")) + .setSignalName("signalName") + .setControl(utf8("control")) + .build(); + + public static final StartWorkflowExecutionAsyncRequest START_WORKFLOW_EXECUTION_ASYNC_REQUEST = + StartWorkflowExecutionAsyncRequest.newBuilder().setRequest(START_WORKFLOW_EXECUTION).build(); + + public static final SignalWithStartWorkflowExecutionAsyncRequest + SIGNAL_WITH_START_WORKFLOW_EXECUTION_ASYNC_REQUEST = + SignalWithStartWorkflowExecutionAsyncRequest.newBuilder() + .setRequest(SIGNAL_WITH_START_WORKFLOW_EXECUTION) + .build(); + + public static final SignalWorkflowExecutionRequest SIGNAL_WORKFLOW_EXECUTION_REQUEST = + SignalWorkflowExecutionRequest.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setSignalName("signalName") + .setSignalInput(payload("input")) + .setRequestId("requestId") + .setControl(utf8("control")) + .setIdentity("identity") + .build(); + + public static final TerminateWorkflowExecutionRequest TERMINATE_WORKFLOW_EXECUTION_REQUEST = + TerminateWorkflowExecutionRequest.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setReason("reason") + .setDetails(payload("details")) + .setIdentity("identity") + .build(); + + public static final DeprecateDomainRequest DEPRECATE_DOMAIN_REQUEST = + DeprecateDomainRequest.newBuilder() + .setName("domain") + .setSecurityToken("securityToken") + .build(); + + public static final ListWorkflowExecutionsRequest LIST_WORKFLOW_EXECUTIONS_REQUEST = + ListWorkflowExecutionsRequest.newBuilder() + .setDomain("domain") + .setQuery("query") + .setPageSize(1) + .setNextPageToken(utf8("nextPageToken")) + .build(); + + public static final DescribeDomainRequest DESCRIBE_DOMAIN_BY_ID_REQUEST = + DescribeDomainRequest.newBuilder().setId("uuid").build(); + + public static final DescribeDomainRequest DESCRIBE_DOMAIN_BY_NAME_REQUEST = + DescribeDomainRequest.newBuilder().setName("name").build(); + + public static final ListDomainsRequest LIST_DOMAINS_REQUEST = + ListDomainsRequest.newBuilder() + .setPageSize(1) + .setNextPageToken(utf8("nextPageToken")) + .build(); + + public static final ListTaskListPartitionsRequest LIST_TASK_LIST_PARTITIONS_REQUEST = + ListTaskListPartitionsRequest.newBuilder().setDomain("domain").setTaskList(TASK_LIST).build(); + + public static final PollForActivityTaskRequest POLL_FOR_ACTIVITY_TASK_REQUEST = + PollForActivityTaskRequest.newBuilder() + .setDomain("domain") + .setTaskList(TASK_LIST) + .setTaskListMetadata(TASK_LIST_METADATA) + .setIdentity("identity") + .build(); + public static final PollForDecisionTaskRequest POLL_FOR_DECISION_TASK_REQUEST = + PollForDecisionTaskRequest.newBuilder() + .setDomain("domain") + .setTaskList(TASK_LIST) + .setBinaryChecksum("binaryChecksum") + .setIdentity("identity") + .build(); + public static final QueryWorkflowRequest QUERY_WORKFLOW_REQUEST = + QueryWorkflowRequest.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setQuery(WORKFLOW_QUERY) + .setQueryRejectCondition( + QueryRejectCondition.QUERY_REJECT_CONDITION_NOT_COMPLETED_CLEANLY) + .setQueryConsistencyLevel(QueryConsistencyLevel.QUERY_CONSISTENCY_LEVEL_STRONG) + .build(); + + public static final RecordActivityTaskHeartbeatByIDRequest + RECORD_ACTIVITY_TASK_HEARTBEAT_BY_ID_REQUEST = + RecordActivityTaskHeartbeatByIDRequest.newBuilder() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setActivityId("activityId") + .setDetails(payload("details")) + .setIdentity("identity") + .build(); + + public static final RecordActivityTaskHeartbeatRequest RECORD_ACTIVITY_TASK_HEARTBEAT_REQUEST = + RecordActivityTaskHeartbeatRequest.newBuilder() + .setDetails(payload("details")) + .setTaskToken(utf8("taskToken")) + .setIdentity("identity") + .build(); + + public static final RegisterDomainRequest REGISTER_DOMAIN_REQUEST = + RegisterDomainRequest.newBuilder() + .setName("domain") + .setDescription("description") + .setOwnerEmail("ownerEmail") + .setWorkflowExecutionRetentionPeriod(days(1)) + .addAllClusters(ImmutableList.of(CLUSTER_REPLICATION_CONFIGURATION)) + .setActiveClusterName("activeCluster") + .putAllData(DATA) + .setSecurityToken("securityToken") + .setIsGlobalDomain(true) + .setHistoryArchivalStatus(ArchivalStatus.ARCHIVAL_STATUS_ENABLED) + .setHistoryArchivalUri("historyArchivalUri") + .setVisibilityArchivalStatus(ArchivalStatus.ARCHIVAL_STATUS_DISABLED) + .setVisibilityArchivalUri("visibilityArchivalUri") + .build(); + + public static final UpdateDomainRequest UPDATE_DOMAIN_REQUEST = + UpdateDomainRequest.newBuilder() + .setName("domain") + .setSecurityToken("securityToken") + .setDescription("description") + .setOwnerEmail("ownerEmail") + .setWorkflowExecutionRetentionPeriod(days(2)) + .setBadBinaries( + BadBinaries.newBuilder() + .putBinaries( + "badBinaryKey", + BadBinaryInfo.newBuilder() + .setReason("reason") + .setOperator("operator") + .setCreatedTime(timestampNanos(3)) + .build())) + .setHistoryArchivalStatus(ArchivalStatus.ARCHIVAL_STATUS_ENABLED) + .setHistoryArchivalUri("historyArchivalUri") + .setVisibilityArchivalStatus(ArchivalStatus.ARCHIVAL_STATUS_DISABLED) + .setVisibilityArchivalUri("visibilityArchivalUri") + .setDeleteBadBinary("deleteBadBinary") + .setFailoverTimeout(seconds(1)) + .setUpdateMask( + FieldMask.newBuilder() + .addPaths("description") + .addPaths("owner_email") + .addPaths("data") + .addPaths("workflow_execution_retention_period") + .addPaths("bad_binaries") + .addPaths("history_archival_status") + .addPaths("history_archival_uri") + .addPaths("visibility_archival_status") + .addPaths("visibility_archival_uri") + .addPaths("delete_bad_binary") + .addPaths("failover_timeout") + .build()) + .build(); + + public static final ListClosedWorkflowExecutionsRequest LIST_CLOSED_WORKFLOW_EXECUTIONS_REQUEST = + ListClosedWorkflowExecutionsRequest.newBuilder() + .setDomain("domain") + .setPageSize(1) + .setExecutionFilter( + WorkflowExecutionFilter.newBuilder() + .setWorkflowId(WORKFLOW_EXECUTION.getWorkflowId()) + .setRunId(WORKFLOW_EXECUTION.getRunId())) + .setTypeFilter(WorkflowTypeFilter.newBuilder().setName(WORKFLOW_TYPE.getName())) + .setStatusFilter( + StatusFilter.newBuilder() + .setStatus( + WorkflowExecutionCloseStatus.WORKFLOW_EXECUTION_CLOSE_STATUS_COMPLETED)) + .setNextPageToken(utf8("nextPageToken")) + .setStartTimeFilter( + StartTimeFilter.newBuilder() + .setEarliestTime(timestampNanos(2)) + .setLatestTime(timestampNanos(3))) + .build(); + + public static final ListOpenWorkflowExecutionsRequest LIST_OPEN_WORKFLOW_EXECUTIONS_REQUEST = + ListOpenWorkflowExecutionsRequest.newBuilder() + .setDomain("domain") + .setPageSize(1) + .setExecutionFilter( + WorkflowExecutionFilter.newBuilder() + .setWorkflowId(WORKFLOW_EXECUTION.getWorkflowId()) + .setRunId(WORKFLOW_EXECUTION.getRunId())) + .setTypeFilter(WorkflowTypeFilter.newBuilder().setName(WORKFLOW_TYPE.getName())) + .setNextPageToken(utf8("nextPageToken")) + .setStartTimeFilter( + StartTimeFilter.newBuilder() + .setEarliestTime(timestampNanos(2)) + .setLatestTime(timestampNanos(3))) + .build(); + + private ProtoObjects() {} + + private static Payload payload(String value) { + return Payload.newBuilder().setData(utf8(value)).build(); + } + + private static Duration seconds(int value) { + return Duration.newBuilder().setSeconds(value).build(); + } + + private static Duration days(int value) { + return Duration.newBuilder().setSeconds(((long) value) * 24 * 60 * 60).build(); + } + + private static Timestamp timestampNanos(int value) { + return Timestamp.newBuilder().setNanos(value).build(); + } + + private static ByteString utf8(String value) { + return ByteString.copyFromUtf8(value); + } +} diff --git a/src/test/java/com/uber/cadence/internal/compatibility/ThriftObjects.java b/src/test/java/com/uber/cadence/internal/compatibility/ThriftObjects.java new file mode 100644 index 000000000..d3269daa1 --- /dev/null +++ b/src/test/java/com/uber/cadence/internal/compatibility/ThriftObjects.java @@ -0,0 +1,497 @@ +package com.uber.cadence.internal.compatibility; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.uber.cadence.*; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.Map; + +public final class ThriftObjects { + public static final WorkflowType WORKFLOW_TYPE = + new com.uber.cadence.WorkflowType().setName("workflowType"); + public static final ActivityType ACTIVITY_TYPE = new ActivityType().setName("activityName"); + public static final TaskList TASK_LIST = + new com.uber.cadence.TaskList() + .setName("taskList") + .setKind(com.uber.cadence.TaskListKind.NORMAL); + public static final TaskListMetadata TASK_LIST_METADATA = + new TaskListMetadata().setMaxTasksPerSecond(10); + public static final RetryPolicy RETRY_POLICY = + new com.uber.cadence.RetryPolicy() + .setInitialIntervalInSeconds(11) + .setBackoffCoefficient(0.5) + .setMaximumIntervalInSeconds(12) + .setMaximumAttempts(13) + .setNonRetriableErrorReasons(ImmutableList.of("error")) + .setExpirationIntervalInSeconds(14); + public static final String WORKFLOW_ID = "workflowId"; + public static final String RUN_ID = "runId"; + public static final WorkflowExecution WORKFLOW_EXECUTION = + new WorkflowExecution().setWorkflowId(WORKFLOW_ID).setRunId(RUN_ID); + public static final StickyExecutionAttributes STICKY_EXECUTION_ATTRIBUTES = + new StickyExecutionAttributes() + .setWorkerTaskList(TASK_LIST) + .setScheduleToStartTimeoutSeconds(1); + public static final WorkflowQuery WORKFLOW_QUERY = + new WorkflowQuery().setQueryType("queryType").setQueryArgs(utf8("queryArgs")); + public static final WorkflowQueryResult WORKFLOW_QUERY_RESULT = + new WorkflowQueryResult() + .setResultType(QueryResultType.ANSWERED) + .setAnswer(utf8("answer")) + .setErrorMessage("error"); + public static final Header HEADER = new Header().setFields(ImmutableMap.of("key", utf8("value"))); + public static final Memo MEMO = new Memo().setFields(ImmutableMap.of("memo", utf8("memoValue"))); + 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 ClusterReplicationConfiguration CLUSTER_REPLICATION_CONFIGURATION = + new ClusterReplicationConfiguration().setClusterName("cluster"); + + public static Decision DECISION_SCHEDULE_ACTIVITY_TASK = + new Decision() + .setDecisionType(DecisionType.ScheduleActivityTask) + .setScheduleActivityTaskDecisionAttributes( + new ScheduleActivityTaskDecisionAttributes() + .setActivityId("activityId") + .setActivityType(ACTIVITY_TYPE) + .setTaskList(TASK_LIST) + .setInput(utf8("input")) + .setScheduleToCloseTimeoutSeconds(1) + .setScheduleToStartTimeoutSeconds(2) + .setStartToCloseTimeoutSeconds(3) + .setHeartbeatTimeoutSeconds(4) + .setHeader(HEADER) + .setRequestLocalDispatch(true) + .setRetryPolicy(RETRY_POLICY) + .setDomain("domain")); + public static Decision DECISION_REQUEST_CANCEL_ACTIVITY_TASK = + new Decision() + .setDecisionType(DecisionType.RequestCancelActivityTask) + .setRequestCancelActivityTaskDecisionAttributes( + new RequestCancelActivityTaskDecisionAttributes().setActivityId("activityId")); + public static Decision DECISION_START_TIMER = + new Decision() + .setDecisionType(DecisionType.StartTimer) + .setStartTimerDecisionAttributes( + new StartTimerDecisionAttributes() + .setTimerId("timerId") + .setStartToFireTimeoutSeconds(2)); + public static Decision DECISION_COMPLETE_WORKFLOW_EXECUTION = + new Decision() + .setDecisionType(DecisionType.CompleteWorkflowExecution) + .setCompleteWorkflowExecutionDecisionAttributes( + new CompleteWorkflowExecutionDecisionAttributes().setResult(utf8("result"))); + public static Decision DECISION_FAIL_WORKFLOW_EXECUTION = + new Decision() + .setDecisionType(DecisionType.FailWorkflowExecution) + .setFailWorkflowExecutionDecisionAttributes( + new FailWorkflowExecutionDecisionAttributes() + .setReason("reason") + .setDetails(utf8("details"))); + public static Decision DECISION_CANCEL_TIMER = + new Decision() + .setDecisionType(DecisionType.CancelTimer) + .setCancelTimerDecisionAttributes( + new CancelTimerDecisionAttributes().setTimerId("timerId")); + public static Decision DECISION_CANCEL_WORKFLOW = + new Decision() + .setDecisionType(DecisionType.CancelWorkflowExecution) + .setCancelWorkflowExecutionDecisionAttributes( + new CancelWorkflowExecutionDecisionAttributes().setDetails(utf8("details"))); + public static Decision DECISION_REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION = + new Decision() + .setDecisionType(DecisionType.RequestCancelExternalWorkflowExecution) + .setRequestCancelExternalWorkflowExecutionDecisionAttributes( + new RequestCancelExternalWorkflowExecutionDecisionAttributes() + .setDomain("domain") + .setWorkflowId(WORKFLOW_ID) + .setRunId(RUN_ID) + .setChildWorkflowOnly(true) + .setControl(utf8("control"))); + public static Decision DECISION_CONTINUE_AS_NEW_WORKFLOW_EXECUTION = + new Decision() + .setDecisionType(DecisionType.ContinueAsNewWorkflowExecution) + .setContinueAsNewWorkflowExecutionDecisionAttributes( + new ContinueAsNewWorkflowExecutionDecisionAttributes() + .setWorkflowType(WORKFLOW_TYPE) + .setTaskList(TASK_LIST) + .setInput(utf8("input")) + .setExecutionStartToCloseTimeoutSeconds(1) + .setTaskStartToCloseTimeoutSeconds(2) + .setBackoffStartIntervalInSeconds(3) + .setInitiator(ContinueAsNewInitiator.Decider) + .setFailureDetails(utf8("details")) + .setFailureReason("reason") + .setLastCompletionResult(utf8("lastCompletionResult")) + .setHeader(HEADER) + .setMemo(MEMO) + .setSearchAttributes(SEARCH_ATTRIBUTES) + .setRetryPolicy(RETRY_POLICY) + .setCronSchedule("cron")); + public static Decision DECISION_START_CHILD_WORKFLOW_EXECUTION = + new Decision() + .setDecisionType(DecisionType.StartChildWorkflowExecution) + .setStartChildWorkflowExecutionDecisionAttributes( + new StartChildWorkflowExecutionDecisionAttributes() + .setDomain("domain") + .setWorkflowId(WORKFLOW_ID) + .setWorkflowType(WORKFLOW_TYPE) + .setTaskList(TASK_LIST) + .setInput(utf8("input")) + .setExecutionStartToCloseTimeoutSeconds(1) + .setTaskStartToCloseTimeoutSeconds(2) + .setHeader(HEADER) + .setMemo(MEMO) + .setSearchAttributes(SEARCH_ATTRIBUTES) + .setRetryPolicy(RETRY_POLICY) + .setCronSchedule("cron") + .setControl(utf8("control")) + .setParentClosePolicy(ParentClosePolicy.ABANDON) + .setWorkflowIdReusePolicy(WorkflowIdReusePolicy.AllowDuplicate)); + public static Decision DECISION_SIGNAL_EXTERNAL_WORKFLOW_EXECUTION = + new Decision() + .setDecisionType(DecisionType.SignalExternalWorkflowExecution) + .setSignalExternalWorkflowExecutionDecisionAttributes( + new SignalExternalWorkflowExecutionDecisionAttributes() + .setDomain("domain") + .setExecution(WORKFLOW_EXECUTION) + .setSignalName("signalName") + .setInput(utf8("input")) + .setChildWorkflowOnly(true) + .setControl(utf8("control"))); + public static Decision DECISION_UPSERT_WORKFLOW_SEARCH_ATTRIBUTES = + new Decision() + .setDecisionType(DecisionType.UpsertWorkflowSearchAttributes) + .setUpsertWorkflowSearchAttributesDecisionAttributes( + new UpsertWorkflowSearchAttributesDecisionAttributes() + .setSearchAttributes(SEARCH_ATTRIBUTES)); + public static Decision DECISION_RECORD_MARKER = + new Decision() + .setDecisionType(DecisionType.RecordMarker) + .setRecordMarkerDecisionAttributes( + new RecordMarkerDecisionAttributes() + .setMarkerName("markerName") + .setDetails(utf8("details")) + .setHeader(HEADER)); + public static final CountWorkflowExecutionsRequest COUNT_WORKFLOW_EXECUTIONS_REQUEST = + new CountWorkflowExecutionsRequest().setDomain("domain").setQuery("query"); + public static final DescribeTaskListRequest DESCRIBE_TASK_LIST_REQUEST = + new DescribeTaskListRequest() + .setDomain("domain") + .setTaskList(TASK_LIST) + .setTaskListType(TaskListType.Activity) + .setIncludeTaskListStatus(true); + public static final ListArchivedWorkflowExecutionsRequest + LIST_ARCHIVED_WORKFLOW_EXECUTIONS_REQUEST = + new ListArchivedWorkflowExecutionsRequest() + .setDomain("domain") + .setPageSize(1) + .setNextPageToken(utf8Bytes("pageToken")) + .setQuery("query"); + public static final RequestCancelWorkflowExecutionRequest + REQUEST_CANCEL_WORKFLOW_EXECUTION_REQUEST = + new RequestCancelWorkflowExecutionRequest() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setRequestId("requestId") + .setIdentity("identity"); + public static final ResetStickyTaskListRequest RESET_STICKY_TASK_LIST_REQUEST = + new ResetStickyTaskListRequest().setDomain("domain").setExecution(WORKFLOW_EXECUTION); + public static final ResetWorkflowExecutionRequest RESET_WORKFLOW_EXECUTION_REQUEST = + new ResetWorkflowExecutionRequest() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setReason("reason") + .setDecisionFinishEventId(1) + .setRequestId("requestId") + .setSkipSignalReapply(true); + public static final RespondActivityTaskCanceledByIDRequest + RESPOND_ACTIVITY_TASK_CANCELED_BY_ID_REQUEST = + new RespondActivityTaskCanceledByIDRequest() + .setDomain("domain") + .setWorkflowID(WORKFLOW_ID) + .setRunID(RUN_ID) + .setActivityID("activityId") + .setDetails(utf8("details")) + .setIdentity("identity"); + public static final RespondActivityTaskCanceledRequest RESPOND_ACTIVITY_TASK_CANCELED_REQUEST = + new com.uber.cadence.RespondActivityTaskCanceledRequest() + .setTaskToken(utf8("taskToken")) + .setDetails(utf8("details")) + .setIdentity("identity"); + public static final RespondActivityTaskCompletedByIDRequest + RESPOND_ACTIVITY_TASK_COMPLETED_BY_ID_REQUEST = + new RespondActivityTaskCompletedByIDRequest() + .setDomain("domain") + .setWorkflowID(WORKFLOW_ID) + .setRunID(RUN_ID) + .setActivityID("activityId") + .setResult(utf8("result")) + .setIdentity("identity"); + public static final RespondActivityTaskCompletedRequest RESPOND_ACTIVITY_TASK_COMPLETED_REQUEST = + new RespondActivityTaskCompletedRequest() + .setTaskToken(utf8("taskToken")) + .setIdentity("identity") + .setResult(utf8("result")); + public static final RespondActivityTaskFailedByIDRequest + RESPOND_ACTIVITY_TASK_FAILED_BY_ID_REQUEST = + new RespondActivityTaskFailedByIDRequest() + .setDomain("domain") + .setWorkflowID(WORKFLOW_ID) + .setRunID(RUN_ID) + .setActivityID("activityId") + .setReason("reason") + .setDetails(utf8("details")) + .setIdentity("identity"); + public static final RespondActivityTaskFailedRequest RESPOND_ACTIVITY_TASK_FAILED_REQUEST = + new RespondActivityTaskFailedRequest() + .setTaskToken(utf8("taskToken")) + .setDetails(utf8("details")) + .setReason("reason") + .setIdentity("identity"); + public static final RespondDecisionTaskCompletedRequest RESPOND_DECISION_TASK_COMPLETED_REQUEST = + new RespondDecisionTaskCompletedRequest() + .setDecisions(ImmutableList.of(DECISION_COMPLETE_WORKFLOW_EXECUTION)) + .setStickyAttributes(STICKY_EXECUTION_ATTRIBUTES) + .setReturnNewDecisionTask(true) + .setForceCreateNewDecisionTask(false) + .setQueryResults(ImmutableMap.of("query", WORKFLOW_QUERY_RESULT)) + .setExecutionContext(utf8("executionContext")) + .setBinaryChecksum("binaryChecksum") + .setTaskToken(utf8("taskToken")) + .setIdentity("identity"); + public static final RespondDecisionTaskFailedRequest RESPOND_DECISION_TASK_FAILED_REQUEST = + new RespondDecisionTaskFailedRequest() + .setCause(DecisionTaskFailedCause.BAD_BINARY) + .setDetails(utf8("details")) + .setBinaryChecksum("binaryChecksum") + .setTaskToken(utf8("taskToken")) + .setIdentity("identity"); + public static final RespondQueryTaskCompletedRequest RESPOND_QUERY_TASK_COMPLETED_REQUEST = + new RespondQueryTaskCompletedRequest() + .setCompletedType(QueryTaskCompletedType.COMPLETED) + .setQueryResult(utf8("queryResult")) + .setErrorMessage("errorMessage") + .setWorkerVersionInfo( + new WorkerVersionInfo().setFeatureVersion("featureVersion").setImpl("impl")) + .setTaskToken(utf8("taskToken")); + + public static final ListWorkflowExecutionsRequest LIST_WORKFLOW_EXECUTIONS_REQUEST = + new ListWorkflowExecutionsRequest() + .setDomain("domain") + .setPageSize(1) + .setNextPageToken(utf8("nextPageToken")) + .setQuery("query"); + + public static final DescribeWorkflowExecutionRequest DESCRIBE_WORKFLOW_EXECUTION_REQUEST = + new DescribeWorkflowExecutionRequest().setDomain("domain").setExecution(WORKFLOW_EXECUTION); + + public static final GetWorkflowExecutionHistoryRequest GET_WORKFLOW_EXECUTION_HISTORY_REQUEST = + new GetWorkflowExecutionHistoryRequest() + .setDomain("domain") + .setExecution(WORKFLOW_EXECUTION) + .setMaximumPageSize(1) + .setWaitForNewEvent(true) + .setHistoryEventFilterType(HistoryEventFilterType.CLOSE_EVENT) + .setSkipArchival(true) + .setNextPageToken(utf8("nextPageToken")); + + public static final com.uber.cadence.StartWorkflowExecutionRequest START_WORKFLOW_EXECUTION = + new com.uber.cadence.StartWorkflowExecutionRequest() + .setDomain("domain") + .setWorkflowId(WORKFLOW_ID) + .setWorkflowType(WORKFLOW_TYPE) + .setTaskList(TASK_LIST) + .setInput("input".getBytes(StandardCharsets.UTF_8)) + .setExecutionStartToCloseTimeoutSeconds(1) + .setTaskStartToCloseTimeoutSeconds(2) + .setIdentity("identity") + .setRequestId("requestId") + .setWorkflowIdReusePolicy(com.uber.cadence.WorkflowIdReusePolicy.AllowDuplicate) + .setRetryPolicy(RETRY_POLICY) + .setCronSchedule("cronSchedule") + .setMemo(MEMO) + .setSearchAttributes(SEARCH_ATTRIBUTES) + .setHeader(HEADER) + .setDelayStartSeconds(3); + public static final com.uber.cadence.SignalWithStartWorkflowExecutionRequest + SIGNAL_WITH_START_WORKFLOW_EXECUTION = + new SignalWithStartWorkflowExecutionRequest() + .setDomain("domain") + .setWorkflowId(WORKFLOW_ID) + .setWorkflowType(WORKFLOW_TYPE) + .setTaskList(TASK_LIST) + .setInput("input".getBytes(StandardCharsets.UTF_8)) + .setExecutionStartToCloseTimeoutSeconds(1) + .setTaskStartToCloseTimeoutSeconds(2) + .setIdentity("identity") + .setRequestId("requestId") + .setWorkflowIdReusePolicy(com.uber.cadence.WorkflowIdReusePolicy.AllowDuplicate) + .setSignalName("signalName") + .setSignalInput("signalInput".getBytes(StandardCharsets.UTF_8)) + .setControl("control".getBytes(StandardCharsets.UTF_8)) + .setRetryPolicy(RETRY_POLICY) + .setCronSchedule("cronSchedule") + .setMemo(MEMO) + .setSearchAttributes(SEARCH_ATTRIBUTES) + .setHeader(HEADER) + .setDelayStartSeconds(3); + + public static final StartWorkflowExecutionAsyncRequest START_WORKFLOW_EXECUTION_ASYNC_REQUEST = + new StartWorkflowExecutionAsyncRequest().setRequest(START_WORKFLOW_EXECUTION); + + public static final SignalWithStartWorkflowExecutionAsyncRequest + SIGNAL_WITH_START_WORKFLOW_EXECUTION_ASYNC_REQUEST = + new SignalWithStartWorkflowExecutionAsyncRequest() + .setRequest(SIGNAL_WITH_START_WORKFLOW_EXECUTION); + + public static final SignalWorkflowExecutionRequest SIGNAL_WORKFLOW_EXECUTION_REQUEST = + new SignalWorkflowExecutionRequest() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setSignalName("signalName") + .setInput(utf8("input")) + .setRequestId("requestId") + .setControl(utf8("control")) + .setIdentity("identity"); + + public static final TerminateWorkflowExecutionRequest TERMINATE_WORKFLOW_EXECUTION_REQUEST = + new TerminateWorkflowExecutionRequest() + .setDomain("domain") + .setWorkflowExecution(WORKFLOW_EXECUTION) + .setReason("reason") + .setDetails(utf8("details")) + .setIdentity("identity"); + + public static final DeprecateDomainRequest DEPRECATE_DOMAIN_REQUEST = + new DeprecateDomainRequest().setName("domain").setSecurityToken("securityToken"); + + public static final DescribeDomainRequest DESCRIBE_DOMAIN_BY_ID_REQUEST = + new DescribeDomainRequest().setUuid("uuid"); + + public static final DescribeDomainRequest DESCRIBE_DOMAIN_BY_NAME_REQUEST = + new DescribeDomainRequest().setName("name"); + + public static final ListDomainsRequest LIST_DOMAINS_REQUEST = + new ListDomainsRequest().setPageSize(1).setNextPageToken(utf8("nextPageToken")); + + public static final ListTaskListPartitionsRequest LIST_TASK_LIST_PARTITIONS_REQUEST = + new ListTaskListPartitionsRequest().setDomain("domain").setTaskList(TASK_LIST); + + public static final PollForActivityTaskRequest POLL_FOR_ACTIVITY_TASK_REQUEST = + new PollForActivityTaskRequest() + .setDomain("domain") + .setTaskList(TASK_LIST) + .setTaskListMetadata(TASK_LIST_METADATA) + .setIdentity("identity"); + public static final PollForDecisionTaskRequest POLL_FOR_DECISION_TASK_REQUEST = + new PollForDecisionTaskRequest() + .setDomain("domain") + .setTaskList(TASK_LIST) + .setBinaryChecksum("binaryChecksum") + .setIdentity("identity"); + public static final QueryWorkflowRequest QUERY_WORKFLOW_REQUEST = + new QueryWorkflowRequest() + .setDomain("domain") + .setExecution(WORKFLOW_EXECUTION) + .setQuery(WORKFLOW_QUERY) + .setQueryRejectCondition(QueryRejectCondition.NOT_COMPLETED_CLEANLY) + .setQueryConsistencyLevel(QueryConsistencyLevel.STRONG); + + public static final RecordActivityTaskHeartbeatByIDRequest + RECORD_ACTIVITY_TASK_HEARTBEAT_BY_ID_REQUEST = + new RecordActivityTaskHeartbeatByIDRequest() + .setDomain("domain") + .setWorkflowID(WORKFLOW_ID) + .setRunID(RUN_ID) + .setActivityID("activityId") + .setDetails(utf8("details")) + .setIdentity("identity"); + + public static final RecordActivityTaskHeartbeatRequest RECORD_ACTIVITY_TASK_HEARTBEAT_REQUEST = + new RecordActivityTaskHeartbeatRequest() + .setDetails(utf8("details")) + .setTaskToken(utf8("taskToken")) + .setIdentity("identity"); + + public static final RegisterDomainRequest REGISTER_DOMAIN_REQUEST = + new RegisterDomainRequest() + .setName("domain") + .setDescription("description") + .setOwnerEmail("ownerEmail") + .setWorkflowExecutionRetentionPeriodInDays(1) + .setClusters(ImmutableList.of(CLUSTER_REPLICATION_CONFIGURATION)) + .setActiveClusterName("activeCluster") + .setData(DATA) + .setSecurityToken("securityToken") + .setIsGlobalDomain(true) + .setHistoryArchivalStatus(ArchivalStatus.ENABLED) + .setHistoryArchivalURI("historyArchivalUri") + .setVisibilityArchivalStatus(ArchivalStatus.DISABLED) + .setVisibilityArchivalURI("visibilityArchivalUri"); + + public static final UpdateDomainRequest UPDATE_DOMAIN_REQUEST = + new UpdateDomainRequest() + .setName("domain") + .setSecurityToken("securityToken") + .setUpdatedInfo( + new UpdateDomainInfo() + .setData(DATA) + .setDescription("description") + .setOwnerEmail("ownerEmail")) + .setReplicationConfiguration( + new DomainReplicationConfiguration() + .setActiveClusterName("activeCluster") + .setClusters(ImmutableList.of(CLUSTER_REPLICATION_CONFIGURATION))) + .setConfiguration( + new DomainConfiguration() + .setWorkflowExecutionRetentionPeriodInDays(2) + .setBadBinaries( + new BadBinaries() + .setBinaries( + ImmutableMap.of( + "badBinaryKey", + new BadBinaryInfo() + .setReason("reason") + .setOperator("operator") + .setCreatedTimeNano(3)))) + .setHistoryArchivalStatus(ArchivalStatus.ENABLED) + .setHistoryArchivalURI("historyArchivalUri") + .setVisibilityArchivalStatus(ArchivalStatus.DISABLED) + .setVisibilityArchivalURI("visibilityArchivalUri")) + .setDeleteBadBinary("deleteBadBinary") + .setFailoverTimeoutInSeconds(1); + + public static final ListClosedWorkflowExecutionsRequest LIST_CLOSED_WORKFLOW_EXECUTIONS_REQUEST = + new ListClosedWorkflowExecutionsRequest() + .setDomain("domain") + .setMaximumPageSize(1) + .setExecutionFilter( + new WorkflowExecutionFilter().setWorkflowId(WORKFLOW_ID).setRunId(RUN_ID)) + .setTypeFilter(new WorkflowTypeFilter().setName(WORKFLOW_TYPE.getName())) + .setStatusFilter(WorkflowExecutionCloseStatus.COMPLETED) + .setNextPageToken(utf8("nextPageToken")) + .setStartTimeFilter(new StartTimeFilter().setEarliestTime(2).setLatestTime(3)); + + public static final ListOpenWorkflowExecutionsRequest LIST_OPEN_WORKFLOW_EXECUTIONS_REQUEST = + new ListOpenWorkflowExecutionsRequest() + .setDomain("domain") + .setMaximumPageSize(1) + .setExecutionFilter( + new WorkflowExecutionFilter().setWorkflowId(WORKFLOW_ID).setRunId(RUN_ID)) + .setTypeFilter(new WorkflowTypeFilter().setName(WORKFLOW_TYPE.getName())) + .setNextPageToken(utf8("nextPageToken")) + .setStartTimeFilter(new StartTimeFilter().setEarliestTime(2).setLatestTime(3)); + + private ThriftObjects() {} + + public static ByteBuffer utf8(String value) { + return ByteBuffer.wrap(utf8Bytes(value)); + } + + public static byte[] utf8Bytes(String value) { + return value.getBytes(StandardCharsets.UTF_8); + } +} diff --git a/src/test/java/com/uber/cadence/internal/compatibility/proto/DecisionMapperTest.java b/src/test/java/com/uber/cadence/internal/compatibility/proto/DecisionMapperTest.java new file mode 100644 index 000000000..163d64858 --- /dev/null +++ b/src/test/java/com/uber/cadence/internal/compatibility/proto/DecisionMapperTest.java @@ -0,0 +1,128 @@ +package com.uber.cadence.internal.compatibility.proto; + +import static com.uber.cadence.internal.compatibility.MapperTestUtil.assertMissingFields; +import static com.uber.cadence.internal.compatibility.MapperTestUtil.assertNoMissingFields; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Sets; +import com.uber.cadence.Decision; +import com.uber.cadence.DecisionType; +import com.uber.cadence.internal.compatibility.ProtoObjects; +import com.uber.cadence.internal.compatibility.ThriftObjects; +import java.util.Collections; +import java.util.EnumSet; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import org.junit.Assert; +import org.junit.Test; + +public class DecisionMapperTest { + private static final Map DECISIONS = + ImmutableMap.builder() + .put( + ThriftObjects.DECISION_SCHEDULE_ACTIVITY_TASK, + ProtoObjects.DECISION_SCHEDULE_ACTIVITY_TASK) + .put( + ThriftObjects.DECISION_REQUEST_CANCEL_ACTIVITY_TASK, + ProtoObjects.DECISION_REQUEST_CANCEL_ACTIVITY_TASK) + .put(ThriftObjects.DECISION_START_TIMER, ProtoObjects.DECISION_START_TIMER) + .put( + ThriftObjects.DECISION_COMPLETE_WORKFLOW_EXECUTION, + ProtoObjects.DECISION_COMPLETE_WORKFLOW_EXECUTION) + .put( + ThriftObjects.DECISION_FAIL_WORKFLOW_EXECUTION, + ProtoObjects.DECISION_FAIL_WORKFLOW_EXECUTION) + .put(ThriftObjects.DECISION_CANCEL_TIMER, ProtoObjects.DECISION_CANCEL_TIMER) + .put(ThriftObjects.DECISION_CANCEL_WORKFLOW, ProtoObjects.DECISION_CANCEL_WORKFLOW) + .put( + ThriftObjects.DECISION_REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION, + ProtoObjects.DECISION_REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION) + .put( + ThriftObjects.DECISION_CONTINUE_AS_NEW_WORKFLOW_EXECUTION, + ProtoObjects.DECISION_CONTINUE_AS_NEW_WORKFLOW_EXECUTION) + .put( + ThriftObjects.DECISION_START_CHILD_WORKFLOW_EXECUTION, + ProtoObjects.DECISION_START_CHILD_WORKFLOW_EXECUTION) + .put( + ThriftObjects.DECISION_SIGNAL_EXTERNAL_WORKFLOW_EXECUTION, + ProtoObjects.DECISION_SIGNAL_EXTERNAL_WORKFLOW_EXECUTION) + .put( + ThriftObjects.DECISION_UPSERT_WORKFLOW_SEARCH_ATTRIBUTES, + ProtoObjects.DECISION_UPSERT_WORKFLOW_SEARCH_ATTRIBUTES) + .put(ThriftObjects.DECISION_RECORD_MARKER, ProtoObjects.DECISION_RECORD_MARKER) + .build(); + + @Test + public void testMapDecision() { + for (Map.Entry entry : DECISIONS.entrySet()) { + Assert.assertEquals( + "Failed to convert decision of type: " + entry.getKey().getDecisionType(), + entry.getValue(), + DecisionMapper.decision(entry.getKey())); + } + } + + @Test + public void testAllDecisionTypesCovered() { + // If IDL changes add a new decision type, this should fail + Set expected = EnumSet.allOf(DecisionType.class); + Set actual = + DECISIONS.keySet().stream().map(Decision::getDecisionType).collect(Collectors.toSet()); + + Assert.assertEquals( + "Missing conversion for some DecisionTypes", + Collections.emptySet(), + Sets.difference(expected, actual)); + } + + @Test + public void testAllAttributesSet() { + // If IDL changes add a new field to decision attributes, this should fail + for (Map.Entry entry : DECISIONS.entrySet()) { + Decision decision = entry.getKey(); + switch (decision.decisionType) { + case ScheduleActivityTask: + assertNoMissingFields(decision.scheduleActivityTaskDecisionAttributes); + break; + case RequestCancelActivityTask: + assertNoMissingFields(decision.requestCancelActivityTaskDecisionAttributes); + break; + case StartTimer: + assertNoMissingFields(decision.startTimerDecisionAttributes); + break; + case CompleteWorkflowExecution: + assertNoMissingFields(decision.completeWorkflowExecutionDecisionAttributes); + break; + case FailWorkflowExecution: + assertNoMissingFields(decision.failWorkflowExecutionDecisionAttributes); + break; + case CancelTimer: + assertNoMissingFields(decision.cancelTimerDecisionAttributes); + break; + case CancelWorkflowExecution: + assertNoMissingFields(decision.cancelWorkflowExecutionDecisionAttributes); + break; + case RequestCancelExternalWorkflowExecution: + assertNoMissingFields(decision.requestCancelExternalWorkflowExecutionDecisionAttributes); + break; + case RecordMarker: + assertNoMissingFields(decision.recordMarkerDecisionAttributes); + break; + case ContinueAsNewWorkflowExecution: + assertMissingFields( + decision.continueAsNewWorkflowExecutionDecisionAttributes, "jitterStartSeconds"); + break; + case StartChildWorkflowExecution: + assertNoMissingFields(decision.startChildWorkflowExecutionDecisionAttributes); + break; + case SignalExternalWorkflowExecution: + assertNoMissingFields(decision.signalExternalWorkflowExecutionDecisionAttributes); + break; + case UpsertWorkflowSearchAttributes: + assertNoMissingFields(decision.upsertWorkflowSearchAttributesDecisionAttributes); + break; + } + } + } +} diff --git a/src/test/java/com/uber/cadence/internal/compatibility/proto/RequestMapperTest.java b/src/test/java/com/uber/cadence/internal/compatibility/proto/RequestMapperTest.java index e5ba36361..d560e2caf 100644 --- a/src/test/java/com/uber/cadence/internal/compatibility/proto/RequestMapperTest.java +++ b/src/test/java/com/uber/cadence/internal/compatibility/proto/RequestMapperTest.java @@ -20,219 +20,237 @@ import static com.uber.cadence.internal.compatibility.MapperTestUtil.assertMissingFields; import static com.uber.cadence.internal.compatibility.MapperTestUtil.assertNoMissingFields; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.protobuf.ByteString; -import com.google.protobuf.Duration; -import com.uber.cadence.SignalWithStartWorkflowExecutionRequest; -import com.uber.cadence.api.v1.Header; -import com.uber.cadence.api.v1.Memo; -import com.uber.cadence.api.v1.Payload; -import com.uber.cadence.api.v1.RetryPolicy; -import com.uber.cadence.api.v1.SearchAttributes; -import com.uber.cadence.api.v1.SignalWithStartWorkflowExecutionAsyncRequest; -import com.uber.cadence.api.v1.StartWorkflowExecutionAsyncRequest; -import com.uber.cadence.api.v1.StartWorkflowExecutionRequest; -import com.uber.cadence.api.v1.TaskList; -import com.uber.cadence.api.v1.TaskListKind; -import com.uber.cadence.api.v1.WorkflowIdReusePolicy; -import com.uber.cadence.api.v1.WorkflowType; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; +import com.google.common.collect.ImmutableSet; +import com.google.protobuf.Message; +import com.uber.cadence.internal.compatibility.ProtoObjects; +import com.uber.cadence.internal.compatibility.ThriftObjects; +import java.util.Arrays; +import java.util.Set; +import java.util.function.Function; +import org.apache.thrift.TBase; +import org.apache.thrift.TFieldIdEnum; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; -public class RequestMapperTest { +@RunWith(Parameterized.class) +public class RequestMapperTest< + F extends Enum & TFieldIdEnum, T extends TBase, P extends Message> { - // These are shared between testStartWorkflowExecutionRequest and - // testStartWorkflowExecutionAsyncRequest - // because the mapper throws an exception if necessary fields are missing - private static final com.uber.cadence.StartWorkflowExecutionRequest - THRIFT_START_WORKFLOW_EXECUTION = - new com.uber.cadence.StartWorkflowExecutionRequest() - .setDomain("domain") - .setWorkflowId("workflowId") - .setWorkflowType(new com.uber.cadence.WorkflowType().setName("workflowType")) - .setTaskList( - new com.uber.cadence.TaskList() - .setName("taskList") - .setKind(com.uber.cadence.TaskListKind.NORMAL)) - .setInput("input".getBytes(StandardCharsets.UTF_8)) - .setExecutionStartToCloseTimeoutSeconds(1) - .setTaskStartToCloseTimeoutSeconds(2) - .setIdentity("identity") - .setRequestId("requestId") - .setWorkflowIdReusePolicy(com.uber.cadence.WorkflowIdReusePolicy.AllowDuplicate) - .setRetryPolicy( - new com.uber.cadence.RetryPolicy() - .setInitialIntervalInSeconds(11) - .setBackoffCoefficient(0.5) - .setMaximumIntervalInSeconds(12) - .setMaximumAttempts(13) - .setNonRetriableErrorReasons(ImmutableList.of("error")) - .setExpirationIntervalInSeconds(14)) - .setCronSchedule("cronSchedule") - .setMemo( - new com.uber.cadence.Memo().setFields(ImmutableMap.of("memo", utf8("memoValue")))) - .setSearchAttributes( - new com.uber.cadence.SearchAttributes() - .setIndexedFields(ImmutableMap.of("search", utf8("searchValue")))) - .setHeader( - new com.uber.cadence.Header().setFields(ImmutableMap.of("key", utf8("value")))) - .setDelayStartSeconds(3); - private static final com.uber.cadence.api.v1.StartWorkflowExecutionRequest - PROTO_START_WORKFLOW_EXECUTION = - StartWorkflowExecutionRequest.newBuilder() - .setDomain("domain") - .setWorkflowId("workflowId") - .setWorkflowType(WorkflowType.newBuilder().setName("workflowType")) - .setTaskList( - TaskList.newBuilder() - .setName("taskList") - .setKind(TaskListKind.TASK_LIST_KIND_NORMAL)) - .setInput(protoPayload("input")) - .setExecutionStartToCloseTimeout(seconds(1)) - .setTaskStartToCloseTimeout(seconds(2)) - .setIdentity("identity") - .setRequestId("requestId") - .setWorkflowIdReusePolicy( - WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE) - .setRetryPolicy( - RetryPolicy.newBuilder() - .setInitialInterval(seconds(11)) - .setBackoffCoefficient(0.5) - .setMaximumInterval(seconds(12)) - .setMaximumAttempts(13) - .addNonRetryableErrorReasons("error") - .setExpirationInterval(seconds(14))) - .setCronSchedule("cronSchedule") - .setMemo(Memo.newBuilder().putFields("memo", protoPayload("memoValue")).build()) - .setSearchAttributes( - SearchAttributes.newBuilder() - .putIndexedFields("search", protoPayload("searchValue")) - .build()) - .setHeader(Header.newBuilder().putFields("key", protoPayload("value")).build()) - .setDelayStart(seconds(3)) - .build(); - private static final com.uber.cadence.SignalWithStartWorkflowExecutionRequest - THRIFT_SIGNAL_WITH_START_WORKFLOW_EXECUTION = - new SignalWithStartWorkflowExecutionRequest() - .setDomain("domain") - .setWorkflowId("workflowId") - .setWorkflowType(new com.uber.cadence.WorkflowType().setName("workflowType")) - .setTaskList( - new com.uber.cadence.TaskList() - .setName("taskList") - .setKind(com.uber.cadence.TaskListKind.NORMAL)) - .setInput("input".getBytes(StandardCharsets.UTF_8)) - .setExecutionStartToCloseTimeoutSeconds(1) - .setTaskStartToCloseTimeoutSeconds(2) - .setIdentity("identity") - .setRequestId("requestId") - .setWorkflowIdReusePolicy(com.uber.cadence.WorkflowIdReusePolicy.AllowDuplicate) - .setSignalName("signalName") - .setSignalInput("signalInput".getBytes(StandardCharsets.UTF_8)) - .setControl("control".getBytes(StandardCharsets.UTF_8)) - .setRetryPolicy( - new com.uber.cadence.RetryPolicy() - .setInitialIntervalInSeconds(11) - .setBackoffCoefficient(0.5) - .setMaximumIntervalInSeconds(12) - .setMaximumAttempts(13) - .setNonRetriableErrorReasons(ImmutableList.of("error")) - .setExpirationIntervalInSeconds(14)) - .setCronSchedule("cronSchedule") - .setMemo( - new com.uber.cadence.Memo().setFields(ImmutableMap.of("memo", utf8("memoValue")))) - .setSearchAttributes( - new com.uber.cadence.SearchAttributes() - .setIndexedFields(ImmutableMap.of("search", utf8("searchValue")))) - .setHeader( - new com.uber.cadence.Header().setFields(ImmutableMap.of("key", utf8("value")))) - .setDelayStartSeconds(3); - private static final com.uber.cadence.api.v1.SignalWithStartWorkflowExecutionRequest - PROTO_SIGNAL_WITH_START_WORKFLOW_EXECUTION = - com.uber.cadence.api.v1.SignalWithStartWorkflowExecutionRequest.newBuilder() - .setStartRequest(PROTO_START_WORKFLOW_EXECUTION) - .setSignalInput(protoPayload("signalInput")) - .setSignalName("signalName") - .setControl(ByteString.copyFromUtf8("control")) - .build(); + @Parameterized.Parameter(0) + public String testName; - @Test - public void testStartWorkflowExecutionRequest() { - // Pulling in new IDL will intentionally cause this to fail. Either update the mapper or account - // for it here - assertMissingFields( - THRIFT_START_WORKFLOW_EXECUTION, - com.uber.cadence.StartWorkflowExecutionRequest._Fields.class, - "jitterStartSeconds"); - - assertEquals( - PROTO_START_WORKFLOW_EXECUTION, - RequestMapper.startWorkflowExecutionRequest(THRIFT_START_WORKFLOW_EXECUTION)); - } + @Parameterized.Parameter(1) + public T from; - @Test - public void testStartWorkflowExecutionAsyncRequest() { - com.uber.cadence.StartWorkflowExecutionAsyncRequest thrift = - new com.uber.cadence.StartWorkflowExecutionAsyncRequest() - .setRequest(THRIFT_START_WORKFLOW_EXECUTION); - - com.uber.cadence.api.v1.StartWorkflowExecutionAsyncRequest expected = - StartWorkflowExecutionAsyncRequest.newBuilder() - .setRequest(PROTO_START_WORKFLOW_EXECUTION) - .build(); + @Parameterized.Parameter(2) + public P to; - assertNoMissingFields( - thrift, com.uber.cadence.StartWorkflowExecutionAsyncRequest._Fields.class); + @Parameterized.Parameter(3) + public Function via; - assertEquals(expected, RequestMapper.startWorkflowExecutionAsyncRequest(thrift)); - } + @Parameterized.Parameter(4) + public Set missingFields; @Test - public void testSignalWithStartWorkflowExecutionRequest() { - assertMissingFields( - THRIFT_SIGNAL_WITH_START_WORKFLOW_EXECUTION, - com.uber.cadence.SignalWithStartWorkflowExecutionRequest._Fields.class, - "jitterStartSeconds"); - - assertEquals( - PROTO_SIGNAL_WITH_START_WORKFLOW_EXECUTION, - RequestMapper.signalWithStartWorkflowExecutionRequest( - THRIFT_SIGNAL_WITH_START_WORKFLOW_EXECUTION)); + public void testFieldsPresent() { + // If IDL is updated, this will fail. Update the mapper or add it to the test + if (missingFields.isEmpty()) { + assertNoMissingFields(from); + } else { + assertMissingFields(from, missingFields); + } } @Test - public void testSignalWithStartWorkflowExecutionAsyncRequest() { - com.uber.cadence.SignalWithStartWorkflowExecutionAsyncRequest thrift = - new com.uber.cadence.SignalWithStartWorkflowExecutionAsyncRequest() - .setRequest(THRIFT_SIGNAL_WITH_START_WORKFLOW_EXECUTION); - - com.uber.cadence.api.v1.SignalWithStartWorkflowExecutionAsyncRequest expected = - SignalWithStartWorkflowExecutionAsyncRequest.newBuilder() - .setRequest(PROTO_SIGNAL_WITH_START_WORKFLOW_EXECUTION) - .build(); - - assertNoMissingFields( - thrift, com.uber.cadence.SignalWithStartWorkflowExecutionAsyncRequest._Fields.class); - - assertEquals(expected, RequestMapper.signalWithStartWorkflowExecutionAsyncRequest(thrift)); + public void testMapper() { + P actual = via.apply(from); + assertEquals(to, actual); } - private static Duration seconds(int value) { - return Duration.newBuilder().setSeconds(value).build(); - } + @Test + public void testHandlesNull() { + P actual = via.apply(null); - private static Payload protoPayload(String value) { - return Payload.newBuilder().setData(ByteString.copyFromUtf8(value)).build(); + assertNull("Mapper functions should accept null, returning null", actual); } - private static ByteBuffer utf8(String value) { - return ByteBuffer.wrap(utf8Bytes(value)); + @Parameterized.Parameters(name = "{0}") + public static Iterable cases() { + return Arrays.asList( + testCase( + ThriftObjects.COUNT_WORKFLOW_EXECUTIONS_REQUEST, + ProtoObjects.COUNT_WORKFLOW_EXECUTIONS_REQUEST, + RequestMapper::countWorkflowExecutionsRequest), + testCase( + ThriftObjects.DESCRIBE_TASK_LIST_REQUEST, + ProtoObjects.DESCRIBE_TASK_LIST_REQUEST, + RequestMapper::describeTaskListRequest), + testCase( + ThriftObjects.LIST_ARCHIVED_WORKFLOW_EXECUTIONS_REQUEST, + ProtoObjects.LIST_ARCHIVED_WORKFLOW_EXECUTIONS_REQUEST, + RequestMapper::listArchivedWorkflowExecutionsRequest), + testCase( + ThriftObjects.REQUEST_CANCEL_WORKFLOW_EXECUTION_REQUEST, + ProtoObjects.REQUEST_CANCEL_WORKFLOW_EXECUTION_REQUEST, + RequestMapper::requestCancelWorkflowExecutionRequest, + "firstExecutionRunID", + "cause"), + testCase( + ThriftObjects.RESET_STICKY_TASK_LIST_REQUEST, + ProtoObjects.RESET_STICKY_TASK_LIST_REQUEST, + RequestMapper::resetStickyTaskListRequest), + testCase( + ThriftObjects.RESET_WORKFLOW_EXECUTION_REQUEST, + ProtoObjects.RESET_WORKFLOW_EXECUTION_REQUEST, + RequestMapper::resetWorkflowExecutionRequest), + testCase( + ThriftObjects.RESPOND_ACTIVITY_TASK_CANCELED_BY_ID_REQUEST, + ProtoObjects.RESPOND_ACTIVITY_TASK_CANCELED_BY_ID_REQUEST, + RequestMapper::respondActivityTaskCanceledByIdRequest), + testCase( + ThriftObjects.RESPOND_ACTIVITY_TASK_CANCELED_REQUEST, + ProtoObjects.RESPOND_ACTIVITY_TASK_CANCELED_REQUEST, + RequestMapper::respondActivityTaskCanceledRequest), + testCase( + ThriftObjects.RESPOND_ACTIVITY_TASK_COMPLETED_BY_ID_REQUEST, + ProtoObjects.RESPOND_ACTIVITY_TASK_COMPLETED_BY_ID_REQUEST, + RequestMapper::respondActivityTaskCompletedByIdRequest), + testCase( + ThriftObjects.RESPOND_ACTIVITY_TASK_COMPLETED_REQUEST, + ProtoObjects.RESPOND_ACTIVITY_TASK_COMPLETED_REQUEST, + RequestMapper::respondActivityTaskCompletedRequest), + testCase( + ThriftObjects.RESPOND_ACTIVITY_TASK_FAILED_BY_ID_REQUEST, + ProtoObjects.RESPOND_ACTIVITY_TASK_FAILED_BY_ID_REQUEST, + RequestMapper::respondActivityTaskFailedByIdRequest), + testCase( + ThriftObjects.RESPOND_ACTIVITY_TASK_FAILED_REQUEST, + ProtoObjects.RESPOND_ACTIVITY_TASK_FAILED_REQUEST, + RequestMapper::respondActivityTaskFailedRequest), + testCase( + ThriftObjects.RESPOND_DECISION_TASK_COMPLETED_REQUEST, + ProtoObjects.RESPOND_DECISION_TASK_COMPLETED_REQUEST, + RequestMapper::respondDecisionTaskCompletedRequest), + testCase( + ThriftObjects.RESPOND_DECISION_TASK_FAILED_REQUEST, + ProtoObjects.RESPOND_DECISION_TASK_FAILED_REQUEST, + RequestMapper::respondDecisionTaskFailedRequest), + testCase( + ThriftObjects.RESPOND_QUERY_TASK_COMPLETED_REQUEST, + ProtoObjects.RESPOND_QUERY_TASK_COMPLETED_REQUEST, + RequestMapper::respondQueryTaskCompletedRequest), + testCase( + ThriftObjects.LIST_WORKFLOW_EXECUTIONS_REQUEST, + ProtoObjects.SCAN_WORKFLOW_EXECUTIONS_REQUEST, + RequestMapper::scanWorkflowExecutionsRequest), + testCase( + ThriftObjects.DESCRIBE_WORKFLOW_EXECUTION_REQUEST, + ProtoObjects.DESCRIBE_WORKFLOW_EXECUTION_REQUEST, + RequestMapper::describeWorkflowExecutionRequest), + testCase( + ThriftObjects.GET_WORKFLOW_EXECUTION_HISTORY_REQUEST, + ProtoObjects.GET_WORKFLOW_EXECUTION_HISTORY_REQUEST, + RequestMapper::getWorkflowExecutionHistoryRequest), + testCase( + ThriftObjects.START_WORKFLOW_EXECUTION, + ProtoObjects.START_WORKFLOW_EXECUTION, + RequestMapper::startWorkflowExecutionRequest, + "jitterStartSeconds"), + testCase( + ThriftObjects.SIGNAL_WITH_START_WORKFLOW_EXECUTION, + ProtoObjects.SIGNAL_WITH_START_WORKFLOW_EXECUTION, + RequestMapper::signalWithStartWorkflowExecutionRequest, + "jitterStartSeconds"), + testCase( + ThriftObjects.START_WORKFLOW_EXECUTION_ASYNC_REQUEST, + ProtoObjects.START_WORKFLOW_EXECUTION_ASYNC_REQUEST, + RequestMapper::startWorkflowExecutionAsyncRequest), + testCase( + ThriftObjects.SIGNAL_WITH_START_WORKFLOW_EXECUTION_ASYNC_REQUEST, + ProtoObjects.SIGNAL_WITH_START_WORKFLOW_EXECUTION_ASYNC_REQUEST, + RequestMapper::signalWithStartWorkflowExecutionAsyncRequest), + testCase( + ThriftObjects.SIGNAL_WORKFLOW_EXECUTION_REQUEST, + ProtoObjects.SIGNAL_WORKFLOW_EXECUTION_REQUEST, + RequestMapper::signalWorkflowExecutionRequest), + testCase( + ThriftObjects.TERMINATE_WORKFLOW_EXECUTION_REQUEST, + ProtoObjects.TERMINATE_WORKFLOW_EXECUTION_REQUEST, + RequestMapper::terminateWorkflowExecutionRequest, + "firstExecutionRunID"), + testCase( + ThriftObjects.DEPRECATE_DOMAIN_REQUEST, + ProtoObjects.DEPRECATE_DOMAIN_REQUEST, + RequestMapper::deprecateDomainRequest), + testCase( + ThriftObjects.DESCRIBE_DOMAIN_BY_ID_REQUEST, + ProtoObjects.DESCRIBE_DOMAIN_BY_ID_REQUEST, + RequestMapper::describeDomainRequest, + "name"), + testCase( + ThriftObjects.DESCRIBE_DOMAIN_BY_NAME_REQUEST, + ProtoObjects.DESCRIBE_DOMAIN_BY_NAME_REQUEST, + RequestMapper::describeDomainRequest, + "uuid"), + testCase( + ThriftObjects.LIST_DOMAINS_REQUEST, + ProtoObjects.LIST_DOMAINS_REQUEST, + RequestMapper::listDomainsRequest), + testCase( + ThriftObjects.LIST_TASK_LIST_PARTITIONS_REQUEST, + ProtoObjects.LIST_TASK_LIST_PARTITIONS_REQUEST, + RequestMapper::listTaskListPartitionsRequest), + testCase( + ThriftObjects.POLL_FOR_ACTIVITY_TASK_REQUEST, + ProtoObjects.POLL_FOR_ACTIVITY_TASK_REQUEST, + RequestMapper::pollForActivityTaskRequest), + testCase( + ThriftObjects.POLL_FOR_DECISION_TASK_REQUEST, + ProtoObjects.POLL_FOR_DECISION_TASK_REQUEST, + RequestMapper::pollForDecisionTaskRequest), + testCase( + ThriftObjects.QUERY_WORKFLOW_REQUEST, + ProtoObjects.QUERY_WORKFLOW_REQUEST, + RequestMapper::queryWorkflowRequest), + testCase( + ThriftObjects.RECORD_ACTIVITY_TASK_HEARTBEAT_BY_ID_REQUEST, + ProtoObjects.RECORD_ACTIVITY_TASK_HEARTBEAT_BY_ID_REQUEST, + RequestMapper::recordActivityTaskHeartbeatByIdRequest), + testCase( + ThriftObjects.RECORD_ACTIVITY_TASK_HEARTBEAT_REQUEST, + ProtoObjects.RECORD_ACTIVITY_TASK_HEARTBEAT_REQUEST, + RequestMapper::recordActivityTaskHeartbeatRequest), + testCase( + ThriftObjects.REGISTER_DOMAIN_REQUEST, + ProtoObjects.REGISTER_DOMAIN_REQUEST, + RequestMapper::registerDomainRequest, + "emitMetric"), + testCase( + ThriftObjects.UPDATE_DOMAIN_REQUEST, + // Data and replicationConfiguration are copied incorrectly due to a bug :( + ProtoObjects.UPDATE_DOMAIN_REQUEST, + RequestMapper::updateDomainRequest), + testCase( + ThriftObjects.LIST_CLOSED_WORKFLOW_EXECUTIONS_REQUEST, + ProtoObjects.LIST_CLOSED_WORKFLOW_EXECUTIONS_REQUEST, + RequestMapper::listClosedWorkflowExecutionsRequest), + testCase( + ThriftObjects.LIST_OPEN_WORKFLOW_EXECUTIONS_REQUEST, + ProtoObjects.LIST_OPEN_WORKFLOW_EXECUTIONS_REQUEST, + RequestMapper::listOpenWorkflowExecutionsRequest), + testCase( + ThriftObjects.LIST_WORKFLOW_EXECUTIONS_REQUEST, + ProtoObjects.LIST_WORKFLOW_EXECUTIONS_REQUEST, + RequestMapper::listWorkflowExecutionsRequest)); } - private static byte[] utf8Bytes(String value) { - return value.getBytes(StandardCharsets.UTF_8); + private static Object[] testCase( + T from, P to, Function via, String... missingFields) { + return new Object[] { + from.getClass().getSimpleName(), from, to, via, ImmutableSet.copyOf(missingFields) + }; } }