Skip to content

Commit

Permalink
Add missing proto to thrift enum mappings and unit tests for both Enu…
Browse files Browse the repository at this point in the history
…mMappers

Add a suite of tests that will automatically fail if new enum types are added in IDL but the mappers aren't updated. This was done in a few ways:
- For enums that have mappers both directions, we roundtrip all thrift values and assert that they're equal.
- For enums that are identical across thrift/proto, we generate a mapping based on the value names and assert that the mapper matches it.
- For enums that aren't identical, we explicitly assert that our mapping contains all values.
  • Loading branch information
natemort committed Oct 23, 2024
1 parent 760f880 commit 58b9bc5
Show file tree
Hide file tree
Showing 3 changed files with 391 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@
import com.uber.cadence.api.v1.WorkflowExecutionCloseStatus;
import com.uber.cadence.api.v1.WorkflowIdReusePolicy;

class EnumMapper {
public final class EnumMapper {

static TaskListKind taskListKind(com.uber.cadence.TaskListKind t) {
private EnumMapper() {}

public static TaskListKind taskListKind(com.uber.cadence.TaskListKind t) {
if (t == null) {
return TaskListKind.TASK_LIST_KIND_INVALID;
}
Expand All @@ -71,7 +73,7 @@ static TaskListKind taskListKind(com.uber.cadence.TaskListKind t) {
throw new IllegalArgumentException("unexpected enum value");
}

static TaskListType taskListType(com.uber.cadence.TaskListType t) {
public static TaskListType taskListType(com.uber.cadence.TaskListType t) {
if (t == null) {
return TaskListType.TASK_LIST_TYPE_INVALID;
}
Expand All @@ -84,7 +86,7 @@ static TaskListType taskListType(com.uber.cadence.TaskListType t) {
throw new IllegalArgumentException("unexpected enum value");
}

static EventFilterType eventFilterType(com.uber.cadence.HistoryEventFilterType t) {
public static EventFilterType eventFilterType(com.uber.cadence.HistoryEventFilterType t) {
if (t == null) {
return EventFilterType.EVENT_FILTER_TYPE_INVALID;
}
Expand All @@ -97,7 +99,7 @@ static EventFilterType eventFilterType(com.uber.cadence.HistoryEventFilterType t
throw new IllegalArgumentException("unexpected enum value");
}

static QueryRejectCondition queryRejectCondition(com.uber.cadence.QueryRejectCondition t) {
public static QueryRejectCondition queryRejectCondition(com.uber.cadence.QueryRejectCondition t) {
if (t == null) {
return QueryRejectCondition.QUERY_REJECT_CONDITION_INVALID;
}
Expand All @@ -110,7 +112,8 @@ static QueryRejectCondition queryRejectCondition(com.uber.cadence.QueryRejectCon
throw new IllegalArgumentException("unexpected enum value");
}

static QueryConsistencyLevel queryConsistencyLevel(com.uber.cadence.QueryConsistencyLevel t) {
public static QueryConsistencyLevel queryConsistencyLevel(
com.uber.cadence.QueryConsistencyLevel t) {
if (t == null) {
return QueryConsistencyLevel.QUERY_CONSISTENCY_LEVEL_INVALID;
}
Expand All @@ -123,7 +126,8 @@ static QueryConsistencyLevel queryConsistencyLevel(com.uber.cadence.QueryConsist
throw new IllegalArgumentException("unexpected enum value");
}

static ContinueAsNewInitiator continueAsNewInitiator(com.uber.cadence.ContinueAsNewInitiator t) {
public static ContinueAsNewInitiator continueAsNewInitiator(
com.uber.cadence.ContinueAsNewInitiator t) {
if (t == null) {
return ContinueAsNewInitiator.CONTINUE_AS_NEW_INITIATOR_INVALID;
}
Expand All @@ -138,7 +142,8 @@ static ContinueAsNewInitiator continueAsNewInitiator(com.uber.cadence.ContinueAs
throw new IllegalArgumentException("unexpected enum value");
}

static WorkflowIdReusePolicy workflowIdReusePolicy(com.uber.cadence.WorkflowIdReusePolicy t) {
public static WorkflowIdReusePolicy workflowIdReusePolicy(
com.uber.cadence.WorkflowIdReusePolicy t) {
if (t == null) {
return WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_INVALID;
}
Expand All @@ -155,7 +160,7 @@ static WorkflowIdReusePolicy workflowIdReusePolicy(com.uber.cadence.WorkflowIdRe
throw new IllegalArgumentException("unexpected enum value");
}

static QueryResultType queryResultType(com.uber.cadence.QueryResultType t) {
public static QueryResultType queryResultType(com.uber.cadence.QueryResultType t) {
if (t == null) {
return QUERY_RESULT_TYPE_INVALID;
}
Expand All @@ -168,7 +173,7 @@ static QueryResultType queryResultType(com.uber.cadence.QueryResultType t) {
throw new IllegalArgumentException("unexpected enum value");
}

static ArchivalStatus archivalStatus(com.uber.cadence.ArchivalStatus t) {
public static ArchivalStatus archivalStatus(com.uber.cadence.ArchivalStatus t) {
if (t == null) {
return ArchivalStatus.ARCHIVAL_STATUS_INVALID;
}
Expand All @@ -181,7 +186,7 @@ static ArchivalStatus archivalStatus(com.uber.cadence.ArchivalStatus t) {
throw new IllegalArgumentException("unexpected enum value");
}

static ParentClosePolicy parentClosePolicy(com.uber.cadence.ParentClosePolicy t) {
public static ParentClosePolicy parentClosePolicy(com.uber.cadence.ParentClosePolicy t) {
if (t == null) {
return ParentClosePolicy.PARENT_CLOSE_POLICY_INVALID;
}
Expand All @@ -196,7 +201,7 @@ static ParentClosePolicy parentClosePolicy(com.uber.cadence.ParentClosePolicy t)
throw new IllegalArgumentException("unexpected enum value");
}

static DecisionTaskFailedCause decisionTaskFailedCause(
public static DecisionTaskFailedCause decisionTaskFailedCause(
com.uber.cadence.DecisionTaskFailedCause t) {
if (t == null) {
return DECISION_TASK_FAILED_CAUSE_INVALID;
Expand Down Expand Up @@ -252,7 +257,7 @@ static DecisionTaskFailedCause decisionTaskFailedCause(
throw new IllegalArgumentException("unexpected enum value");
}

static WorkflowExecutionCloseStatus workflowExecutionCloseStatus(
public static WorkflowExecutionCloseStatus workflowExecutionCloseStatus(
com.uber.cadence.WorkflowExecutionCloseStatus t) {
if (t == null) {
return WorkflowExecutionCloseStatus.WORKFLOW_EXECUTION_CLOSE_STATUS_INVALID;
Expand All @@ -274,7 +279,7 @@ static WorkflowExecutionCloseStatus workflowExecutionCloseStatus(
throw new IllegalArgumentException("unexpected enum value");
}

static QueryResultType queryTaskCompletedType(com.uber.cadence.QueryTaskCompletedType t) {
public static QueryResultType queryTaskCompletedType(com.uber.cadence.QueryTaskCompletedType t) {
if (t == null) {
return QUERY_RESULT_TYPE_INVALID;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
import com.uber.cadence.WorkflowExecutionCloseStatus;
import com.uber.cadence.WorkflowIdReusePolicy;

class EnumMapper {
public final class EnumMapper {

private EnumMapper() {}

public static TaskListKind taskListKind(com.uber.cadence.api.v1.TaskListKind t) {
switch (t) {
Expand Down Expand Up @@ -311,6 +313,8 @@ public static DecisionTaskTimedOutCause decisionTaskTimedOutCause(
return null;
case CANCEL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_UNKNOWN_EXTERNAL_WORKFLOW_EXECUTION:
return CancelExternalWorkflowExecutionFailedCause.UNKNOWN_EXTERNAL_WORKFLOW_EXECUTION;
case CANCEL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_WORKFLOW_ALREADY_COMPLETED:
return CancelExternalWorkflowExecutionFailedCause.WORKFLOW_ALREADY_COMPLETED;
}
throw new IllegalArgumentException("unexpected enum value");
}
Expand All @@ -323,6 +327,8 @@ public static DecisionTaskTimedOutCause decisionTaskTimedOutCause(
return null;
case SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_UNKNOWN_EXTERNAL_WORKFLOW_EXECUTION:
return SignalExternalWorkflowExecutionFailedCause.UNKNOWN_EXTERNAL_WORKFLOW_EXECUTION;
case SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_WORKFLOW_ALREADY_COMPLETED:
return SignalExternalWorkflowExecutionFailedCause.WORKFLOW_ALREADY_COMPLETED;
}
throw new IllegalArgumentException("unexpected enum value");
}
Expand Down
Loading

0 comments on commit 58b9bc5

Please sign in to comment.