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

temporalio / sdk-java / #433

20 Nov 2026 11:28PM UTC coverage: 71.886% (+0.05%) from 71.837%
#433

push

github

web-flow
Report storage driver types in worker heartbeats (#3230)

8791 of 14383 branches covered (61.12%)

Branch coverage included in aggregate %.

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

146 existing lines in 21 files now uncovered.

34692 of 46106 relevant lines covered (75.24%)

0.75 hits per line

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

80.1
/temporal-sdk/src/main/java/io/temporal/activity/LocalActivityOptions.java
1
package io.temporal.activity;
2

3
import com.google.common.base.Objects;
4
import io.temporal.common.Experimental;
5
import io.temporal.common.MethodRetry;
6
import io.temporal.common.RetryOptions;
7
import io.temporal.workflow.EventGroup;
8
import java.time.Duration;
9
import java.util.ArrayList;
10
import java.util.Collections;
11
import java.util.List;
12

13
/** Options used to configure how a local Activity is invoked. */
14
public final class LocalActivityOptions {
15

16
  public static Builder newBuilder() {
17
    return new Builder(null);
1 ✔
18
  }
19

20
  /**
21
   * @param o null is allowed.
22
   */
23
  public static Builder newBuilder(LocalActivityOptions o) {
24
    return new Builder(o);
1 ✔
25
  }
26

27
  public static LocalActivityOptions getDefaultInstance() {
28
    return DEFAULT_INSTANCE;
×
29
  }
30

31
  private static final LocalActivityOptions DEFAULT_INSTANCE;
32

33
  static {
34
    DEFAULT_INSTANCE = LocalActivityOptions.newBuilder().build();
1 ✔
35
  }
1 ✔
36

37
  public static final class Builder {
38
    private Duration scheduleToCloseTimeout;
39
    private Duration startToCloseTimeout;
40
    private Duration scheduleToStartTimeout;
41
    private Duration localRetryThreshold;
42
    private RetryOptions retryOptions;
43
    private Boolean doNotIncludeArgumentsIntoMarker;
44
    private String summary;
45
    private List<EventGroup> eventGroups;
46

47
    /** Copy Builder fields from the options. */
48
    private Builder(LocalActivityOptions options) {
1 ✔
49
      if (options == null) {
1 ✔
50
        return;
1 ✔
51
      }
52
      this.scheduleToCloseTimeout = options.getScheduleToCloseTimeout();
1 ✔
53
      this.startToCloseTimeout = options.getStartToCloseTimeout();
1 ✔
54
      this.scheduleToStartTimeout = options.getScheduleToStartTimeout();
1 ✔
55
      this.localRetryThreshold = options.getLocalRetryThreshold();
1 ✔
56
      this.retryOptions = options.getRetryOptions();
1 ✔
57
      this.doNotIncludeArgumentsIntoMarker = options.isDoNotIncludeArgumentsIntoMarker();
1 ✔
58
      this.summary = options.getSummary();
1 ✔
59
      if (!options.eventGroups.isEmpty()) {
1 ✔
60
        this.eventGroups = new ArrayList<>(options.eventGroups);
1 ✔
61
      }
62
    }
1 ✔
63

64
    /**
65
     * Total time that a workflow is willing to wait for an Activity to complete.
66
     *
67
     * <p>ScheduleToCloseTimeout limits the total time of an Activity's execution including retries
68
     * (use {@link #setStartToCloseTimeout(Duration)} to limit the time of a single attempt).
69
     *
70
     * <p>Either this option or {@link #setStartToCloseTimeout(Duration)} is required.
71
     *
72
     * <p>Defaults to unlimited.
73
     */
74
    public Builder setScheduleToCloseTimeout(Duration timeout) {
75
      if (timeout.isZero() || timeout.isNegative()) {
1 !
76
        throw new IllegalArgumentException("Illegal timeout: " + timeout);
×
77
      }
78
      this.scheduleToCloseTimeout = timeout;
1 ✔
79
      return this;
1 ✔
80
    }
81

82
    /**
83
     * Time that the Activity Task can stay in the Worker's internal Task Queue of Local Activities
84
     * until it's picked up by the Local Activity Executor.
85
     *
86
     * <p>ScheduleToStartTimeout is always non-retryable. Retrying after this timeout doesn't make
87
     * sense as it would just put the Activity Task back into the same Task Queue.
88
     *
89
     * <p>Defaults to unlimited.
90
     */
91
    public Builder setScheduleToStartTimeout(Duration timeout) {
92
      if (timeout.isZero() || timeout.isNegative()) {
1 !
93
        throw new IllegalArgumentException("Illegal timeout: " + timeout);
×
94
      }
95
      this.scheduleToStartTimeout = timeout;
1 ✔
96
      return this;
1 ✔
97
    }
98

99
    /**
100
     * Maximum time of a single Activity attempt.
101
     *
102
     * <p>If {@link #setScheduleToCloseTimeout(Duration)} is not provided, then this timeout is
103
     * required.
104
     */
105
    public Builder setStartToCloseTimeout(Duration timeout) {
106
      if (timeout.isZero() || timeout.isNegative()) {
1 !
107
        throw new IllegalArgumentException("Illegal timeout: " + timeout);
×
108
      }
109
      this.startToCloseTimeout = timeout;
1 ✔
110
      return this;
1 ✔
111
    }
112

113
    /**
114
     * Maximum time to wait between retries locally, while keeping the Workflow Task open via a
115
     * Heartbeat. If the delay between the attempts becomes larger that this threshold, a Workflow
116
     * Timer will be scheduled. Default value is Workflow Task Timeout multiplied by 3.
117
     */
118
    public Builder setLocalRetryThreshold(Duration localRetryThreshold) {
119
      if (localRetryThreshold.isZero() || localRetryThreshold.isNegative()) {
1 !
120
        throw new IllegalArgumentException("Illegal threshold: " + localRetryThreshold);
×
121
      }
122
      this.localRetryThreshold = localRetryThreshold;
1 ✔
123
      return this;
1 ✔
124
    }
125

126
    /**
127
     * {@link RetryOptions} that define how an Activity is retried in case of failure.
128
     *
129
     * <p>If not provided, the default activity retry policy is:
130
     *
131
     * <pre><code>
132
     *   InitialInterval:         1 second
133
     *   BackoffCoefficient:      2
134
     *   MaximumInterval:         100 seconds   // 100 * InitialInterval
135
     *   MaximumAttempts:         0             // Unlimited
136
     *   NonRetryableErrorTypes:  []
137
     * </pre></code>
138
     *
139
     * <p>If both {@link #setScheduleToCloseTimeout(Duration)} and {@link
140
     * RetryOptions.Builder#setMaximumAttempts(int)} are not set, the Activity will not be retried.
141
     *
142
     * <p>To ensure zero retries, set {@link RetryOptions.Builder#setMaximumAttempts(int)} to 1.
143
     */
144
    public Builder setRetryOptions(RetryOptions retryOptions) {
145
      this.retryOptions = retryOptions;
1 ✔
146
      return this;
1 ✔
147
    }
148

149
    /**
150
     * Merges {@link MethodRetry} annotation. The values of this builder take precedence over
151
     * annotated ones.
152
     */
153
    public Builder setMethodRetry(MethodRetry r) {
154
      if (r != null) {
1 !
155
        this.retryOptions = RetryOptions.merge(r, retryOptions);
×
156
      }
157
      return this;
1 ✔
158
    }
159

160
    /**
161
     * When set to true, the serialized arguments of the local Activity are not included in the
162
     * Marker Event that stores the local Activity's invocation result. The serialized arguments are
163
     * included only for human troubleshooting as they are never read by the SDK code. In some
164
     * cases, it is better to not include them to reduce the history size. The default value is set
165
     * to false.
166
     */
167
    public Builder setDoNotIncludeArgumentsIntoMarker(boolean doNotIncludeArgumentsIntoMarker) {
168
      this.doNotIncludeArgumentsIntoMarker = doNotIncludeArgumentsIntoMarker;
1 ✔
169
      return this;
1 ✔
170
    }
171

172
    /**
173
     * Single-line fixed summary for this activity that will appear in UI/CLI. This can be in
174
     * single-line Temporal Markdown format.
175
     *
176
     * <p>Default is none/empty.
177
     */
178
    public Builder setSummary(String summary) {
179
      this.summary = summary;
1 ✔
180
      return this;
1 ✔
181
    }
182

183
    /**
184
     * Event Groups to associate with this local activity, in addition to those in scope. Calls
185
     * accumulate.
186
     *
187
     * @see EventGroup
188
     */
189
    @Experimental
190
    public Builder addEventGroups(EventGroup... eventGroups) {
191
      if (eventGroups.length == 0) return this;
1 !
192
      if (this.eventGroups == null) {
1 !
193
        this.eventGroups = new ArrayList<>(eventGroups.length);
1 ✔
194
      }
195
      for (EventGroup group : eventGroups) {
1 ✔
196
        this.eventGroups.add(java.util.Objects.requireNonNull(group, "eventGroups"));
1 ✔
197
      }
198
      return this;
1 ✔
199
    }
200

201
    /**
202
     * Associates the given Event Groups, in addition to any already added. Calls accumulate.
203
     *
204
     * @see EventGroup
205
     */
206
    @Experimental
207
    public Builder addEventGroups(List<EventGroup> eventGroups) {
UNCOV
208
      return addEventGroups(eventGroups.toArray(new EventGroup[0]));
×
209
    }
210

211
    public Builder mergeActivityOptions(LocalActivityOptions override) {
212
      if (override == null) {
1 ✔
213
        return this;
1 ✔
214
      }
215
      this.scheduleToCloseTimeout =
1 ✔
216
          (override.scheduleToCloseTimeout == null)
1 ✔
217
              ? this.scheduleToCloseTimeout
1 ✔
218
              : override.scheduleToCloseTimeout;
1 ✔
219
      this.startToCloseTimeout =
1 ✔
220
          (override.startToCloseTimeout == null)
1 ✔
221
              ? this.startToCloseTimeout
1 ✔
222
              : override.startToCloseTimeout;
1 ✔
223
      this.scheduleToStartTimeout =
1 ✔
224
          (override.scheduleToStartTimeout == null)
1 !
225
              ? this.scheduleToStartTimeout
1 ✔
226
              : override.scheduleToStartTimeout;
1 ✔
227
      this.localRetryThreshold =
1 ✔
228
          (override.localRetryThreshold == null)
1 ✔
229
              ? this.localRetryThreshold
1 ✔
230
              : override.localRetryThreshold;
1 ✔
231
      this.retryOptions =
1 ✔
232
          (override.retryOptions == null) ? this.retryOptions : override.retryOptions;
1 ✔
233
      this.doNotIncludeArgumentsIntoMarker =
1 ✔
234
          (override.doNotIncludeArgumentsIntoMarker != null)
1 ✔
235
              ? override.doNotIncludeArgumentsIntoMarker
1 ✔
236
              : this.doNotIncludeArgumentsIntoMarker;
1 ✔
237
      this.summary = (override.summary == null) ? this.summary : override.summary;
1 !
238
      if (!override.eventGroups.isEmpty()) {
1 !
239
        if (this.eventGroups == null) {
×
UNCOV
240
          this.eventGroups = new ArrayList<>(override.eventGroups);
×
241
        } else {
UNCOV
242
          this.eventGroups.addAll(override.eventGroups);
×
243
        }
244
      }
245
      return this;
1 ✔
246
    }
247

248
    public LocalActivityOptions build() {
249
      return new LocalActivityOptions(
1 ✔
250
          startToCloseTimeout,
251
          scheduleToCloseTimeout,
252
          scheduleToStartTimeout,
253
          localRetryThreshold,
254
          retryOptions,
255
          doNotIncludeArgumentsIntoMarker,
256
          summary,
257
          eventGroups);
258
    }
259

260
    public LocalActivityOptions validateAndBuildWithDefaults() {
261
      if (startToCloseTimeout == null && scheduleToCloseTimeout == null) {
1 ✔
262
        throw new IllegalArgumentException(
1 ✔
263
            "one of the startToCloseTimeout or scheduleToCloseTimeout is required");
264
      }
265
      return new LocalActivityOptions(
1 ✔
266
          startToCloseTimeout,
267
          scheduleToCloseTimeout,
268
          scheduleToStartTimeout,
269
          localRetryThreshold,
270
          RetryOptions.newBuilder(retryOptions).validateBuildWithDefaults(),
1 ✔
271
          doNotIncludeArgumentsIntoMarker,
272
          summary,
273
          eventGroups);
274
    }
275
  }
276

277
  private final Duration scheduleToCloseTimeout;
278
  private final Duration localRetryThreshold;
279
  private final Duration startToCloseTimeout;
280
  private final Duration scheduleToStartTimeout;
281
  private final RetryOptions retryOptions;
282
  private final Boolean doNotIncludeArgumentsIntoMarker;
283
  private final String summary;
284
  private final List<EventGroup> eventGroups;
285

286
  private LocalActivityOptions(
287
      Duration startToCloseTimeout,
288
      Duration scheduleToCloseTimeout,
289
      Duration scheduleToStartTimeout,
290
      Duration localRetryThreshold,
291
      RetryOptions retryOptions,
292
      Boolean doNotIncludeArgumentsIntoMarker,
293
      String summary,
294
      List<EventGroup> eventGroups) {
1 ✔
295
    this.scheduleToCloseTimeout = scheduleToCloseTimeout;
1 ✔
296
    this.startToCloseTimeout = startToCloseTimeout;
1 ✔
297
    this.scheduleToStartTimeout = scheduleToStartTimeout;
1 ✔
298
    this.localRetryThreshold = localRetryThreshold;
1 ✔
299
    this.retryOptions = retryOptions;
1 ✔
300
    this.doNotIncludeArgumentsIntoMarker = doNotIncludeArgumentsIntoMarker;
1 ✔
301
    this.summary = summary;
1 ✔
302
    this.eventGroups =
1 ✔
303
        eventGroups == null || eventGroups.isEmpty()
1 !
304
            ? Collections.emptyList()
1 ✔
305
            : Collections.unmodifiableList(new ArrayList<>(eventGroups));
1 ✔
306
  }
1 ✔
307

308
  public Duration getScheduleToCloseTimeout() {
309
    return scheduleToCloseTimeout;
1 ✔
310
  }
311

312
  public Duration getStartToCloseTimeout() {
313
    return startToCloseTimeout;
1 ✔
314
  }
315

316
  public Duration getScheduleToStartTimeout() {
317
    return scheduleToStartTimeout;
1 ✔
318
  }
319

320
  public Duration getLocalRetryThreshold() {
321
    return localRetryThreshold;
1 ✔
322
  }
323

324
  public RetryOptions getRetryOptions() {
325
    return retryOptions;
1 ✔
326
  }
327

328
  public boolean isDoNotIncludeArgumentsIntoMarker() {
329
    return doNotIncludeArgumentsIntoMarker != null && doNotIncludeArgumentsIntoMarker;
1 ✔
330
  }
331

332
  public String getSummary() {
333
    return summary;
1 ✔
334
  }
335

336
  /**
337
   * @see LocalActivityOptions.Builder#addEventGroups(EventGroup...)
338
   */
339
  @Experimental
340
  public List<EventGroup> getEventGroups() {
341
    return eventGroups;
1 ✔
342
  }
343

344
  public Builder toBuilder() {
345
    return new Builder(this);
1 ✔
346
  }
347

348
  @Override
349
  public boolean equals(Object o) {
350
    if (this == o) return true;
1 !
351
    if (!(o instanceof LocalActivityOptions)) return false;
1 !
352
    LocalActivityOptions that = (LocalActivityOptions) o;
1 ✔
353
    return Objects.equal(doNotIncludeArgumentsIntoMarker, that.doNotIncludeArgumentsIntoMarker)
1 !
354
        && Objects.equal(scheduleToCloseTimeout, that.scheduleToCloseTimeout)
1 !
355
        && Objects.equal(startToCloseTimeout, that.startToCloseTimeout)
1 !
356
        && Objects.equal(scheduleToStartTimeout, that.scheduleToStartTimeout)
1 !
357
        && Objects.equal(localRetryThreshold, that.localRetryThreshold)
1 !
358
        && Objects.equal(retryOptions, that.retryOptions)
1 !
359
        && Objects.equal(summary, that.summary)
1 !
360
        && Objects.equal(eventGroups, that.eventGroups);
1 !
361
  }
362

363
  @Override
364
  public int hashCode() {
UNCOV
365
    return Objects.hashCode(
×
366
        scheduleToCloseTimeout,
367
        startToCloseTimeout,
368
        scheduleToStartTimeout,
369
        localRetryThreshold,
370
        retryOptions,
371
        doNotIncludeArgumentsIntoMarker,
372
        summary,
373
        eventGroups);
374
  }
375

376
  @Override
377
  public String toString() {
UNCOV
378
    return "LocalActivityOptions{"
×
379
        + "scheduleToCloseTimeout="
380
        + scheduleToCloseTimeout
381
        + ", localRetryThreshold="
382
        + localRetryThreshold
383
        + ", startToCloseTimeout="
384
        + startToCloseTimeout
385
        + ", retryOptions="
386
        + retryOptions
387
        + ", doNotIncludeArgumentsIntoMarker="
UNCOV
388
        + isDoNotIncludeArgumentsIntoMarker()
×
389
        + ", summary="
390
        + summary
391
        + ", eventGroups="
392
        + eventGroups
393
        + '}';
394
  }
395
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc