Search in sources :

Example 1 with WorkflowOptions

use of com.uber.cadence.client.WorkflowOptions 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 WorkflowOptions

use of com.uber.cadence.client.WorkflowOptions in project cadence-client by uber-java.

the class WorkflowTest method testDecisionFailureBackoff.

@Test
public void testDecisionFailureBackoff() {
    testDecisionFailureBackoffReplayCount = 0;
    startWorkerFor(TestDecisionFailureBackoff.class);
    WorkflowOptions o = new WorkflowOptions.Builder().setExecutionStartToCloseTimeout(Duration.ofSeconds(10)).setTaskStartToCloseTimeout(Duration.ofSeconds(1)).setTaskList(taskList).build();
    TestWorkflow1 workflowStub = workflowClient.newWorkflowStub(TestWorkflow1.class, o);
    long start = System.currentTimeMillis();
    String result = workflowStub.execute(taskList);
    long elapsed = System.currentTimeMillis() - start;
    assertTrue("spinned on fail decision", elapsed > 1000);
    assertEquals("result1", result);
}
Also used : Builder(com.uber.cadence.testing.TestEnvironmentOptions.Builder) WorkflowOptions(com.uber.cadence.client.WorkflowOptions) DeterministicRunnerTest(com.uber.cadence.internal.sync.DeterministicRunnerTest) Test(org.junit.Test)

Example 3 with WorkflowOptions

use of com.uber.cadence.client.WorkflowOptions in project cadence-client by uber-java.

the class WorkflowTestingTest method testChild.

@Test
public void testChild() {
    Worker worker = testEnvironment.newWorker(TASK_LIST);
    worker.registerWorkflowImplementationTypes(ChildWorklfowImpl.class, ParentWorkflowImpl.class);
    worker.start();
    WorkflowClient client = testEnvironment.newWorkflowClient();
    WorkflowOptions options = new WorkflowOptions.Builder().setWorkflowId("parent1").build();
    ParentWorkflow workflow = client.newWorkflowStub(ParentWorkflow.class, options);
    String result = workflow.workflow("input1");
    assertEquals("child input1", result);
}
Also used : Worker(com.uber.cadence.worker.Worker) WorkflowClient(com.uber.cadence.client.WorkflowClient) WorkflowOptions(com.uber.cadence.client.WorkflowOptions) Test(org.junit.Test)

Example 4 with WorkflowOptions

use of com.uber.cadence.client.WorkflowOptions in project cadence-client by uber-java.

the class WorkflowTestingTest method testWorkflowTimeout.

@Test
public void testWorkflowTimeout() {
    Worker worker = testEnvironment.newWorker(TASK_LIST);
    worker.registerWorkflowImplementationTypes(TimeoutWorkflow.class);
    worker.start();
    WorkflowClient client = testEnvironment.newWorkflowClient();
    WorkflowOptions options = new WorkflowOptions.Builder().setExecutionStartToCloseTimeout(Duration.ofSeconds(1)).build();
    TestWorkflow workflow = client.newWorkflowStub(TestWorkflow.class, options);
    try {
        workflow.workflow1("bar");
        fail("unreacheable");
    } catch (WorkflowException e) {
        assertTrue(e instanceof WorkflowTimedOutException);
        assertEquals(TimeoutType.START_TO_CLOSE, ((WorkflowTimedOutException) e).getTimeoutType());
    }
}
Also used : WorkflowTimedOutException(com.uber.cadence.client.WorkflowTimedOutException) WorkflowException(com.uber.cadence.client.WorkflowException) Worker(com.uber.cadence.worker.Worker) WorkflowClient(com.uber.cadence.client.WorkflowClient) WorkflowOptions(com.uber.cadence.client.WorkflowOptions) Test(org.junit.Test)

Example 5 with WorkflowOptions

use of com.uber.cadence.client.WorkflowOptions in project cadence-client by uber-java.

the class WorkflowTest method testTimer.

@Test
public void testTimer() {
    startWorkerFor(TestTimerWorkflowImpl.class);
    WorkflowOptions options;
    if (useExternalService) {
        options = newWorkflowOptionsBuilder(taskList).build();
    } else {
        options = newWorkflowOptionsBuilder(taskList).setExecutionStartToCloseTimeout(Duration.ofDays(1)).build();
    }
    TestWorkflow2 client = workflowClient.newWorkflowStub(TestWorkflow2.class, options);
    String result = client.execute(useExternalService);
    assertEquals("testTimer", result);
}
Also used : WorkflowOptions(com.uber.cadence.client.WorkflowOptions) DeterministicRunnerTest(com.uber.cadence.internal.sync.DeterministicRunnerTest) Test(org.junit.Test)

Aggregations

WorkflowOptions (com.uber.cadence.client.WorkflowOptions)7 Test (org.junit.Test)7 DeterministicRunnerTest (com.uber.cadence.internal.sync.DeterministicRunnerTest)5 WorkflowClient (com.uber.cadence.client.WorkflowClient)3 DuplicateWorkflowException (com.uber.cadence.client.DuplicateWorkflowException)2 WorkflowException (com.uber.cadence.client.WorkflowException)2 Builder (com.uber.cadence.testing.TestEnvironmentOptions.Builder)2 Worker (com.uber.cadence.worker.Worker)2 WorkflowClientInterceptorBase (com.uber.cadence.client.WorkflowClientInterceptorBase)1 WorkflowClientOptions (com.uber.cadence.client.WorkflowClientOptions)1 WorkflowStub (com.uber.cadence.client.WorkflowStub)1 WorkflowTimedOutException (com.uber.cadence.client.WorkflowTimedOutException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1