Skip to content

Fix newExternalWorkflowStub on a interfaces without a WorkflowMethod #2531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ExternalWorkflowInvocationHandler(
WorkflowExecution execution,
WorkflowOutboundCallsInterceptor workflowOutboundCallsInterceptor,
Functions.Proc1<String> assertReadOnly) {
this.workflowMetadata = POJOWorkflowInterfaceMetadata.newInstance(workflowInterface);
this.workflowMetadata = POJOWorkflowInterfaceMetadata.newInstance(workflowInterface, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got a bit confused on this trailing param reading:

if true, methods of the {@code anInterface} that are
annotated with {@link WorkflowMethod}, {@link QueryMethod}, {@link UpdateMethod}, {@link
UpdateValidatorMethod} or {@link SignalMethod} are processed like {@code current} is a
workflow interface even if it is not annotated with {@link WorkflowInterface} itself.

That'd make me think the default of true should work with non-workflow interfaces. But maybe I'm misunderstanding what was meant there.

this.stub =
new ExternalWorkflowStubImpl(execution, workflowOutboundCallsInterceptor, assertReadOnly);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package io.temporal.workflow;

import static org.junit.Assert.assertEquals;

import io.temporal.api.common.v1.WorkflowExecution;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowOptions;
import io.temporal.client.WorkflowStub;
import io.temporal.testing.internal.SDKTestWorkflowRule;
import java.time.Duration;
import org.junit.Rule;
import org.junit.Test;

public class ExternalWorkflowInterfaceInheritanceTest {

@Rule
public SDKTestWorkflowRule testWorkflowRule =
SDKTestWorkflowRule.newBuilder()
.setWorkflowTypes(TargetWorkflowImpl.class, SignalerWorkflowImpl.class)
.build();

@Test
public void testSignalWithParentInterface() {
WorkflowOptions options =
WorkflowOptions.newBuilder()
.setWorkflowRunTimeout(Duration.ofSeconds(30))
.setWorkflowTaskTimeout(Duration.ofSeconds(2))
.setTaskQueue(testWorkflowRule.getTaskQueue())
.build();
TargetWorkflow target =
testWorkflowRule.getWorkflowClient().newWorkflowStub(TargetWorkflow.class, options);
WorkflowExecution execution = WorkflowClient.start(target::execute);

SignalerWorkflow signaler =
testWorkflowRule.newWorkflowStubTimeoutOptions(SignalerWorkflow.class);
signaler.execute(execution.getWorkflowId());

String result = WorkflowStub.fromTyped(target).getResult(String.class);
assertEquals("retried", result);
}

public interface Retryable {
@SignalMethod
void retryNow();
}

@WorkflowInterface
public interface TargetWorkflow extends Retryable {
@WorkflowMethod
String execute();
}

public static class TargetWorkflowImpl implements TargetWorkflow {
private String status = "started";

@Override
public String execute() {
Workflow.await(() -> status.equals("retried"));
return status;
}

@Override
public void retryNow() {
status = "retried";
}
}

@WorkflowInterface
public interface SignalerWorkflow {
@WorkflowMethod
void execute(String workflowId);
}

public static class SignalerWorkflowImpl implements SignalerWorkflow {
@Override
public void execute(String workflowId) {
Retryable stub = Workflow.newExternalWorkflowStub(Retryable.class, workflowId);
stub.retryNow();
}
}
}
Loading