-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow creating a stub of an update only interface
- Loading branch information
1 parent
1f7a59c
commit a64d92c
Showing
2 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateAnnotationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package io.temporal.workflow.updateTest; | ||
|
||
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.testing.internal.SDKTestOptions; | ||
import io.temporal.testing.internal.SDKTestWorkflowRule; | ||
import io.temporal.workflow.UpdateMethod; | ||
import io.temporal.workflow.Workflow; | ||
import io.temporal.workflow.WorkflowInterface; | ||
import io.temporal.workflow.WorkflowMethod; | ||
import java.util.Optional; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class UpdateAnnotationTest { | ||
@Rule | ||
public SDKTestWorkflowRule testWorkflowRule = | ||
SDKTestWorkflowRule.newBuilder().setWorkflowTypes(WorkflowImpl.class).build(); | ||
|
||
@Test | ||
public void testUpdateOnlyInterface() { | ||
// Verify a stub to an interface with only @UpdateMethod can be created. | ||
WorkflowClient workflowClient = testWorkflowRule.getWorkflowClient(); | ||
WorkflowOptions options = | ||
SDKTestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()).toBuilder() | ||
.build(); | ||
WorkflowTestInterface workflow = | ||
workflowClient.newWorkflowStub(WorkflowTestInterface.class, options); | ||
|
||
WorkflowExecution execution = WorkflowClient.start(workflow::execute); | ||
|
||
UpdateWorkflowInterface updateOnlyWorkflow = | ||
workflowClient.newWorkflowStub(UpdateWorkflowInterface.class, execution.getWorkflowId()); | ||
updateOnlyWorkflow.update(); | ||
|
||
String result = | ||
testWorkflowRule | ||
.getWorkflowClient() | ||
.newUntypedWorkflowStub(execution, Optional.empty()) | ||
.getResult(String.class); | ||
assertEquals("success", result); | ||
} | ||
|
||
public interface UpdateWorkflowInterface { | ||
@UpdateMethod | ||
void update(); | ||
} | ||
|
||
@WorkflowInterface | ||
public interface WorkflowTestInterface extends UpdateWorkflowInterface { | ||
@WorkflowMethod | ||
String execute(); | ||
} | ||
|
||
public static class WorkflowImpl implements WorkflowTestInterface { | ||
boolean complete = false; | ||
|
||
@Override | ||
public String execute() { | ||
Workflow.await(() -> complete); | ||
return "success"; | ||
} | ||
|
||
@Override | ||
public void update() { | ||
complete = true; | ||
} | ||
} | ||
} |