Search in sources :

Example 1 with DuplicateWorkflowException

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());
}
Also used : DuplicateWorkflowException(com.uber.cadence.client.DuplicateWorkflowException) WorkflowOptions(com.uber.cadence.client.WorkflowOptions) DeterministicRunnerTest(com.uber.cadence.internal.sync.DeterministicRunnerTest) Test(org.junit.Test)

Example 2 with DuplicateWorkflowException

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();
}
Also used : DuplicateWorkflowException(com.uber.cadence.client.DuplicateWorkflowException) WorkflowType(com.uber.cadence.WorkflowType) WorkflowExecutionAlreadyStartedError(com.uber.cadence.WorkflowExecutionAlreadyStartedError) StartWorkflowExecutionParameters(com.uber.cadence.internal.common.StartWorkflowExecutionParameters) WorkflowExecution(com.uber.cadence.WorkflowExecution) DuplicateWorkflowException(com.uber.cadence.client.DuplicateWorkflowException) TimeoutException(java.util.concurrent.TimeoutException) WorkflowFailureException(com.uber.cadence.client.WorkflowFailureException) WorkflowNotFoundException(com.uber.cadence.client.WorkflowNotFoundException) WorkflowQueryException(com.uber.cadence.client.WorkflowQueryException) WorkflowException(com.uber.cadence.client.WorkflowException) CancellationException(java.util.concurrent.CancellationException) CompletionException(java.util.concurrent.CompletionException) WorkflowExecutionFailedException(com.uber.cadence.internal.common.WorkflowExecutionFailedException) WorkflowServiceException(com.uber.cadence.client.WorkflowServiceException) WorkflowServiceException(com.uber.cadence.client.WorkflowServiceException)

Aggregations

DuplicateWorkflowException (com.uber.cadence.client.DuplicateWorkflowException)2 WorkflowExecution (com.uber.cadence.WorkflowExecution)1 WorkflowExecutionAlreadyStartedError (com.uber.cadence.WorkflowExecutionAlreadyStartedError)1 WorkflowType (com.uber.cadence.WorkflowType)1 WorkflowException (com.uber.cadence.client.WorkflowException)1 WorkflowFailureException (com.uber.cadence.client.WorkflowFailureException)1 WorkflowNotFoundException (com.uber.cadence.client.WorkflowNotFoundException)1 WorkflowOptions (com.uber.cadence.client.WorkflowOptions)1 WorkflowQueryException (com.uber.cadence.client.WorkflowQueryException)1 WorkflowServiceException (com.uber.cadence.client.WorkflowServiceException)1 StartWorkflowExecutionParameters (com.uber.cadence.internal.common.StartWorkflowExecutionParameters)1 WorkflowExecutionFailedException (com.uber.cadence.internal.common.WorkflowExecutionFailedException)1 DeterministicRunnerTest (com.uber.cadence.internal.sync.DeterministicRunnerTest)1 CancellationException (java.util.concurrent.CancellationException)1 CompletionException (java.util.concurrent.CompletionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Test (org.junit.Test)1