Skip to content

Commit 2d9b906

Browse files
Fix newExternalWorkflowStub on a interfaces without a WorkflowMethod (#2531)
Fix a bug causing newExternalWorkflowStub to fail on interfaces without WorkflowMethod
1 parent f45c947 commit 2d9b906

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

temporal-sdk/src/main/java/io/temporal/internal/sync/ExternalWorkflowInvocationHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public ExternalWorkflowInvocationHandler(
2020
WorkflowExecution execution,
2121
WorkflowOutboundCallsInterceptor workflowOutboundCallsInterceptor,
2222
Functions.Proc1<String> assertReadOnly) {
23-
this.workflowMetadata = POJOWorkflowInterfaceMetadata.newInstance(workflowInterface);
23+
this.workflowMetadata = POJOWorkflowInterfaceMetadata.newInstance(workflowInterface, false);
2424
this.stub =
2525
new ExternalWorkflowStubImpl(execution, workflowOutboundCallsInterceptor, assertReadOnly);
2626
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package io.temporal.workflow;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import io.temporal.api.common.v1.WorkflowExecution;
6+
import io.temporal.client.WorkflowClient;
7+
import io.temporal.client.WorkflowOptions;
8+
import io.temporal.client.WorkflowStub;
9+
import io.temporal.testing.internal.SDKTestWorkflowRule;
10+
import java.time.Duration;
11+
import org.junit.Rule;
12+
import org.junit.Test;
13+
14+
public class ExternalWorkflowInterfaceInheritanceTest {
15+
16+
@Rule
17+
public SDKTestWorkflowRule testWorkflowRule =
18+
SDKTestWorkflowRule.newBuilder()
19+
.setWorkflowTypes(TargetWorkflowImpl.class, SignalerWorkflowImpl.class)
20+
.build();
21+
22+
@Test
23+
public void testSignalWithParentInterface() {
24+
WorkflowOptions options =
25+
WorkflowOptions.newBuilder()
26+
.setWorkflowRunTimeout(Duration.ofSeconds(30))
27+
.setWorkflowTaskTimeout(Duration.ofSeconds(2))
28+
.setTaskQueue(testWorkflowRule.getTaskQueue())
29+
.build();
30+
TargetWorkflow target =
31+
testWorkflowRule.getWorkflowClient().newWorkflowStub(TargetWorkflow.class, options);
32+
WorkflowExecution execution = WorkflowClient.start(target::execute);
33+
34+
SignalerWorkflow signaler =
35+
testWorkflowRule.newWorkflowStubTimeoutOptions(SignalerWorkflow.class);
36+
signaler.execute(execution.getWorkflowId());
37+
38+
String result = WorkflowStub.fromTyped(target).getResult(String.class);
39+
assertEquals("retried", result);
40+
}
41+
42+
public interface Retryable {
43+
@SignalMethod
44+
void retryNow();
45+
}
46+
47+
@WorkflowInterface
48+
public interface TargetWorkflow extends Retryable {
49+
@WorkflowMethod
50+
String execute();
51+
}
52+
53+
public static class TargetWorkflowImpl implements TargetWorkflow {
54+
private String status = "started";
55+
56+
@Override
57+
public String execute() {
58+
Workflow.await(() -> status.equals("retried"));
59+
return status;
60+
}
61+
62+
@Override
63+
public void retryNow() {
64+
status = "retried";
65+
}
66+
}
67+
68+
@WorkflowInterface
69+
public interface SignalerWorkflow {
70+
@WorkflowMethod
71+
void execute(String workflowId);
72+
}
73+
74+
public static class SignalerWorkflowImpl implements SignalerWorkflow {
75+
@Override
76+
public void execute(String workflowId) {
77+
Retryable stub = Workflow.newExternalWorkflowStub(Retryable.class, workflowId);
78+
stub.retryNow();
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)