• 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

84.38
/temporal-sdk/src/main/java/io/temporal/internal/sync/ChildWorkflowInvocationHandler.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 static io.temporal.internal.common.InternalUtils.getValueOrDefault;
24

25
import io.temporal.common.CronSchedule;
26
import io.temporal.common.MethodRetry;
27
import io.temporal.common.interceptors.WorkflowOutboundCallsInterceptor;
28
import io.temporal.common.metadata.POJOWorkflowInterfaceMetadata;
29
import io.temporal.common.metadata.POJOWorkflowMethodMetadata;
30
import io.temporal.common.metadata.WorkflowMethodType;
31
import io.temporal.workflow.ChildWorkflowOptions;
32
import io.temporal.workflow.ChildWorkflowStub;
33
import io.temporal.workflow.Functions;
34
import java.lang.reflect.InvocationHandler;
35
import java.lang.reflect.Method;
36
import java.util.Optional;
37

38
/** Dynamic implementation of a strongly typed child workflow interface. */
39
class ChildWorkflowInvocationHandler implements InvocationHandler {
40

41
  private final ChildWorkflowStub stub;
42
  private final POJOWorkflowInterfaceMetadata workflowMetadata;
43

44
  ChildWorkflowInvocationHandler(
45
      Class<?> workflowInterface,
46
      ChildWorkflowOptions options,
47
      WorkflowOutboundCallsInterceptor outboundCallsInterceptor,
48
      Functions.Proc1<String> assertReadOnly) {
1✔
49
    workflowMetadata = POJOWorkflowInterfaceMetadata.newInstance(workflowInterface);
1✔
50
    Optional<POJOWorkflowMethodMetadata> workflowMethodMetadata =
1✔
51
        workflowMetadata.getWorkflowMethod();
1✔
52
    if (!workflowMethodMetadata.isPresent()) {
1✔
53
      throw new IllegalArgumentException(
×
54
          "Missing method annotated with @WorkflowMethod: " + workflowInterface.getName());
×
55
    }
56
    Method workflowMethod = workflowMethodMetadata.get().getWorkflowMethod();
1✔
57
    MethodRetry retryAnnotation = workflowMethod.getAnnotation(MethodRetry.class);
1✔
58
    CronSchedule cronSchedule = workflowMethod.getAnnotation(CronSchedule.class);
1✔
59
    ChildWorkflowOptions merged =
1✔
60
        ChildWorkflowOptions.newBuilder(options)
1✔
61
            .setMethodRetry(retryAnnotation)
1✔
62
            .setCronSchedule(cronSchedule)
1✔
63
            .validateAndBuildWithDefaults();
1✔
64
    this.stub =
1✔
65
        new ChildWorkflowStubImpl(
66
            workflowMethodMetadata.get().getName(),
1✔
67
            merged,
68
            outboundCallsInterceptor,
69
            assertReadOnly);
70
  }
1✔
71

72
  @Override
73
  public Object invoke(Object proxy, Method method, Object[] args) {
74
    // Implement StubMarker
75
    if (method.getName().equals(StubMarker.GET_UNTYPED_STUB_METHOD)) {
1✔
76
      return stub;
1✔
77
    }
78
    POJOWorkflowMethodMetadata methodMetadata = workflowMetadata.getMethodMetadata(method);
1✔
79
    WorkflowMethodType type = methodMetadata.getType();
1✔
80

81
    if (type == WorkflowMethodType.WORKFLOW) {
1✔
82
      return getValueOrDefault(
1✔
83
          stub.execute(method.getReturnType(), method.getGenericReturnType(), args),
1✔
84
          method.getReturnType());
1✔
85
    }
86
    if (type == WorkflowMethodType.SIGNAL) {
1✔
87
      stub.signal(methodMetadata.getName(), args);
1✔
88
      return null;
1✔
89
    }
90
    if (type == WorkflowMethodType.QUERY) {
×
91
      throw new UnsupportedOperationException(
×
92
          "Query is not supported from workflow to workflow. "
93
              + "Use activity that perform the query instead.");
94
    }
95
    throw new IllegalArgumentException("unreachable");
×
96
  }
97
}
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