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

temporalio / sdk-java / #181

pending completion
#181

push

github-actions

web-flow
Properly wrap exceptions from schedule client (#1827)

Wrap schedule exception

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

18557 of 23894 relevant lines covered (77.66%)

0.78 hits per line

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

94.44
/temporal-sdk/src/main/java/io/temporal/internal/sync/ActivityInvocationHandler.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.sync;
22

23
import com.google.common.annotations.VisibleForTesting;
24
import io.temporal.activity.ActivityOptions;
25
import io.temporal.common.MethodRetry;
26
import io.temporal.common.interceptors.WorkflowOutboundCallsInterceptor;
27
import io.temporal.workflow.ActivityStub;
28
import io.temporal.workflow.Functions;
29
import java.lang.reflect.InvocationHandler;
30
import java.lang.reflect.Method;
31
import java.util.HashMap;
32
import java.util.Map;
33
import java.util.function.Function;
34

35
@VisibleForTesting
36
public class ActivityInvocationHandler extends ActivityInvocationHandlerBase {
37
  private final ActivityOptions options;
38
  private final Map<String, ActivityOptions> activityMethodOptions;
39
  private final WorkflowOutboundCallsInterceptor activityExecutor;
40
  private final Functions.Proc assertReadOnly;
41

42
  @VisibleForTesting
43
  public static InvocationHandler newInstance(
44
      Class<?> activityInterface,
45
      ActivityOptions options,
46
      Map<String, ActivityOptions> methodOptions,
47
      WorkflowOutboundCallsInterceptor activityExecutor,
48
      Functions.Proc assertReadOnly) {
49
    return new ActivityInvocationHandler(
1✔
50
        activityInterface, activityExecutor, options, methodOptions, assertReadOnly);
51
  }
52

53
  private ActivityInvocationHandler(
54
      Class<?> activityInterface,
55
      WorkflowOutboundCallsInterceptor activityExecutor,
56
      ActivityOptions options,
57
      Map<String, ActivityOptions> methodOptions,
58
      Functions.Proc assertReadOnly) {
59
    super(activityInterface);
1✔
60
    this.options = options;
1✔
61
    this.activityMethodOptions = (methodOptions == null) ? new HashMap<>() : methodOptions;
1✔
62
    this.activityExecutor = activityExecutor;
1✔
63
    this.assertReadOnly = assertReadOnly;
1✔
64
  }
1✔
65

66
  @Override
67
  protected Function<Object[], Object> getActivityFunc(
68
      Method method, MethodRetry methodRetry, String activityName) {
69
    Function<Object[], Object> function;
70
    ActivityOptions merged =
1✔
71
        ActivityOptions.newBuilder(options)
1✔
72
            .mergeActivityOptions(this.activityMethodOptions.get(activityName))
1✔
73
            .mergeMethodRetry(methodRetry)
1✔
74
            .build();
1✔
75
    if (merged.getStartToCloseTimeout() == null && merged.getScheduleToCloseTimeout() == null) {
1✔
76
      throw new IllegalArgumentException(
×
77
          "Both StartToCloseTimeout and ScheduleToCloseTimeout aren't specified for "
78
              + activityName
79
              + " activity. Please set at least one of the above through the ActivityStub or WorkflowImplementationOptions.");
80
    }
81
    ActivityStub stub = ActivityStubImpl.newInstance(merged, activityExecutor, assertReadOnly);
1✔
82
    function =
1✔
83
        (a) -> stub.execute(activityName, method.getReturnType(), method.getGenericReturnType(), a);
1✔
84
    return function;
1✔
85
  }
86
}
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