• 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

87.88
/temporal-sdk/src/main/java/io/temporal/internal/common/RetryOptionsUtils.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.common;
22

23
import io.grpc.Deadline;
24
import io.temporal.api.common.v1.RetryPolicy;
25
import io.temporal.common.RetryOptions;
26
import io.temporal.failure.ActivityFailure;
27
import io.temporal.failure.ApplicationFailure;
28
import io.temporal.failure.ChildWorkflowFailure;
29
import java.time.Duration;
30
import java.util.concurrent.TimeUnit;
31
import javax.annotation.Nullable;
32

33
public class RetryOptionsUtils {
×
34
  public static boolean isNotRetryable(RetryOptions o, @Nullable Throwable e) {
35
    if (e == null) {
1✔
36
      return false;
1✔
37
    }
38
    if (e instanceof ActivityFailure || e instanceof ChildWorkflowFailure) {
1✔
39
      e = e.getCause();
×
40
    }
41
    String type =
42
        e instanceof ApplicationFailure
1✔
43
            ? ((ApplicationFailure) e).getType()
1✔
44
            : e.getClass().getName();
1✔
45
    return isNotRetryable(o, type);
1✔
46
  }
47

48
  public static boolean isNotRetryable(RetryOptions o, @Nullable String type) {
49
    if (type == null) {
1✔
50
      return false;
×
51
    }
52
    if (o.getDoNotRetry() != null) {
1✔
53
      for (String doNotRetry : o.getDoNotRetry()) {
1✔
54
        if (doNotRetry.equals(type)) {
1✔
55
          return true;
×
56
        }
57
      }
58
    }
59
    return false;
1✔
60
  }
61

62
  public static boolean areAttemptsReached(RetryOptions o, long attempt) {
63
    return (o.getMaximumAttempts() != 0 && attempt >= o.getMaximumAttempts());
1✔
64
  }
65

66
  public static boolean isDeadlineReached(@Nullable Deadline deadline, long sleepTimeMs) {
67
    return deadline != null && deadline.timeRemaining(TimeUnit.MILLISECONDS) < sleepTimeMs;
1✔
68
  }
69

70
  public static RetryOptions toRetryOptions(RetryPolicy retryPolicy) {
71
    RetryOptions.Builder roBuilder = RetryOptions.newBuilder();
1✔
72

73
    Duration maximumInterval = ProtobufTimeUtils.toJavaDuration(retryPolicy.getMaximumInterval());
1✔
74
    if (!maximumInterval.isZero()) {
1✔
75
      roBuilder.setMaximumInterval(maximumInterval);
1✔
76
    }
77

78
    Duration initialInterval = ProtobufTimeUtils.toJavaDuration(retryPolicy.getInitialInterval());
1✔
79
    if (!initialInterval.isZero()) {
1✔
80
      roBuilder.setInitialInterval(initialInterval);
1✔
81
    }
82

83
    if (retryPolicy.getBackoffCoefficient() >= 1) {
1✔
84
      roBuilder.setBackoffCoefficient(retryPolicy.getBackoffCoefficient());
1✔
85
    }
86

87
    if (retryPolicy.getMaximumAttempts() > 0) {
1✔
88
      roBuilder.setMaximumAttempts(retryPolicy.getMaximumAttempts());
1✔
89
    }
90

91
    roBuilder.setDoNotRetry(
1✔
92
        retryPolicy
93
            .getNonRetryableErrorTypesList()
1✔
94
            .toArray(new String[retryPolicy.getNonRetryableErrorTypesCount()]));
1✔
95

96
    return roBuilder.validateBuildWithDefaults();
1✔
97
  }
98
}
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