Search in sources :

Example 1 with WorkflowClientOptions

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

the class WorkflowTest method setUp.

@Before
public void setUp() {
    if (testName.getMethodName().equals("testExecute[TestService]") || testName.getMethodName().equals("testStart[TestService]")) {
        taskList = ANNOTATION_TASK_LIST;
    } else {
        taskList = "WorkflowTest-" + testName.getMethodName();
    }
    if (useExternalService) {
        worker = new Worker(domain, taskList);
        workflowClient = WorkflowClient.newInstance(domain);
        WorkflowClientOptions clientOptions = new WorkflowClientOptions.Builder().setDataConverter(JsonDataConverter.getInstance()).build();
        workflowClientWithOptions = WorkflowClient.newInstance(domain, clientOptions);
        scheduledExecutor = new ScheduledThreadPoolExecutor(1);
    } else {
        TestEnvironmentOptions testOptions = new Builder().setDomain(domain).build();
        testEnvironment = TestWorkflowEnvironment.newInstance(testOptions);
        worker = testEnvironment.newWorker(taskList);
        workflowClient = testEnvironment.newWorkflowClient();
        workflowClientWithOptions = testEnvironment.newWorkflowClient();
    }
    ActivityCompletionClient completionClient = workflowClient.newActivityCompletionClient();
    activitiesImpl = new TestActivitiesImpl(completionClient);
    worker.registerActivitiesImplementations(activitiesImpl);
    newWorkflowOptionsBuilder(taskList);
    newActivityOptions1(taskList);
    activitiesImpl.invocations.clear();
    activitiesImpl.procResult.clear();
}
Also used : TestEnvironmentOptions(com.uber.cadence.testing.TestEnvironmentOptions) ActivityCompletionClient(com.uber.cadence.client.ActivityCompletionClient) WorkflowClientOptions(com.uber.cadence.client.WorkflowClientOptions) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Builder(com.uber.cadence.testing.TestEnvironmentOptions.Builder) Worker(com.uber.cadence.worker.Worker) Before(org.junit.Before)

Example 2 with WorkflowClientOptions

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

WorkflowClientOptions (com.uber.cadence.client.WorkflowClientOptions)2 Builder (com.uber.cadence.testing.TestEnvironmentOptions.Builder)2 ActivityCompletionClient (com.uber.cadence.client.ActivityCompletionClient)1 DuplicateWorkflowException (com.uber.cadence.client.DuplicateWorkflowException)1 WorkflowClient (com.uber.cadence.client.WorkflowClient)1 WorkflowClientInterceptorBase (com.uber.cadence.client.WorkflowClientInterceptorBase)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 TestEnvironmentOptions (com.uber.cadence.testing.TestEnvironmentOptions)1 Worker (com.uber.cadence.worker.Worker)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Before (org.junit.Before)1 Test (org.junit.Test)1