use of com.uber.cadence.client.DuplicateWorkflowException in project cadence-client by uber-java.
the class WorkflowTest method testStart.
@Test
public void testStart() {
startWorkerFor(TestMultiargsWorkflowsImpl.class);
WorkflowOptions workflowOptions = newWorkflowOptionsBuilder(taskList).build();
TestMultiargsWorkflowsFunc stubF = workflowClient.newWorkflowStub(TestMultiargsWorkflowsFunc.class, workflowOptions);
assertResult("func", WorkflowClient.start(stubF::func));
// Check that duplicated start just returns the result.
assertEquals("func", stubF.func());
TestMultiargsWorkflowsFunc1 stubF1 = workflowClient.newWorkflowStub(TestMultiargsWorkflowsFunc1.class);
if (!useExternalService) {
// Use worker that polls on a task list configured through @WorkflowMethod annotation of func1
assertResult("1", WorkflowClient.start(stubF1::func1, "1"));
// Check that duplicated start just returns the result.
assertEquals("1", stubF1.func1("1"));
}
// Check that duplicated start is not allowed for AllowDuplicate IdReusePolicy
TestMultiargsWorkflowsFunc2 stubF2 = workflowClientWithOptions.newWorkflowStub(TestMultiargsWorkflowsFunc2.class, newWorkflowOptionsBuilder(taskList).setWorkflowIdReusePolicy(WorkflowIdReusePolicy.AllowDuplicate).build());
assertResult("12", WorkflowClient.start(stubF2::func2, "1", 2));
try {
stubF2.func2("1", 2);
fail("unreachable");
} catch (DuplicateWorkflowException e) {
// expected
}
TestMultiargsWorkflowsFunc3 stubF3 = workflowClient.newWorkflowStub(TestMultiargsWorkflowsFunc3.class, workflowOptions);
assertResult("123", WorkflowClient.start(stubF3::func3, "1", 2, 3));
TestMultiargsWorkflowsFunc4 stubF4 = workflowClient.newWorkflowStub(TestMultiargsWorkflowsFunc4.class, workflowOptions);
assertResult("1234", WorkflowClient.start(stubF4::func4, "1", 2, 3, 4));
TestMultiargsWorkflowsFunc5 stubF5 = workflowClient.newWorkflowStub(TestMultiargsWorkflowsFunc5.class, workflowOptions);
assertResult("12345", WorkflowClient.start(stubF5::func5, "1", 2, 3, 4, 5));
TestMultiargsWorkflowsFunc6 stubF6 = workflowClient.newWorkflowStub(TestMultiargsWorkflowsFunc6.class, workflowOptions);
assertResult("123456", WorkflowClient.start(stubF6::func6, "1", 2, 3, 4, 5, 6));
TestMultiargsWorkflowsProc stubP = workflowClientWithOptions.newWorkflowStub(TestMultiargsWorkflowsProc.class, workflowOptions);
waitForProc(WorkflowClient.start(stubP::proc));
TestMultiargsWorkflowsProc1 stubP1 = workflowClientWithOptions.newWorkflowStub(TestMultiargsWorkflowsProc1.class, workflowOptions);
waitForProc(WorkflowClient.start(stubP1::proc1, "1"));
TestMultiargsWorkflowsProc2 stubP2 = workflowClientWithOptions.newWorkflowStub(TestMultiargsWorkflowsProc2.class, workflowOptions);
waitForProc(WorkflowClient.start(stubP2::proc2, "1", 2));
TestMultiargsWorkflowsProc3 stubP3 = workflowClientWithOptions.newWorkflowStub(TestMultiargsWorkflowsProc3.class, workflowOptions);
waitForProc(WorkflowClient.start(stubP3::proc3, "1", 2, 3));
TestMultiargsWorkflowsProc4 stubP4 = workflowClientWithOptions.newWorkflowStub(TestMultiargsWorkflowsProc4.class, workflowOptions);
waitForProc(WorkflowClient.start(stubP4::proc4, "1", 2, 3, 4));
TestMultiargsWorkflowsProc5 stubP5 = workflowClientWithOptions.newWorkflowStub(TestMultiargsWorkflowsProc5.class, workflowOptions);
waitForProc(WorkflowClient.start(stubP5::proc5, "1", 2, 3, 4, 5));
TestMultiargsWorkflowsProc6 stubP6 = workflowClientWithOptions.newWorkflowStub(TestMultiargsWorkflowsProc6.class, workflowOptions);
waitForProc(WorkflowClient.start(stubP6::proc6, "1", 2, 3, 4, 5, 6));
assertEquals("proc", stubP.query());
assertEquals("1", stubP1.query());
assertEquals("12", stubP2.query());
assertEquals("123", stubP3.query());
assertEquals("1234", stubP4.query());
assertEquals("12345", stubP5.query());
assertEquals("123456", stubP6.query());
}
use of com.uber.cadence.client.DuplicateWorkflowException in project cadence-client by uber-java.
the class WorkflowStubImpl method startWithOptions.
private WorkflowExecution startWithOptions(WorkflowOptions o, Object... args) {
if (execution.get() != null) {
throw new DuplicateWorkflowException(execution.get(), workflowType.get(), "Cannot reuse a stub instance to start more than one workflow execution. The stub " + "points to already started execution.");
}
StartWorkflowExecutionParameters p = new StartWorkflowExecutionParameters();
p.setTaskStartToCloseTimeoutSeconds(o.getTaskStartToCloseTimeout().getSeconds());
if (o.getWorkflowId() == null) {
p.setWorkflowId(UUID.randomUUID().toString());
} else {
p.setWorkflowId(o.getWorkflowId());
}
p.setExecutionStartToCloseTimeoutSeconds(o.getExecutionStartToCloseTimeout().getSeconds());
p.setInput(dataConverter.toData(args));
p.setWorkflowType(new WorkflowType().setName(workflowType.get()));
p.setTaskList(o.getTaskList());
p.setChildPolicy(o.getChildPolicy());
try {
execution.set(genericClient.startWorkflow(p));
} catch (WorkflowExecutionAlreadyStartedError e) {
execution.set(new WorkflowExecution().setWorkflowId(p.getWorkflowId()).setRunId(e.getRunId()));
WorkflowExecution execution = new WorkflowExecution().setWorkflowId(p.getWorkflowId()).setRunId(e.getRunId());
throw new DuplicateWorkflowException(execution, workflowType.get(), e.getMessage());
} catch (Exception e) {
throw new WorkflowServiceException(execution.get(), workflowType, e);
}
return execution.get();
}
Aggregations