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

temporalio / sdk-java / #265

05 Jun 2024 01:39AM UTC coverage: 77.459% (-0.005%) from 77.464%
#265

push

github

web-flow
Add exception for calling an update method on a stub (#2095)

Add exception for calling an update method on a stub

0 of 4 new or added lines in 2 files covered. (0.0%)

19233 of 24830 relevant lines covered (77.46%)

0.77 hits per line

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

73.33
/temporal-sdk/src/main/java/io/temporal/internal/sync/ExternalWorkflowInvocationHandler.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 io.temporal.api.common.v1.WorkflowExecution;
24
import io.temporal.common.interceptors.WorkflowOutboundCallsInterceptor;
25
import io.temporal.common.metadata.POJOWorkflowInterfaceMetadata;
26
import io.temporal.common.metadata.POJOWorkflowMethodMetadata;
27
import io.temporal.workflow.ExternalWorkflowStub;
28
import io.temporal.workflow.Functions;
29
import java.lang.reflect.InvocationHandler;
30
import java.lang.reflect.Method;
31

32
/** Dynamic implementation of a strongly typed child workflow interface. */
33
class ExternalWorkflowInvocationHandler implements InvocationHandler {
34

35
  private final ExternalWorkflowStub stub;
36
  private final POJOWorkflowInterfaceMetadata workflowMetadata;
37

38
  public ExternalWorkflowInvocationHandler(
39
      Class<?> workflowInterface,
40
      WorkflowExecution execution,
41
      WorkflowOutboundCallsInterceptor workflowOutboundCallsInterceptor,
42
      Functions.Proc1<String> assertReadOnly) {
1✔
43
    this.workflowMetadata = POJOWorkflowInterfaceMetadata.newInstance(workflowInterface);
1✔
44
    this.stub =
1✔
45
        new ExternalWorkflowStubImpl(execution, workflowOutboundCallsInterceptor, assertReadOnly);
46
  }
1✔
47

48
  @Override
49
  public Object invoke(Object proxy, Method method, Object[] args) {
50
    // Implement StubMarker
51
    if (method.getName().equals(StubMarker.GET_UNTYPED_STUB_METHOD)) {
1✔
52
      return stub;
1✔
53
    }
54
    POJOWorkflowMethodMetadata methodMetadata = workflowMetadata.getMethodMetadata(method);
1✔
55
    switch (methodMetadata.getType()) {
1✔
56
      case QUERY:
57
        throw new UnsupportedOperationException(
×
58
            "Query is not supported from workflow to workflow. "
59
                + "Use activity that perform the query instead.");
60
      case WORKFLOW:
61
        throw new IllegalStateException(
×
62
            "Cannot start a workflow with an external workflow stub "
63
                + "created through Workflow.newExternalWorkflowStub");
64
      case SIGNAL:
65
        stub.signal(methodMetadata.getName(), args);
1✔
66
        break;
1✔
67
      case UPDATE:
NEW
68
        throw new UnsupportedOperationException(
×
69
            "Cannot update a workflow with an external workflow stub "
70
                + "created through Workflow.newExternalWorkflowStub");
71
      default:
NEW
72
        throw new IllegalStateException("unreachable");
×
73
    }
74
    return null;
1✔
75
  }
76
}
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