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

temporalio / sdk-java / #296

06 Aug 2024 09:52PM UTC coverage: 77.714% (+0.009%) from 77.705%
#296

push

github

web-flow
Wrap GRPC::CANCELED and DEADLINE_EXCEEDED in new exception type (#2172)

* Wrap GRPC::CANCELED and DEADLINE_EXCEEDED

15 of 18 new or added lines in 3 files covered. (83.33%)

7 existing lines in 3 files now uncovered.

19894 of 25599 relevant lines covered (77.71%)

0.78 hits per line

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

82.93
/temporal-sdk/src/main/java/io/temporal/internal/client/LazyUpdateHandleImpl.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.client;
22

23
import io.grpc.Status;
24
import io.grpc.StatusRuntimeException;
25
import io.temporal.api.common.v1.WorkflowExecution;
26
import io.temporal.client.UpdateHandle;
27
import io.temporal.client.WorkflowException;
28
import io.temporal.client.WorkflowServiceException;
29
import io.temporal.common.Experimental;
30
import io.temporal.common.interceptors.WorkflowClientCallsInterceptor;
31
import io.temporal.serviceclient.CheckedExceptionWrapper;
32
import java.lang.reflect.Type;
33
import java.util.concurrent.CompletableFuture;
34
import java.util.concurrent.CompletionException;
35
import java.util.concurrent.TimeUnit;
36
import java.util.concurrent.TimeoutException;
37

38
@Experimental
39
public final class LazyUpdateHandleImpl<T> implements UpdateHandle<T> {
40

41
  private final WorkflowClientCallsInterceptor workflowClientInvoker;
42
  private final String workflowType;
43
  private final String updateName;
44
  private final String id;
45
  private final WorkflowExecution execution;
46
  private final Class<T> resultClass;
47
  private final Type resultType;
48
  private WorkflowClientCallsInterceptor.PollWorkflowUpdateOutput<T> waitCompletedPollCall;
49

50
  public LazyUpdateHandleImpl(
51
      WorkflowClientCallsInterceptor workflowClientInvoker,
52
      String workflowType,
53
      String updateName,
54
      String id,
55
      WorkflowExecution execution,
56
      Class<T> resultClass,
57
      Type resultType) {
1✔
58
    this.workflowClientInvoker = workflowClientInvoker;
1✔
59
    this.workflowType = workflowType;
1✔
60
    this.updateName = updateName;
1✔
61
    this.id = id;
1✔
62
    this.execution = execution;
1✔
63
    this.resultClass = resultClass;
1✔
64
    this.resultType = resultType;
1✔
65
  }
1✔
66

67
  @Override
68
  public WorkflowExecution getExecution() {
69
    return execution;
×
70
  }
71

72
  @Override
73
  public String getId() {
74
    return id;
×
75
  }
76

77
  @Override
78
  public CompletableFuture<T> getResultAsync(long timeout, TimeUnit unit) {
79

80
    WorkflowClientCallsInterceptor.PollWorkflowUpdateOutput<T> pollCall = null;
1✔
81

82
    // If waitCompleted was called, use the result from that call.
83
    synchronized (this) {
1✔
84
      if (waitCompletedPollCall != null) {
1✔
85
        pollCall = waitCompletedPollCall;
1✔
86
        waitCompletedPollCall = null;
1✔
87
      }
88
    }
1✔
89

90
    if (pollCall == null) {
1✔
91
      pollCall = pollUntilComplete(timeout, unit);
1✔
92
    }
93

94
    return pollCall
1✔
95
        .getResult()
1✔
96
        .exceptionally(
1✔
97
            failure -> {
98
              if (failure instanceof CompletionException) {
1✔
99
                // unwrap the CompletionException
100
                failure = ((Throwable) failure).getCause();
1✔
101
              }
102
              failure = CheckedExceptionWrapper.unwrap((Throwable) failure);
1✔
103
              if (failure instanceof Error) {
1✔
104
                throw (Error) failure;
×
105
              }
106
              if (failure instanceof StatusRuntimeException) {
1✔
107
                StatusRuntimeException sre = (StatusRuntimeException) failure;
1✔
108
                if (Status.Code.NOT_FOUND.equals(sre.getStatus().getCode())) {
1✔
109
                  // Currently no way to tell if the NOT_FOUND was because the workflow ID
110
                  // does not exist or because the update ID does not exist.
111
                  throw sre;
1✔
112
                }
NEW
113
                throw sre;
×
114
              } else if (failure instanceof WorkflowException) {
1✔
115
                throw (WorkflowException) failure;
1✔
UNCOV
116
              } else if (failure instanceof TimeoutException) {
×
NEW
117
                throw new CompletionException(failure);
×
118
              }
NEW
119
              throw new WorkflowServiceException(execution, workflowType, failure);
×
120
            });
121
  }
122

123
  @Override
124
  public CompletableFuture<T> getResultAsync() {
125
    return this.getResultAsync(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
1✔
126
  }
127

128
  // Can be called immediately after initialization to wait for the update to be completed, but
129
  // still have the result be returned by getResultAsync.
130
  void waitCompleted() {
131
    waitCompletedPollCall = pollUntilComplete(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
1✔
132
  }
1✔
133

134
  private WorkflowClientCallsInterceptor.PollWorkflowUpdateOutput<T> pollUntilComplete(
135
      long timeout, TimeUnit unit) {
136
    return workflowClientInvoker.pollWorkflowUpdate(
1✔
137
        new WorkflowClientCallsInterceptor.PollWorkflowUpdateInput<>(
138
            execution, updateName, id, resultClass, resultType, timeout, unit));
139
  }
140
}
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

© 2026 Coveralls, Inc