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

temporalio / sdk-java / #264

03 Jun 2024 04:52PM UTC coverage: 77.464% (-0.08%) from 77.542%
#264

push

github

web-flow
Require WaitForStage in StartUpdate (#2088)

10 of 15 new or added lines in 3 files covered. (66.67%)

18 existing lines in 6 files now uncovered.

19232 of 24827 relevant lines covered (77.46%)

0.77 hits per line

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

60.61
/temporal-sdk/src/main/java/io/temporal/client/UpdateOptions.java
1
/*
2
 * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3
 *
4
 * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
 *
6
 * Modifications copyright (C) 2017 Uber Technologies, Inc.
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this material except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

21
package io.temporal.client;
22

23
import com.google.common.base.Objects;
24
import java.lang.reflect.Type;
25
import java.util.UUID;
26

27
public final class UpdateOptions<T> {
28
  public static <T> UpdateOptions.Builder<T> newBuilder() {
29
    return new UpdateOptions.Builder<T>();
1✔
30
  }
31

32
  public static <T> UpdateOptions.Builder<T> newBuilder(Class<T> resultClass) {
33
    return new UpdateOptions.Builder<T>().setResultClass(resultClass);
1✔
34
  }
35

36
  public static <T> UpdateOptions.Builder<T> newBuilder(UpdateOptions<T> options) {
NEW
37
    return new UpdateOptions.Builder<T>(options);
×
38
  }
39

40
  public static UpdateOptions getDefaultInstance() {
41
    return DEFAULT_INSTANCE;
×
42
  }
43

44
  private static final UpdateOptions DEFAULT_INSTANCE;
45

46
  static {
47
    DEFAULT_INSTANCE = UpdateOptions.newBuilder().build();
1✔
48
  }
1✔
49

50
  private final String updateName;
51
  private final String updateId;
52
  private final String firstExecutionRunId;
53
  private final WorkflowUpdateStage waitForStage;
54
  private final Class<T> resultClass;
55
  private final Type resultType;
56

57
  private UpdateOptions(
58
      String updateName,
59
      String updateId,
60
      String firstExecutionRunId,
61
      WorkflowUpdateStage waitForStage,
62
      Class<T> resultClass,
63
      Type resultType) {
1✔
64
    this.updateName = updateName;
1✔
65
    this.updateId = updateId;
1✔
66
    this.firstExecutionRunId = firstExecutionRunId;
1✔
67
    this.waitForStage = waitForStage;
1✔
68
    this.resultClass = resultClass;
1✔
69
    this.resultType = resultType;
1✔
70
  }
1✔
71

72
  public String getUpdateName() {
73
    return updateName;
1✔
74
  }
75

76
  public String getUpdateId() {
77
    return updateId;
1✔
78
  }
79

80
  public String getFirstExecutionRunId() {
81
    return firstExecutionRunId;
1✔
82
  }
83

84
  public WorkflowUpdateStage getWaitForStage() {
85
    return waitForStage;
1✔
86
  }
87

88
  public Class<T> getResultClass() {
89
    return resultClass;
1✔
90
  }
91

92
  public Type getResultType() {
93
    return resultType;
1✔
94
  }
95

96
  public UpdateOptions.Builder toBuilder() {
97
    return new UpdateOptions.Builder(this);
×
98
  }
99

100
  @Override
101
  public boolean equals(Object o) {
102
    if (this == o) return true;
×
103
    if (o == null || getClass() != o.getClass()) return false;
×
104
    UpdateOptions that = (UpdateOptions) o;
×
105
    return Objects.equal(updateName, that.updateName)
×
106
        && updateId == that.updateId
107
        && firstExecutionRunId == that.firstExecutionRunId
NEW
108
        && waitForStage.equals(that.waitForStage)
×
109
        && resultClass.equals(that.resultClass)
×
110
        && resultType.equals(that.resultType);
×
111
  }
112

113
  @Override
114
  public int hashCode() {
115
    return Objects.hashCode(
×
116
        updateName, updateId, firstExecutionRunId, waitForStage, resultClass, resultType);
117
  }
118

119
  @Override
120
  public String toString() {
121
    return "StartUpdateOptions{"
×
122
        + "updateName='"
123
        + updateName
124
        + ", updateId="
125
        + updateId
126
        + ", firstExecutionRunId="
127
        + firstExecutionRunId
128
        + ", waitForStage="
129
        + waitForStage
130
        + ", resultClass="
131
        + resultClass
132
        + ", resultType='"
133
        + resultType
134
        + '}';
135
  }
136

137
  /**
138
   * Validates property values.
139
   *
140
   * @throws IllegalStateException if validation fails.
141
   */
142
  public void validate() {
143
    if (updateName == null || updateName.isEmpty()) {
1✔
144
      throw new IllegalStateException("updateName must be a non empty string");
×
145
    }
146
    if (resultClass == null) {
1✔
147
      throw new IllegalStateException("resultClass must not be null");
×
148
    }
149
    if (waitForStage == null) {
1✔
NEW
150
      throw new IllegalStateException("waitForStage must not be null");
×
151
    }
152
    if (waitForStage.equals(WorkflowUpdateStage.ADMITTED)) {
1✔
NEW
153
      throw new IllegalStateException("waitForStage cannot be ADMITTED");
×
154
    }
155
  }
1✔
156

157
  public static final class Builder<T> {
158
    private String updateName;
159
    private String updateId;
160
    private String firstExecutionRunId;
161
    private WorkflowUpdateStage waitForStage;
162
    private Class<T> resultClass;
163
    private Type resultType;
164

165
    private Builder() {}
166

167
    private Builder(UpdateOptions<T> options) {
×
168
      if (options == null) {
×
169
        return;
×
170
      }
171
      this.updateName = options.updateName;
×
172
      this.updateId = options.updateId;
×
173
      this.firstExecutionRunId = options.firstExecutionRunId;
×
NEW
174
      this.waitForStage = options.waitForStage;
×
175
      this.resultClass = options.resultClass;
×
176
      this.resultType = options.resultType;
×
177
    }
×
178

179
    /** Name of the update handler. Usually it is a method name. */
180
    public Builder<T> setUpdateName(String updateName) {
181
      this.updateName = updateName;
1✔
182
      return this;
1✔
183
    }
184

185
    /**
186
     * The update ID is an application-layer identifier for the requested update. It must be unique
187
     * within the scope of a workflow execution.
188
     *
189
     * <p>Default value if not set: <b>Random UUID</b>
190
     */
191
    public Builder<T> setUpdateId(String updateId) {
192
      this.updateId = updateId;
1✔
193
      return this;
1✔
194
    }
195

196
    /**
197
     * The RunID expected to identify the first run in the workflow execution chain. If this
198
     * expectation does not match then the server will reject the update request with an error.
199
     *
200
     * <p>Default value if not set: <b>Empty String</b>
201
     */
202
    public Builder<T> setFirstExecutionRunId(String firstExecutionRunId) {
203
      this.firstExecutionRunId = firstExecutionRunId;
1✔
204
      return this;
1✔
205
    }
206

207
    /**
208
     * Specifies at what point in the update request life cycles this request should return.
209
     * Required to be set to one of the following values:
210
     *
211
     * <ul>
212
     *   <li><b>Accepted</b> Wait for the update to be accepted by the workflow.
213
     *   <li><b>Completed</b> Wait for the update to be completed by the workflow.
214
     * </ul>
215
     *
216
     * Admitted is not allowed as a value.
217
     */
218
    public Builder<T> setWaitForStage(WorkflowUpdateStage waitForStage) {
219
      this.waitForStage = waitForStage;
1✔
220
      return this;
1✔
221
    }
222

223
    /** The class of the update return value. */
224
    public Builder<T> setResultClass(Class<T> resultClass) {
225
      this.resultClass = resultClass;
1✔
226
      return this;
1✔
227
    }
228

229
    /**
230
     * The type of the update return value.
231
     *
232
     * <p>Default value if not set: <b>resultClass</b>
233
     */
234
    public Builder<T> setResultType(Type resultType) {
235
      this.resultType = resultType;
1✔
236
      return this;
1✔
237
    }
238

239
    /** Builds StartUpdateOptions with default values. */
240
    public UpdateOptions<T> build() {
241
      if (updateId == null || updateId.isEmpty()) {
1✔
242
        updateId = UUID.randomUUID().toString();
1✔
243
      }
244

245
      return new UpdateOptions<T>(
1✔
246
          updateName,
247
          updateId,
248
          firstExecutionRunId == null ? "" : firstExecutionRunId,
1✔
249
          waitForStage,
250
          resultClass,
251
          resultType == null ? resultClass : resultType);
1✔
252
    }
253
  }
254
}
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