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

uber / cadence-java-client / 2310

03 May 2024 10:40PM UTC coverage: 61.463% (-0.02%) from 61.481%
2310

push

buildkite

web-flow
Release v3.12.0 (#893)

11960 of 19459 relevant lines covered (61.46%)

0.61 hits per line

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

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

18
package com.uber.cadence.internal.replay;
19

20
import com.uber.cadence.*;
21
import com.uber.cadence.context.ContextPropagator;
22
import java.nio.ByteBuffer;
23
import java.util.HashMap;
24
import java.util.List;
25
import java.util.Map;
26

27
final class WorkflowContext {
28

29
  private final PollForDecisionTaskResponse decisionTask;
30
  private boolean cancelRequested;
31
  private ContinueAsNewWorkflowExecutionParameters continueAsNewOnCompletion;
32
  private WorkflowExecutionStartedEventAttributes startedAttributes;
33
  private final String domain;
34
  // RunId can change when reset happens. This remembers the actual runId that is used
35
  // as in this particular part of the history.
36
  private String currentRunId;
37
  private SearchAttributes searchAttributes;
38
  private List<ContextPropagator> contextPropagators;
39

40
  WorkflowContext(
41
      String domain,
42
      PollForDecisionTaskResponse decisionTask,
43
      WorkflowExecutionStartedEventAttributes startedAttributes,
44
      List<ContextPropagator> contextPropagators) {
1✔
45
    this.domain = domain;
1✔
46
    this.decisionTask = decisionTask;
1✔
47
    this.startedAttributes = startedAttributes;
1✔
48
    this.currentRunId = startedAttributes.getOriginalExecutionRunId();
1✔
49
    this.searchAttributes = startedAttributes.getSearchAttributes();
1✔
50
    this.contextPropagators = contextPropagators;
1✔
51
  }
1✔
52

53
  WorkflowExecution getWorkflowExecution() {
54
    return decisionTask.getWorkflowExecution();
1✔
55
  }
56

57
  WorkflowType getWorkflowType() {
58
    return decisionTask.getWorkflowType();
1✔
59
  }
60

61
  boolean isCancelRequested() {
62
    return cancelRequested;
×
63
  }
64

65
  void setCancelRequested(boolean flag) {
66
    cancelRequested = flag;
1✔
67
  }
1✔
68

69
  ContinueAsNewWorkflowExecutionParameters getContinueAsNewOnCompletion() {
70
    return continueAsNewOnCompletion;
1✔
71
  }
72

73
  void setContinueAsNewOnCompletion(ContinueAsNewWorkflowExecutionParameters continueParameters) {
74
    if (continueParameters == null) {
1✔
75
      continueParameters = new ContinueAsNewWorkflowExecutionParameters();
×
76
    }
77
    //            continueParameters.setChildPolicy(startedAttributes);
78
    if (continueParameters.getExecutionStartToCloseTimeoutSeconds() == 0) {
1✔
79
      continueParameters.setExecutionStartToCloseTimeoutSeconds(
1✔
80
          startedAttributes.getExecutionStartToCloseTimeoutSeconds());
1✔
81
    }
82
    if (continueParameters.getTaskList() == null) {
1✔
83
      continueParameters.setTaskList(startedAttributes.getTaskList().getName());
1✔
84
    }
85
    if (continueParameters.getTaskStartToCloseTimeoutSeconds() == 0) {
1✔
86
      continueParameters.setTaskStartToCloseTimeoutSeconds(
1✔
87
          startedAttributes.getTaskStartToCloseTimeoutSeconds());
1✔
88
    }
89
    this.continueAsNewOnCompletion = continueParameters;
1✔
90
  }
1✔
91

92
  // TODO: Implement as soon as WorkflowExecutionStartedEventAttributes have these fields added.
93
  ////    com.uber.cadence.ChildPolicy getChildPolicy() {
94
  //        WorkflowExecutionStartedEventAttributes attributes =
95
  // getWorkflowStartedEventAttributes();
96
  //        return ChildPolicy.fromValue(attributes.getChildPolicy());
97
  //    }
98

99
  ////    String getContinuedExecutionRunId() {
100
  //        WorkflowExecutionStartedEventAttributes attributes =
101
  // getWorkflowStartedEventAttributes();
102
  //        return attributes.getContinuedExecutionRunId();
103
  //    }
104

105
  WorkflowExecution getParentWorkflowExecution() {
106
    WorkflowExecutionStartedEventAttributes attributes = getWorkflowStartedEventAttributes();
1✔
107
    return attributes.getParentWorkflowExecution();
1✔
108
  }
109

110
  int getExecutionStartToCloseTimeoutSeconds() {
111
    WorkflowExecutionStartedEventAttributes attributes = getWorkflowStartedEventAttributes();
1✔
112
    return attributes.getExecutionStartToCloseTimeoutSeconds();
1✔
113
  }
114

115
  int getDecisionTaskTimeoutSeconds() {
116
    return startedAttributes.getTaskStartToCloseTimeoutSeconds();
1✔
117
  }
118

119
  String getTaskList() {
120
    WorkflowExecutionStartedEventAttributes attributes = getWorkflowStartedEventAttributes();
1✔
121
    return attributes.getTaskList().getName();
1✔
122
  }
123

124
  String getDomain() {
125
    return domain;
1✔
126
  }
127

128
  private WorkflowExecutionStartedEventAttributes getWorkflowStartedEventAttributes() {
129
    return startedAttributes;
1✔
130
  }
131

132
  void setCurrentRunId(String currentRunId) {
133
    this.currentRunId = currentRunId;
1✔
134
  }
1✔
135

136
  String getCurrentRunId() {
137
    return currentRunId;
1✔
138
  }
139

140
  SearchAttributes getSearchAttributes() {
141
    return searchAttributes;
1✔
142
  }
143

144
  public List<ContextPropagator> getContextPropagators() {
145
    return contextPropagators;
1✔
146
  }
147

148
  /** Returns a map of propagated context objects, keyed by propagator name */
149
  Map<String, Object> getPropagatedContexts() {
150
    if (contextPropagators == null || contextPropagators.isEmpty()) {
1✔
151
      return new HashMap<>();
1✔
152
    }
153

154
    Header headers = startedAttributes.getHeader();
1✔
155
    if (headers == null) {
1✔
156
      return new HashMap<>();
1✔
157
    }
158

159
    Map<String, ByteBuffer> fields = headers.getFields();
1✔
160
    if (fields == null) {
1✔
161
      return new HashMap<>();
×
162
    }
163

164
    Map<String, byte[]> headerData = new HashMap<>();
1✔
165
    fields.forEach(
1✔
166
        (k, v) -> {
167
          headerData.put(k, org.apache.thrift.TBaseHelper.byteBufferToByteArray(v));
1✔
168
        });
1✔
169

170
    Map<String, Object> contextData = new HashMap<>();
1✔
171
    for (ContextPropagator propagator : contextPropagators) {
1✔
172
      contextData.put(propagator.getName(), propagator.deserializeContext(headerData));
1✔
173
    }
1✔
174

175
    return contextData;
1✔
176
  }
177

178
  void mergeSearchAttributes(SearchAttributes searchAttributes) {
179
    if (searchAttributes == null) {
1✔
180
      return;
×
181
    }
182
    if (this.searchAttributes == null) {
1✔
183
      this.searchAttributes = newSearchAttributes();
1✔
184
    }
185
    Map<String, ByteBuffer> current = this.searchAttributes.getIndexedFields();
1✔
186
    searchAttributes
1✔
187
        .getIndexedFields()
1✔
188
        .forEach(
1✔
189
            (k, v) -> {
190
              current.put(k, v);
1✔
191
            });
1✔
192
  }
1✔
193

194
  private SearchAttributes newSearchAttributes() {
195
    SearchAttributes result = new SearchAttributes();
1✔
196
    result.setIndexedFields(new HashMap<String, ByteBuffer>());
1✔
197
    return result;
1✔
198
  }
199
}
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

© 2026 Coveralls, Inc