Search in sources :

Example 1 with WorkflowClientInterceptorBase

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

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