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

temporalio / sdk-java / #103

pending completion
#103

push

github-actions

web-flow
Implement retry of local activities for over local retry threshold duration (#1542)

Issue #1261

244 of 244 new or added lines in 16 files covered. (100.0%)

16122 of 19841 relevant lines covered (81.26%)

0.81 hits per line

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

82.76
/temporal-sdk/src/main/java/io/temporal/internal/worker/LocalActivityResult.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.internal.worker;
22

23
import io.temporal.api.enums.v1.RetryState;
24
import io.temporal.api.failure.v1.Failure;
25
import io.temporal.api.workflowservice.v1.RespondActivityTaskCanceledRequest;
26
import io.temporal.api.workflowservice.v1.RespondActivityTaskCompletedRequest;
27
import java.time.Duration;
28
import javax.annotation.Nonnull;
29
import javax.annotation.Nullable;
30

31
public final class LocalActivityResult {
32
  private final @Nonnull String activityId;
33
  private final int lastAttempt;
34
  private final @Nullable RespondActivityTaskCompletedRequest executionCompleted;
35
  private final @Nullable ExecutionFailedResult executionFailed;
36
  private final @Nullable RespondActivityTaskCanceledRequest executionCanceled;
37

38
  static LocalActivityResult completed(ActivityTaskHandler.Result ahResult, int attempt) {
39
    return new LocalActivityResult(
1✔
40
        ahResult.getActivityId(), attempt, ahResult.getTaskCompleted(), null, null);
1✔
41
  }
42

43
  static LocalActivityResult failed(
44
      String activityId,
45
      int attempt,
46
      RetryState retryState,
47
      Failure timeoutFailure,
48
      @Nullable Duration backoff) {
49
    ExecutionFailedResult failedResult =
1✔
50
        new ExecutionFailedResult(retryState, timeoutFailure, backoff);
51
    return new LocalActivityResult(activityId, attempt, null, failedResult, null);
1✔
52
  }
53

54
  static LocalActivityResult cancelled(ActivityTaskHandler.Result ahResult, int attempt) {
55
    return new LocalActivityResult(
×
56
        ahResult.getActivityId(), attempt, null, null, ahResult.getTaskCanceled());
×
57
  }
58

59
  /**
60
   * Only zero (manual activity completion) or one request is allowed. Task token and identity
61
   * fields shouldn't be filled in. Retry options are the service call. These options override the
62
   * default ones set on the activity worker.
63
   */
64
  public LocalActivityResult(
65
      @Nonnull String activityId,
66
      int lastAttempt,
67
      @Nullable RespondActivityTaskCompletedRequest executionCompleted,
68
      @Nullable ExecutionFailedResult executionFailed,
69
      @Nullable RespondActivityTaskCanceledRequest executionCanceled) {
1✔
70
    this.activityId = activityId;
1✔
71
    this.lastAttempt = lastAttempt;
1✔
72
    this.executionCompleted = executionCompleted;
1✔
73
    this.executionFailed = executionFailed;
1✔
74
    this.executionCanceled = executionCanceled;
1✔
75
  }
1✔
76

77
  @Nonnull
78
  public String getActivityId() {
79
    return activityId;
1✔
80
  }
81

82
  public int getLastAttempt() {
83
    return lastAttempt;
1✔
84
  }
85

86
  @Nullable
87
  public RespondActivityTaskCompletedRequest getExecutionCompleted() {
88
    return executionCompleted;
1✔
89
  }
90

91
  @Nullable
92
  public ExecutionFailedResult getExecutionFailed() {
93
    return executionFailed;
1✔
94
  }
95

96
  @Nullable
97
  public RespondActivityTaskCanceledRequest getExecutionCanceled() {
98
    return executionCanceled;
×
99
  }
100

101
  @Override
102
  public String toString() {
103
    return "LocalActivityResult{"
×
104
        + "activityId='"
105
        + activityId
106
        + '\''
107
        + ", lastAttempt="
108
        + lastAttempt
109
        + ", executionCompleted="
110
        + executionCompleted
111
        + ", executionFailed="
112
        + executionFailed
113
        + ", executionCanceled="
114
        + executionCanceled
115
        + '}';
116
  }
117

118
  public static class ExecutionFailedResult {
119
    @Nonnull private final RetryState retryState;
120
    @Nonnull private final Failure failure;
121
    @Nullable private final Duration backoff;
122

123
    public ExecutionFailedResult(
124
        @Nonnull RetryState retryState, @Nonnull Failure failure, @Nullable Duration backoff) {
1✔
125
      this.retryState = retryState;
1✔
126
      this.failure = failure;
1✔
127
      this.backoff = backoff;
1✔
128
    }
1✔
129

130
    @Nonnull
131
    public RetryState getRetryState() {
132
      return retryState;
1✔
133
    }
134

135
    @Nonnull
136
    public Failure getFailure() {
137
      return failure;
1✔
138
    }
139

140
    @Nullable
141
    public Duration getBackoff() {
142
      return backoff;
1✔
143
    }
144

145
    public boolean isTimeout() {
146
      return failure.hasTimeoutFailureInfo();
1✔
147
    }
148

149
    @Override
150
    public String toString() {
151
      return "ExecutionFailedResult{"
×
152
          + "retryState="
153
          + retryState
154
          + ", failure="
155
          + failure
156
          + ", backoff="
157
          + backoff
158
          + '}';
159
    }
160
  }
161
}
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