From cdeb5e1773b753d7ed7fb504383d21bb6f1dff83 Mon Sep 17 00:00:00 2001 From: Kaili Zhu Date: Thu, 27 Jul 2023 12:35:14 +0900 Subject: [PATCH] Clean up startWorkflow API (#195) Co-authored-by: Kaili Zhu --- src/main/java/io/iworkflow/core/Client.java | 66 ++++--------------- .../java/io/iworkflow/integ/BasicTest.java | 23 +++++++ 2 files changed, 35 insertions(+), 54 deletions(-) diff --git a/src/main/java/io/iworkflow/core/Client.java b/src/main/java/io/iworkflow/core/Client.java index 68a49839..4b53a848 100644 --- a/src/main/java/io/iworkflow/core/Client.java +++ b/src/main/java/io/iworkflow/core/Client.java @@ -50,58 +50,6 @@ public UnregisteredClient getUnregisteredClient() { return unregisteredClient; } - /** - * startWorkflow starts a workflow execution - * - * @param workflow is required - * @param workflowId is required - * @param workflowTimeoutSeconds is required - * @return runId - */ - public String startWorkflow( - final ObjectWorkflow workflow, - final String workflowId, - final int workflowTimeoutSeconds) { - return startWorkflow(workflow, workflowId, workflowTimeoutSeconds, null, null); - } - - /** - * startWorkflow starts a workflow execution - * - * @param workflow is required - * @param workflowId is required - * @param workflowTimeoutSeconds is required - * @param input is optional, can be null - * @return runId - */ - public String startWorkflow( - final ObjectWorkflow workflow, - final String workflowId, - final int workflowTimeoutSeconds, - final Object input) { - return startWorkflow(workflow, workflowId, workflowTimeoutSeconds, input, null); - } - - /** - * startWorkflow starts a workflow execution - * - * @param workflow is required - * @param workflowId is required - * @param workflowTimeoutSeconds is required - * @param input is optional, can be null - * @param options is optional, can be null - * @return runId - */ - public String startWorkflow( - final ObjectWorkflow workflow, - final String workflowId, - final int workflowTimeoutSeconds, - final Object input, - final WorkflowOptions options) { - final String wfType = Registry.getWorkflowType(workflow); - return doStartWorkflow(wfType, workflowId, workflowTimeoutSeconds, input, options); - } - /** * startWorkflow starts a workflow execution * @@ -151,10 +99,20 @@ public String startWorkflow( final Object input, final WorkflowOptions option) { final String wfType = workflowClass.getSimpleName(); - return doStartWorkflow(wfType, workflowId, workflowTimeoutSeconds, input, option); + return startWorkflow(wfType, workflowId, workflowTimeoutSeconds, input, option); } - private String doStartWorkflow( + /** + * startWorkflow starts a workflow execution + * + * @param wfType is required. It should be the same as the {@link ObjectWorkflow#getWorkflowType()} + * @param workflowId is required + * @param workflowTimeoutSeconds is required + * @param input is optional, can be null + * @param options is optional, can be null + * @return runId + */ + public String startWorkflow( final String wfType, final String workflowId, final int workflowTimeoutSeconds, diff --git a/src/test/java/io/iworkflow/integ/BasicTest.java b/src/test/java/io/iworkflow/integ/BasicTest.java index 4d23d411..4cec5534 100644 --- a/src/test/java/io/iworkflow/integ/BasicTest.java +++ b/src/test/java/io/iworkflow/integ/BasicTest.java @@ -84,6 +84,29 @@ public void testEmptyInputWorkflow() throws InterruptedException { Assertions.fail("get results from a wrong workflow should fail"); } + @Test + public void testTypeSpecifiedWorkflow() { + final Client client = new Client(WorkflowRegistry.registry, ClientOptions.localDefault); + final String wfId = "type-specified-test-id" + System.currentTimeMillis() / 1000; + final UnregisteredWorkflowOptions startOptions = ImmutableUnregisteredWorkflowOptions.builder() + .workflowIdReusePolicy(IDReusePolicy.ALLOW_IF_NO_RUNNING) + .build(); + + final EmptyInputWorkflow workflow = new EmptyInputWorkflow(); + + client.startWorkflow(workflow.getWorkflowType(), wfId, 0, null, null); + Integer out = client.getSimpleWorkflowResultWithWait(Integer.class, wfId); + Assertions.assertNull(out); + + // fail when not passing the customized workflowType when starting a workflow with customized workflowType + try { + client.startWorkflow(EmptyInputWorkflow.class, wfId, 0); + } catch (final IllegalArgumentException e) { + return; + } + Assertions.fail("not passing the customized workflowType when starting a workflow with customized workflowType should fail"); + } + @Test public void testModelInputWorkflow() throws InterruptedException { final Client client = new Client(WorkflowRegistry.registry, ClientOptions.localDefault);