• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uber / cadence-java-client / 2583

31 Oct 2024 09:00PM UTC coverage: 74.8% (+4.2%) from 70.648%
2583

push

buildkite

web-flow
Fix ActivityCompletionClient cancellation and failure by WorkflowExecution (#930)

When sending RespondActivityTaskFailedByIDRequest or RespondActivityTaskCanceledByIDRequest we don't include the ActivityID. Correctly include the id and add test coverage.

2 of 2 new or added lines in 1 file covered. (100.0%)

305 existing lines in 9 files now uncovered.

14500 of 19385 relevant lines covered (74.8%)

0.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.83
/src/main/java/com/uber/cadence/internal/compatibility/proto/TypeMapper.java
1
/*
2
 *  Modifications Copyright (c) 2017-2021 Uber Technologies Inc.
3
 *  Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
 *
5
 *  Licensed under the Apache License, Version 2.0 (the "License"). You may not
6
 *  use this file except in compliance with the License. A copy of the License is
7
 *  located at
8
 *
9
 *  http://aws.amazon.com/apache2.0
10
 *
11
 *  or in the "license" file accompanying this file. This file is distributed on
12
 *  an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13
 *  express or implied. See the License for the specific language governing
14
 *  permissions and limitations under the License.
15
 */
16
package com.uber.cadence.internal.compatibility.proto;
17

18
import static com.uber.cadence.internal.compatibility.proto.EnumMapper.queryResultType;
19
import static com.uber.cadence.internal.compatibility.proto.EnumMapper.taskListKind;
20
import static com.uber.cadence.internal.compatibility.proto.EnumMapper.workflowExecutionCloseStatus;
21
import static com.uber.cadence.internal.compatibility.proto.Helpers.arrayToByteString;
22
import static com.uber.cadence.internal.compatibility.proto.Helpers.fromDoubleValue;
23
import static com.uber.cadence.internal.compatibility.proto.Helpers.secondsToDuration;
24
import static com.uber.cadence.internal.compatibility.proto.Helpers.unixNanoToTime;
25

26
import com.google.common.base.Strings;
27
import com.uber.cadence.api.v1.ActivityType;
28
import com.uber.cadence.api.v1.BadBinaries;
29
import com.uber.cadence.api.v1.BadBinaryInfo;
30
import com.uber.cadence.api.v1.ClusterReplicationConfiguration;
31
import com.uber.cadence.api.v1.Failure;
32
import com.uber.cadence.api.v1.Header;
33
import com.uber.cadence.api.v1.Memo;
34
import com.uber.cadence.api.v1.Payload;
35
import com.uber.cadence.api.v1.RetryPolicy;
36
import com.uber.cadence.api.v1.SearchAttributes;
37
import com.uber.cadence.api.v1.StartTimeFilter;
38
import com.uber.cadence.api.v1.StatusFilter;
39
import com.uber.cadence.api.v1.StickyExecutionAttributes;
40
import com.uber.cadence.api.v1.TaskList;
41
import com.uber.cadence.api.v1.TaskListMetadata;
42
import com.uber.cadence.api.v1.WorkerVersionInfo;
43
import com.uber.cadence.api.v1.WorkflowExecution;
44
import com.uber.cadence.api.v1.WorkflowExecutionFilter;
45
import com.uber.cadence.api.v1.WorkflowQuery;
46
import com.uber.cadence.api.v1.WorkflowQueryResult;
47
import com.uber.cadence.api.v1.WorkflowType;
48
import com.uber.cadence.api.v1.WorkflowTypeFilter;
49
import java.nio.ByteBuffer;
50
import java.util.ArrayList;
51
import java.util.Collections;
52
import java.util.HashMap;
53
import java.util.List;
54
import java.util.Map;
55

56
class TypeMapper {
×
57

58
  static BadBinaryInfo badBinaryInfo(com.uber.cadence.BadBinaryInfo t) {
59
    if (t == null) {
1✔
60
      return null;
×
61
    }
62
    return BadBinaryInfo.newBuilder()
1✔
63
        .setReason(t.getReason())
1✔
64
        .setOperator(t.getOperator())
1✔
65
        .setCreatedTime(unixNanoToTime(t.getCreatedTimeNano()))
1✔
66
        .build();
1✔
67
  }
68

69
  static Payload payload(byte[] data) {
70
    if (data == null) {
1✔
UNCOV
71
      return Payload.newBuilder().build();
×
72
    }
73
    return Payload.newBuilder().setData(arrayToByteString(data)).build();
1✔
74
  }
75

76
  static Failure failure(String reason, byte[] details) {
77
    if (reason == null) {
1✔
78
      return Failure.newBuilder().build();
×
79
    }
80
    return Failure.newBuilder().setReason(reason).setDetails(arrayToByteString(details)).build();
1✔
81
  }
82

83
  static WorkflowExecution workflowExecution(com.uber.cadence.WorkflowExecution t) {
84
    if (t == null) {
1✔
85
      return WorkflowExecution.newBuilder().build();
×
86
    }
87
    if (t.getWorkflowId() == null && t.getRunId() == null) {
1✔
88
      return WorkflowExecution.newBuilder().build();
×
89
    }
90
    WorkflowExecution.Builder builder =
91
        WorkflowExecution.newBuilder().setWorkflowId(t.getWorkflowId());
1✔
92
    if (t.getRunId() != null) {
1✔
93
      builder.setRunId(t.getRunId());
1✔
94
    }
95
    return builder.build();
1✔
96
  }
97

98
  static WorkflowExecution workflowRunPair(String workflowId, String runId) {
99
    if (Strings.isNullOrEmpty(workflowId) && Strings.isNullOrEmpty(runId)) {
1✔
100
      return WorkflowExecution.newBuilder().build();
×
101
    }
102
    return WorkflowExecution.newBuilder().setWorkflowId(workflowId).setRunId(runId).build();
1✔
103
  }
104

105
  static ActivityType activityType(com.uber.cadence.ActivityType t) {
106
    if (t == null) {
1✔
107
      return ActivityType.newBuilder().build();
×
108
    }
109
    return ActivityType.newBuilder().setName(t.getName()).build();
1✔
110
  }
111

112
  static WorkflowType workflowType(com.uber.cadence.WorkflowType t) {
113
    if (t == null) {
1✔
UNCOV
114
      return WorkflowType.newBuilder().build();
×
115
    }
116
    return WorkflowType.newBuilder().setName(t.getName()).build();
1✔
117
  }
118

119
  static TaskList taskList(com.uber.cadence.TaskList t) {
120
    if (t == null) {
1✔
UNCOV
121
      return TaskList.newBuilder().build();
×
122
    }
123
    return TaskList.newBuilder().setName(t.getName()).setKind(taskListKind(t.getKind())).build();
1✔
124
  }
125

126
  static TaskListMetadata taskListMetadata(com.uber.cadence.TaskListMetadata t) {
127
    if (t == null) {
1✔
128
      return TaskListMetadata.newBuilder().build();
×
129
    }
130
    return TaskListMetadata.newBuilder()
1✔
131
        .setMaxTasksPerSecond(fromDoubleValue(t.getMaxTasksPerSecond()))
1✔
132
        .build();
1✔
133
  }
134

135
  static RetryPolicy retryPolicy(com.uber.cadence.RetryPolicy t) {
136
    if (t == null) {
1✔
137
      return null;
×
138
    }
139
    RetryPolicy.Builder builder =
140
        RetryPolicy.newBuilder()
1✔
141
            .setInitialInterval(secondsToDuration(t.getInitialIntervalInSeconds()))
1✔
142
            .setBackoffCoefficient(t.getBackoffCoefficient())
1✔
143
            .setMaximumInterval(secondsToDuration(t.getMaximumIntervalInSeconds()))
1✔
144
            .setMaximumAttempts(t.getMaximumAttempts())
1✔
145
            .setExpirationInterval(secondsToDuration(t.getExpirationIntervalInSeconds()));
1✔
146
    if (t.getNonRetriableErrorReasons() != null) {
1✔
147
      builder.addAllNonRetryableErrorReasons(t.getNonRetriableErrorReasons());
1✔
148
    }
149
    return builder.build();
1✔
150
  }
151

152
  static Header header(com.uber.cadence.Header t) {
153
    if (t == null) {
1✔
UNCOV
154
      return Header.newBuilder().build();
×
155
    }
156
    return Header.newBuilder().putAllFields(payloadByteBufferMap(t.getFields())).build();
1✔
157
  }
158

159
  static Memo memo(com.uber.cadence.Memo t) {
160
    if (t == null) {
1✔
UNCOV
161
      return Memo.newBuilder().build();
×
162
    }
163
    return Memo.newBuilder().putAllFields(payloadByteBufferMap(t.getFields())).build();
1✔
164
  }
165

166
  static SearchAttributes searchAttributes(com.uber.cadence.SearchAttributes t) {
167
    if (t == null) {
1✔
UNCOV
168
      return SearchAttributes.newBuilder().build();
×
169
    }
170
    return SearchAttributes.newBuilder()
1✔
171
        .putAllIndexedFields(payloadByteBufferMap(t.getIndexedFields()))
1✔
172
        .build();
1✔
173
  }
174

175
  static BadBinaries badBinaries(com.uber.cadence.BadBinaries t) {
176
    if (t == null) {
1✔
177
      return BadBinaries.newBuilder().build();
×
178
    }
179
    return BadBinaries.newBuilder().putAllBinaries(badBinaryInfoMap(t.getBinaries())).build();
1✔
180
  }
181

182
  static ClusterReplicationConfiguration clusterReplicationConfiguration(
183
      com.uber.cadence.ClusterReplicationConfiguration t) {
184
    if (t == null) {
1✔
185
      return ClusterReplicationConfiguration.newBuilder().build();
×
186
    }
187
    return ClusterReplicationConfiguration.newBuilder().setClusterName(t.getClusterName()).build();
1✔
188
  }
189

190
  static WorkflowQuery workflowQuery(com.uber.cadence.WorkflowQuery t) {
191
    if (t == null) {
1✔
192
      return null;
×
193
    }
194
    return WorkflowQuery.newBuilder()
1✔
195
        .setQueryType(t.getQueryType())
1✔
196
        .setQueryArgs(payload(t.getQueryArgs()))
1✔
197
        .build();
1✔
198
  }
199

200
  static WorkflowQueryResult workflowQueryResult(com.uber.cadence.WorkflowQueryResult t) {
201
    if (t == null) {
1✔
202
      return WorkflowQueryResult.newBuilder().build();
×
203
    }
204
    return WorkflowQueryResult.newBuilder()
1✔
205
        .setResultType(queryResultType(t.getResultType()))
1✔
206
        .setAnswer(payload(t.getAnswer()))
1✔
207
        .setErrorMessage(t.getErrorMessage())
1✔
208
        .build();
1✔
209
  }
210

211
  static StickyExecutionAttributes stickyExecutionAttributes(
212
      com.uber.cadence.StickyExecutionAttributes t) {
213
    if (t == null) {
1✔
214
      return StickyExecutionAttributes.newBuilder().build();
×
215
    }
216
    return StickyExecutionAttributes.newBuilder()
1✔
217
        .setWorkerTaskList(taskList(t.getWorkerTaskList()))
1✔
218
        .setScheduleToStartTimeout(secondsToDuration(t.getScheduleToStartTimeoutSeconds()))
1✔
219
        .build();
1✔
220
  }
221

222
  static WorkerVersionInfo workerVersionInfo(com.uber.cadence.WorkerVersionInfo t) {
223
    if (t == null) {
1✔
224
      return WorkerVersionInfo.newBuilder().build();
×
225
    }
226
    return WorkerVersionInfo.newBuilder()
1✔
227
        .setImpl(t.getImpl())
1✔
228
        .setFeatureVersion(t.getFeatureVersion())
1✔
229
        .build();
1✔
230
  }
231

232
  static StartTimeFilter startTimeFilter(com.uber.cadence.StartTimeFilter t) {
233
    if (t == null) {
1✔
234
      return null;
×
235
    }
236
    return StartTimeFilter.newBuilder()
1✔
237
        .setEarliestTime(unixNanoToTime(t.getEarliestTime()))
1✔
238
        .setLatestTime(unixNanoToTime(t.getLatestTime()))
1✔
239
        .build();
1✔
240
  }
241

242
  static WorkflowExecutionFilter workflowExecutionFilter(
243
      com.uber.cadence.WorkflowExecutionFilter t) {
244
    if (t == null) {
1✔
245
      return WorkflowExecutionFilter.newBuilder().build();
×
246
    }
247
    return WorkflowExecutionFilter.newBuilder()
1✔
248
        .setWorkflowId(t.getWorkflowId())
1✔
249
        .setRunId(t.getRunId())
1✔
250
        .build();
1✔
251
  }
252

253
  static WorkflowTypeFilter workflowTypeFilter(com.uber.cadence.WorkflowTypeFilter t) {
254
    if (t == null) {
1✔
255
      return WorkflowTypeFilter.newBuilder().build();
×
256
    }
257
    return WorkflowTypeFilter.newBuilder().setName(t.getName()).build();
1✔
258
  }
259

260
  static StatusFilter statusFilter(com.uber.cadence.WorkflowExecutionCloseStatus t) {
261
    if (t == null) {
1✔
262
      return null;
×
263
    }
264
    return StatusFilter.newBuilder().setStatus(workflowExecutionCloseStatus(t)).build();
1✔
265
  }
266

267
  static Map<String, Payload> payloadByteBufferMap(Map<String, ByteBuffer> t) {
268
    if (t == null) {
1✔
269
      return Collections.emptyMap();
×
270
    }
271
    Map<String, Payload> v = new HashMap<>();
1✔
272
    for (String key : t.keySet()) {
1✔
273
      v.put(key, payload(t.get(key).array()));
1✔
274
    }
1✔
275
    return v;
1✔
276
  }
277

278
  static Map<String, BadBinaryInfo> badBinaryInfoMap(
279
      Map<String, com.uber.cadence.BadBinaryInfo> t) {
280
    if (t == null) {
1✔
281
      return Collections.emptyMap();
×
282
    }
283
    Map<String, BadBinaryInfo> v = new HashMap<>();
1✔
284
    for (String key : t.keySet()) {
1✔
285
      v.put(key, badBinaryInfo(t.get(key)));
1✔
286
    }
1✔
287
    return v;
1✔
288
  }
289

290
  static List<ClusterReplicationConfiguration> clusterReplicationConfigurationArray(
291
      List<com.uber.cadence.ClusterReplicationConfiguration> t) {
292
    if (t == null) {
1✔
293
      return Collections.emptyList();
×
294
    }
295
    List<ClusterReplicationConfiguration> v = new ArrayList<>();
1✔
296
    for (int i = 0; i < t.size(); i++) {
1✔
297
      v.add(clusterReplicationConfiguration(t.get(i)));
1✔
298
    }
299
    return v;
1✔
300
  }
301

302
  static Map<String, WorkflowQueryResult> workflowQueryResultMap(
303
      Map<String, com.uber.cadence.WorkflowQueryResult> t) {
304
    if (t == null) {
1✔
305
      return Collections.emptyMap();
×
306
    }
307
    Map<String, WorkflowQueryResult> v = new HashMap<>();
1✔
308
    for (String key : t.keySet()) {
1✔
309
      v.put(key, workflowQueryResult(t.get(key)));
1✔
310
    }
1✔
311
    return v;
1✔
312
  }
313
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc