Skip to content

Commit cdeb5e1

Browse files
authored
Clean up startWorkflow API (#195)
Co-authored-by: Kaili Zhu <kzhu@indeed.com>
1 parent b2c3988 commit cdeb5e1

File tree

2 files changed

+35
-54
lines changed

2 files changed

+35
-54
lines changed

src/main/java/io/iworkflow/core/Client.java

Lines changed: 12 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -50,58 +50,6 @@ public UnregisteredClient getUnregisteredClient() {
5050
return unregisteredClient;
5151
}
5252

53-
/**
54-
* startWorkflow starts a workflow execution
55-
*
56-
* @param workflow is required
57-
* @param workflowId is required
58-
* @param workflowTimeoutSeconds is required
59-
* @return runId
60-
*/
61-
public String startWorkflow(
62-
final ObjectWorkflow workflow,
63-
final String workflowId,
64-
final int workflowTimeoutSeconds) {
65-
return startWorkflow(workflow, workflowId, workflowTimeoutSeconds, null, null);
66-
}
67-
68-
/**
69-
* startWorkflow starts a workflow execution
70-
*
71-
* @param workflow is required
72-
* @param workflowId is required
73-
* @param workflowTimeoutSeconds is required
74-
* @param input is optional, can be null
75-
* @return runId
76-
*/
77-
public String startWorkflow(
78-
final ObjectWorkflow workflow,
79-
final String workflowId,
80-
final int workflowTimeoutSeconds,
81-
final Object input) {
82-
return startWorkflow(workflow, workflowId, workflowTimeoutSeconds, input, null);
83-
}
84-
85-
/**
86-
* startWorkflow starts a workflow execution
87-
*
88-
* @param workflow is required
89-
* @param workflowId is required
90-
* @param workflowTimeoutSeconds is required
91-
* @param input is optional, can be null
92-
* @param options is optional, can be null
93-
* @return runId
94-
*/
95-
public String startWorkflow(
96-
final ObjectWorkflow workflow,
97-
final String workflowId,
98-
final int workflowTimeoutSeconds,
99-
final Object input,
100-
final WorkflowOptions options) {
101-
final String wfType = Registry.getWorkflowType(workflow);
102-
return doStartWorkflow(wfType, workflowId, workflowTimeoutSeconds, input, options);
103-
}
104-
10553
/**
10654
* startWorkflow starts a workflow execution
10755
*
@@ -151,10 +99,20 @@ public String startWorkflow(
15199
final Object input,
152100
final WorkflowOptions option) {
153101
final String wfType = workflowClass.getSimpleName();
154-
return doStartWorkflow(wfType, workflowId, workflowTimeoutSeconds, input, option);
102+
return startWorkflow(wfType, workflowId, workflowTimeoutSeconds, input, option);
155103
}
156104

157-
private String doStartWorkflow(
105+
/**
106+
* startWorkflow starts a workflow execution
107+
*
108+
* @param wfType is required. It should be the same as the {@link ObjectWorkflow#getWorkflowType()}
109+
* @param workflowId is required
110+
* @param workflowTimeoutSeconds is required
111+
* @param input is optional, can be null
112+
* @param options is optional, can be null
113+
* @return runId
114+
*/
115+
public String startWorkflow(
158116
final String wfType,
159117
final String workflowId,
160118
final int workflowTimeoutSeconds,

src/test/java/io/iworkflow/integ/BasicTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,29 @@ public void testEmptyInputWorkflow() throws InterruptedException {
8484
Assertions.fail("get results from a wrong workflow should fail");
8585
}
8686

87+
@Test
88+
public void testTypeSpecifiedWorkflow() {
89+
final Client client = new Client(WorkflowRegistry.registry, ClientOptions.localDefault);
90+
final String wfId = "type-specified-test-id" + System.currentTimeMillis() / 1000;
91+
final UnregisteredWorkflowOptions startOptions = ImmutableUnregisteredWorkflowOptions.builder()
92+
.workflowIdReusePolicy(IDReusePolicy.ALLOW_IF_NO_RUNNING)
93+
.build();
94+
95+
final EmptyInputWorkflow workflow = new EmptyInputWorkflow();
96+
97+
client.startWorkflow(workflow.getWorkflowType(), wfId, 0, null, null);
98+
Integer out = client.getSimpleWorkflowResultWithWait(Integer.class, wfId);
99+
Assertions.assertNull(out);
100+
101+
// fail when not passing the customized workflowType when starting a workflow with customized workflowType
102+
try {
103+
client.startWorkflow(EmptyInputWorkflow.class, wfId, 0);
104+
} catch (final IllegalArgumentException e) {
105+
return;
106+
}
107+
Assertions.fail("not passing the customized workflowType when starting a workflow with customized workflowType should fail");
108+
}
109+
87110
@Test
88111
public void testModelInputWorkflow() throws InterruptedException {
89112
final Client client = new Client(WorkflowRegistry.registry, ClientOptions.localDefault);

0 commit comments

Comments
 (0)