Skip to content

Commit 405c755

Browse files
authored
Add missing proto to thrift enum mappings and unit tests for both EnumMappers (#924)
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.
1 parent 760f880 commit 405c755

File tree

3 files changed

+391
-15
lines changed

3 files changed

+391
-15
lines changed

src/main/java/com/uber/cadence/internal/compatibility/proto/EnumMapper.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@
5656
import com.uber.cadence.api.v1.WorkflowExecutionCloseStatus;
5757
import com.uber.cadence.api.v1.WorkflowIdReusePolicy;
5858

59-
class EnumMapper {
59+
public final class EnumMapper {
6060

61-
static TaskListKind taskListKind(com.uber.cadence.TaskListKind t) {
61+
private EnumMapper() {}
62+
63+
public static TaskListKind taskListKind(com.uber.cadence.TaskListKind t) {
6264
if (t == null) {
6365
return TaskListKind.TASK_LIST_KIND_INVALID;
6466
}
@@ -71,7 +73,7 @@ static TaskListKind taskListKind(com.uber.cadence.TaskListKind t) {
7173
throw new IllegalArgumentException("unexpected enum value");
7274
}
7375

74-
static TaskListType taskListType(com.uber.cadence.TaskListType t) {
76+
public static TaskListType taskListType(com.uber.cadence.TaskListType t) {
7577
if (t == null) {
7678
return TaskListType.TASK_LIST_TYPE_INVALID;
7779
}
@@ -84,7 +86,7 @@ static TaskListType taskListType(com.uber.cadence.TaskListType t) {
8486
throw new IllegalArgumentException("unexpected enum value");
8587
}
8688

87-
static EventFilterType eventFilterType(com.uber.cadence.HistoryEventFilterType t) {
89+
public static EventFilterType eventFilterType(com.uber.cadence.HistoryEventFilterType t) {
8890
if (t == null) {
8991
return EventFilterType.EVENT_FILTER_TYPE_INVALID;
9092
}
@@ -97,7 +99,7 @@ static EventFilterType eventFilterType(com.uber.cadence.HistoryEventFilterType t
9799
throw new IllegalArgumentException("unexpected enum value");
98100
}
99101

100-
static QueryRejectCondition queryRejectCondition(com.uber.cadence.QueryRejectCondition t) {
102+
public static QueryRejectCondition queryRejectCondition(com.uber.cadence.QueryRejectCondition t) {
101103
if (t == null) {
102104
return QueryRejectCondition.QUERY_REJECT_CONDITION_INVALID;
103105
}
@@ -110,7 +112,8 @@ static QueryRejectCondition queryRejectCondition(com.uber.cadence.QueryRejectCon
110112
throw new IllegalArgumentException("unexpected enum value");
111113
}
112114

113-
static QueryConsistencyLevel queryConsistencyLevel(com.uber.cadence.QueryConsistencyLevel t) {
115+
public static QueryConsistencyLevel queryConsistencyLevel(
116+
com.uber.cadence.QueryConsistencyLevel t) {
114117
if (t == null) {
115118
return QueryConsistencyLevel.QUERY_CONSISTENCY_LEVEL_INVALID;
116119
}
@@ -123,7 +126,8 @@ static QueryConsistencyLevel queryConsistencyLevel(com.uber.cadence.QueryConsist
123126
throw new IllegalArgumentException("unexpected enum value");
124127
}
125128

126-
static ContinueAsNewInitiator continueAsNewInitiator(com.uber.cadence.ContinueAsNewInitiator t) {
129+
public static ContinueAsNewInitiator continueAsNewInitiator(
130+
com.uber.cadence.ContinueAsNewInitiator t) {
127131
if (t == null) {
128132
return ContinueAsNewInitiator.CONTINUE_AS_NEW_INITIATOR_INVALID;
129133
}
@@ -138,7 +142,8 @@ static ContinueAsNewInitiator continueAsNewInitiator(com.uber.cadence.ContinueAs
138142
throw new IllegalArgumentException("unexpected enum value");
139143
}
140144

141-
static WorkflowIdReusePolicy workflowIdReusePolicy(com.uber.cadence.WorkflowIdReusePolicy t) {
145+
public static WorkflowIdReusePolicy workflowIdReusePolicy(
146+
com.uber.cadence.WorkflowIdReusePolicy t) {
142147
if (t == null) {
143148
return WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_INVALID;
144149
}
@@ -155,7 +160,7 @@ static WorkflowIdReusePolicy workflowIdReusePolicy(com.uber.cadence.WorkflowIdRe
155160
throw new IllegalArgumentException("unexpected enum value");
156161
}
157162

158-
static QueryResultType queryResultType(com.uber.cadence.QueryResultType t) {
163+
public static QueryResultType queryResultType(com.uber.cadence.QueryResultType t) {
159164
if (t == null) {
160165
return QUERY_RESULT_TYPE_INVALID;
161166
}
@@ -168,7 +173,7 @@ static QueryResultType queryResultType(com.uber.cadence.QueryResultType t) {
168173
throw new IllegalArgumentException("unexpected enum value");
169174
}
170175

171-
static ArchivalStatus archivalStatus(com.uber.cadence.ArchivalStatus t) {
176+
public static ArchivalStatus archivalStatus(com.uber.cadence.ArchivalStatus t) {
172177
if (t == null) {
173178
return ArchivalStatus.ARCHIVAL_STATUS_INVALID;
174179
}
@@ -181,7 +186,7 @@ static ArchivalStatus archivalStatus(com.uber.cadence.ArchivalStatus t) {
181186
throw new IllegalArgumentException("unexpected enum value");
182187
}
183188

184-
static ParentClosePolicy parentClosePolicy(com.uber.cadence.ParentClosePolicy t) {
189+
public static ParentClosePolicy parentClosePolicy(com.uber.cadence.ParentClosePolicy t) {
185190
if (t == null) {
186191
return ParentClosePolicy.PARENT_CLOSE_POLICY_INVALID;
187192
}
@@ -196,7 +201,7 @@ static ParentClosePolicy parentClosePolicy(com.uber.cadence.ParentClosePolicy t)
196201
throw new IllegalArgumentException("unexpected enum value");
197202
}
198203

199-
static DecisionTaskFailedCause decisionTaskFailedCause(
204+
public static DecisionTaskFailedCause decisionTaskFailedCause(
200205
com.uber.cadence.DecisionTaskFailedCause t) {
201206
if (t == null) {
202207
return DECISION_TASK_FAILED_CAUSE_INVALID;
@@ -252,7 +257,7 @@ static DecisionTaskFailedCause decisionTaskFailedCause(
252257
throw new IllegalArgumentException("unexpected enum value");
253258
}
254259

255-
static WorkflowExecutionCloseStatus workflowExecutionCloseStatus(
260+
public static WorkflowExecutionCloseStatus workflowExecutionCloseStatus(
256261
com.uber.cadence.WorkflowExecutionCloseStatus t) {
257262
if (t == null) {
258263
return WorkflowExecutionCloseStatus.WORKFLOW_EXECUTION_CLOSE_STATUS_INVALID;
@@ -274,7 +279,7 @@ static WorkflowExecutionCloseStatus workflowExecutionCloseStatus(
274279
throw new IllegalArgumentException("unexpected enum value");
275280
}
276281

277-
static QueryResultType queryTaskCompletedType(com.uber.cadence.QueryTaskCompletedType t) {
282+
public static QueryResultType queryTaskCompletedType(com.uber.cadence.QueryTaskCompletedType t) {
278283
if (t == null) {
279284
return QUERY_RESULT_TYPE_INVALID;
280285
}

src/main/java/com/uber/cadence/internal/compatibility/thrift/EnumMapper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
import com.uber.cadence.WorkflowExecutionCloseStatus;
3737
import com.uber.cadence.WorkflowIdReusePolicy;
3838

39-
class EnumMapper {
39+
public final class EnumMapper {
40+
41+
private EnumMapper() {}
4042

4143
public static TaskListKind taskListKind(com.uber.cadence.api.v1.TaskListKind t) {
4244
switch (t) {
@@ -311,6 +313,8 @@ public static DecisionTaskTimedOutCause decisionTaskTimedOutCause(
311313
return null;
312314
case CANCEL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_UNKNOWN_EXTERNAL_WORKFLOW_EXECUTION:
313315
return CancelExternalWorkflowExecutionFailedCause.UNKNOWN_EXTERNAL_WORKFLOW_EXECUTION;
316+
case CANCEL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_WORKFLOW_ALREADY_COMPLETED:
317+
return CancelExternalWorkflowExecutionFailedCause.WORKFLOW_ALREADY_COMPLETED;
314318
}
315319
throw new IllegalArgumentException("unexpected enum value");
316320
}
@@ -323,6 +327,8 @@ public static DecisionTaskTimedOutCause decisionTaskTimedOutCause(
323327
return null;
324328
case SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_UNKNOWN_EXTERNAL_WORKFLOW_EXECUTION:
325329
return SignalExternalWorkflowExecutionFailedCause.UNKNOWN_EXTERNAL_WORKFLOW_EXECUTION;
330+
case SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_WORKFLOW_ALREADY_COMPLETED:
331+
return SignalExternalWorkflowExecutionFailedCause.WORKFLOW_ALREADY_COMPLETED;
326332
}
327333
throw new IllegalArgumentException("unexpected enum value");
328334
}

0 commit comments

Comments
 (0)