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

temporalio / sdk-java / #343

31 Oct 2024 06:31PM UTC coverage: 75.148% (-3.6%) from 78.794%
#343

push

github

web-flow
Fix jacoco coverage (#2304)

5139 of 8240 branches covered (62.37%)

Branch coverage included in aggregate %.

22841 of 28993 relevant lines covered (78.78%)

0.79 hits per line

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

83.78
/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
  /**
39
   * If present, it will cause an immediate WFT failure instead of providing LA result to the
40
   * workflow code.
41
   */
42
  private final @Nullable ProcessingErrorResult processingError;
43

44
  static LocalActivityResult completed(ActivityTaskHandler.Result ahResult, int attempt) {
45
    return new LocalActivityResult(
1✔
46
        ahResult.getActivityId(), attempt, ahResult.getTaskCompleted(), null, null, null);
1✔
47
  }
48

49
  static LocalActivityResult failed(
50
      String activityId,
51
      int attempt,
52
      RetryState retryState,
53
      Failure timeoutFailure,
54
      @Nullable Duration backoff) {
55
    ExecutionFailedResult failedResult =
1✔
56
        new ExecutionFailedResult(retryState, timeoutFailure, backoff);
57
    return new LocalActivityResult(activityId, attempt, null, failedResult, null, null);
1✔
58
  }
59

60
  static LocalActivityResult cancelled(ActivityTaskHandler.Result ahResult, int attempt) {
61
    return new LocalActivityResult(
×
62
        ahResult.getActivityId(), attempt, null, null, ahResult.getTaskCanceled(), null);
×
63
  }
64

65
  /** result created by this factory method will lead to as immediate WFT failure as possible. */
66
  static LocalActivityResult processingFailed(String activityId, int attempt, Throwable ex) {
67
    return new LocalActivityResult(
1✔
68
        activityId, attempt, null, null, null, new ProcessingErrorResult(ex));
69
  }
70

71
  /**
72
   * Only zero (manual activity completion) or one request is allowed. Task token and identity
73
   * fields shouldn't be filled in. Retry options are the service call. These options override the
74
   * default ones set on the activity worker.
75
   */
76
  public LocalActivityResult(
77
      @Nonnull String activityId,
78
      int lastAttempt,
79
      @Nullable RespondActivityTaskCompletedRequest executionCompleted,
80
      @Nullable ExecutionFailedResult executionFailed,
81
      @Nullable RespondActivityTaskCanceledRequest executionCanceled,
82
      @Nullable ProcessingErrorResult processingError) {
1✔
83
    this.activityId = activityId;
1✔
84
    this.lastAttempt = lastAttempt;
1✔
85
    this.executionCompleted = executionCompleted;
1✔
86
    this.executionFailed = executionFailed;
1✔
87
    this.executionCanceled = executionCanceled;
1✔
88
    this.processingError = processingError;
1✔
89
  }
1✔
90

91
  @Nonnull
92
  public String getActivityId() {
93
    return activityId;
1✔
94
  }
95

96
  public int getLastAttempt() {
97
    return lastAttempt;
1✔
98
  }
99

100
  @Nullable
101
  public RespondActivityTaskCompletedRequest getExecutionCompleted() {
102
    return executionCompleted;
1✔
103
  }
104

105
  @Nullable
106
  public ExecutionFailedResult getExecutionFailed() {
107
    return executionFailed;
1✔
108
  }
109

110
  @Nullable
111
  public RespondActivityTaskCanceledRequest getExecutionCanceled() {
112
    return executionCanceled;
×
113
  }
114

115
  @Nullable
116
  public ProcessingErrorResult getProcessingError() {
117
    return processingError;
1✔
118
  }
119

120
  @Override
121
  public String toString() {
122
    return "LocalActivityResult{"
×
123
        + "activityId='"
124
        + activityId
125
        + '\''
126
        + ", lastAttempt="
127
        + lastAttempt
128
        + ", executionCompleted="
129
        + executionCompleted
130
        + ", executionFailed="
131
        + executionFailed
132
        + ", executionCanceled="
133
        + executionCanceled
134
        + ", processingError="
135
        + processingError
136
        + '}';
137
  }
138

139
  public static class ExecutionFailedResult {
140
    @Nonnull private final RetryState retryState;
141
    @Nonnull private final Failure failure;
142
    @Nullable private final Duration backoff;
143

144
    public ExecutionFailedResult(
145
        @Nonnull RetryState retryState, @Nonnull Failure failure, @Nullable Duration backoff) {
1✔
146
      this.retryState = retryState;
1✔
147
      this.failure = failure;
1✔
148
      this.backoff = backoff;
1✔
149
    }
1✔
150

151
    @Nonnull
152
    public RetryState getRetryState() {
153
      return retryState;
1✔
154
    }
155

156
    @Nonnull
157
    public Failure getFailure() {
158
      return failure;
1✔
159
    }
160

161
    @Nullable
162
    public Duration getBackoff() {
163
      return backoff;
1✔
164
    }
165

166
    public boolean isTimeout() {
167
      return failure.hasTimeoutFailureInfo();
1✔
168
    }
169

170
    @Override
171
    public String toString() {
172
      return "ExecutionFailedResult{"
×
173
          + "retryState="
174
          + retryState
175
          + ", failure="
176
          + failure
177
          + ", backoff="
178
          + backoff
179
          + '}';
180
    }
181
  }
182

183
  public static class ProcessingErrorResult {
184
    @Nonnull private final Throwable throwable;
185

186
    public ProcessingErrorResult(@Nonnull Throwable throwable) {
1✔
187
      this.throwable = throwable;
1✔
188
    }
1✔
189

190
    @Nonnull
191
    public Throwable getThrowable() {
192
      return throwable;
1✔
193
    }
194

195
    @Override
196
    public String toString() {
197
      return "ProcessingErrorResult{" + "throwable=" + throwable + '}';
×
198
    }
199
  }
200
}
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