Search in sources :

Example 6 with WorkflowOptions

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

the class WorkflowTest method testExecute.

@Test
public void testExecute() throws ExecutionException, InterruptedException {
    startWorkerFor(TestMultiargsWorkflowsImpl.class);
    WorkflowOptions workflowOptions = newWorkflowOptionsBuilder(taskList).setTaskList(// To override func2 annotation property
    ANNOTATION_TASK_LIST).build();
    TestMultiargsWorkflowsFunc stubF = workflowClient.newWorkflowStub(TestMultiargsWorkflowsFunc.class, workflowOptions);
    assertEquals("func", WorkflowClient.execute(stubF::func).get());
    TestMultiargsWorkflowsFunc1 stubF1 = workflowClient.newWorkflowStub(TestMultiargsWorkflowsFunc1.class, workflowOptions);
    assertEquals("1", WorkflowClient.execute(stubF1::func1, "1").get());
    // Check that duplicated start just returns the result.
    assertEquals("1", stubF1.func1("1"));
    TestMultiargsWorkflowsFunc2 stubF2 = workflowClient.newWorkflowStub(TestMultiargsWorkflowsFunc2.class, workflowOptions);
    assertEquals("12", WorkflowClient.execute(stubF2::func2, "1", 2).get());
    TestMultiargsWorkflowsFunc3 stubF3 = workflowClient.newWorkflowStub(TestMultiargsWorkflowsFunc3.class, workflowOptions);
    assertEquals("123", WorkflowClient.execute(stubF3::func3, "1", 2, 3).get());
    TestMultiargsWorkflowsFunc4 stubF4 = workflowClient.newWorkflowStub(TestMultiargsWorkflowsFunc4.class, workflowOptions);
    assertEquals("1234", WorkflowClient.execute(stubF4::func4, "1", 2, 3, 4).get());
    TestMultiargsWorkflowsFunc5 stubF5 = workflowClient.newWorkflowStub(TestMultiargsWorkflowsFunc5.class, workflowOptions);
    assertEquals("12345", WorkflowClient.execute(stubF5::func5, "1", 2, 3, 4, 5).get());
    TestMultiargsWorkflowsFunc6 stubF6 = workflowClient.newWorkflowStub(TestMultiargsWorkflowsFunc6.class, workflowOptions);
    assertEquals("123456", WorkflowClient.execute(stubF6::func6, "1", 2, 3, 4, 5, 6).get());
    TestMultiargsWorkflowsProc stubP = workflowClientWithOptions.newWorkflowStub(TestMultiargsWorkflowsProc.class, workflowOptions);
    WorkflowClient.execute(stubP::proc).get();
    TestMultiargsWorkflowsProc1 stubP1 = workflowClientWithOptions.newWorkflowStub(TestMultiargsWorkflowsProc1.class, workflowOptions);
    WorkflowClient.execute(stubP1::proc1, "1").get();
    TestMultiargsWorkflowsProc2 stubP2 = workflowClientWithOptions.newWorkflowStub(TestMultiargsWorkflowsProc2.class, workflowOptions);
    WorkflowClient.execute(stubP2::proc2, "1", 2).get();
    TestMultiargsWorkflowsProc3 stubP3 = workflowClientWithOptions.newWorkflowStub(TestMultiargsWorkflowsProc3.class, workflowOptions);
    WorkflowClient.execute(stubP3::proc3, "1", 2, 3).get();
    TestMultiargsWorkflowsProc4 stubP4 = workflowClientWithOptions.newWorkflowStub(TestMultiargsWorkflowsProc4.class, workflowOptions);
    WorkflowClient.execute(stubP4::proc4, "1", 2, 3, 4).get();
    TestMultiargsWorkflowsProc5 stubP5 = workflowClientWithOptions.newWorkflowStub(TestMultiargsWorkflowsProc5.class, workflowOptions);
    WorkflowClient.execute(stubP5::proc5, "1", 2, 3, 4, 5).get();
    TestMultiargsWorkflowsProc6 stubP6 = workflowClientWithOptions.newWorkflowStub(TestMultiargsWorkflowsProc6.class, workflowOptions);
    WorkflowClient.execute(stubP6::proc6, "1", 2, 3, 4, 5, 6).get();
    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 : WorkflowOptions(com.uber.cadence.client.WorkflowOptions) DeterministicRunnerTest(com.uber.cadence.internal.sync.DeterministicRunnerTest) Test(org.junit.Test)

Example 7 with WorkflowOptions

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

the class WorkflowTest method testChildWorkflowRetry.

@Test
public void testChildWorkflowRetry() {
    AngryChildActivityImpl angryChildActivity = new AngryChildActivityImpl();
    worker.registerActivitiesImplementations(angryChildActivity);
    startWorkerFor(TestChildWorkflowRetryWorkflow.class, AngryChild.class);
    WorkflowOptions.Builder options = new WorkflowOptions.Builder();
    options.setExecutionStartToCloseTimeout(Duration.ofSeconds(20));
    options.setTaskStartToCloseTimeout(Duration.ofSeconds(2));
    options.setTaskList(taskList);
    AtomicReference<String> capturedWorkflowType = new AtomicReference<>();
    WorkflowClientOptions clientOptions = new WorkflowClientOptions.Builder().setInterceptors(new WorkflowClientInterceptorBase() {

        @Override
        public WorkflowStub newUntypedWorkflowStub(String workflowType, WorkflowOptions options, WorkflowStub next) {
            capturedWorkflowType.set(workflowType);
            return next;
        }
    }).build();
    WorkflowClient wc;
    if (useExternalService) {
        wc = WorkflowClient.newInstance(domain, clientOptions);
    } else {
        wc = testEnvironment.newWorkflowClient(clientOptions);
    }
    TestWorkflow1 client = wc.newWorkflowStub(TestWorkflow1.class, options.build());
    try {
        client.execute(taskList);
        fail("unreachable");
    } catch (WorkflowException e) {
        assertTrue(e.getCause() instanceof ChildWorkflowFailureException);
        assertTrue(e.getCause().getCause() instanceof UnsupportedOperationException);
        assertEquals("simulated failure", e.getCause().getCause().getMessage());
    }
    assertEquals("TestWorkflow1::execute", capturedWorkflowType.get());
    assertEquals(3, angryChildActivity.getInvocationCount());
}
Also used : WorkflowStub(com.uber.cadence.client.WorkflowStub) Builder(com.uber.cadence.testing.TestEnvironmentOptions.Builder) DuplicateWorkflowException(com.uber.cadence.client.DuplicateWorkflowException) WorkflowException(com.uber.cadence.client.WorkflowException) WorkflowClient(com.uber.cadence.client.WorkflowClient) AtomicReference(java.util.concurrent.atomic.AtomicReference) WorkflowClientOptions(com.uber.cadence.client.WorkflowClientOptions) WorkflowOptions(com.uber.cadence.client.WorkflowOptions) WorkflowClientInterceptorBase(com.uber.cadence.client.WorkflowClientInterceptorBase) 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