Search in sources :

Example 6 with WorkflowException

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

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

Example 8 with WorkflowException

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

the class WorkflowStubImpl method mapToWorkflowFailureException.

private <R> R mapToWorkflowFailureException(Exception failure, Class<R> returnType) {
    failure = CheckedExceptionWrapper.unwrap(failure);
    Class<Throwable> detailsClass;
    if (failure instanceof WorkflowExecutionFailedException) {
        WorkflowExecutionFailedException executionFailed = (WorkflowExecutionFailedException) failure;
        try {
            @SuppressWarnings("unchecked") Class<Throwable> dc = (Class<Throwable>) Class.forName(executionFailed.getReason());
            detailsClass = dc;
        } catch (Exception e) {
            RuntimeException ee = new RuntimeException("Couldn't deserialize failure cause " + "as the reason field is expected to contain an exception class name", executionFailed);
            throw new WorkflowFailureException(execution.get(), workflowType, executionFailed.getDecisionTaskCompletedEventId(), ee);
        }
        Throwable cause = dataConverter.fromData(executionFailed.getDetails(), detailsClass);
        throw new WorkflowFailureException(execution.get(), workflowType, executionFailed.getDecisionTaskCompletedEventId(), cause);
    } else if (failure instanceof EntityNotExistsError) {
        throw new WorkflowNotFoundException(execution.get(), workflowType, failure.getMessage());
    } else if (failure instanceof CancellationException) {
        throw (CancellationException) failure;
    } else if (failure instanceof WorkflowException) {
        throw (WorkflowException) failure;
    } else {
        throw new WorkflowServiceException(execution.get(), workflowType, failure);
    }
}
Also used : WorkflowFailureException(com.uber.cadence.client.WorkflowFailureException) WorkflowNotFoundException(com.uber.cadence.client.WorkflowNotFoundException) DuplicateWorkflowException(com.uber.cadence.client.DuplicateWorkflowException) WorkflowException(com.uber.cadence.client.WorkflowException) WorkflowExecutionFailedException(com.uber.cadence.internal.common.WorkflowExecutionFailedException) 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) CancellationException(java.util.concurrent.CancellationException) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) WorkflowServiceException(com.uber.cadence.client.WorkflowServiceException)

Aggregations

WorkflowException (com.uber.cadence.client.WorkflowException)8 WorkflowClient (com.uber.cadence.client.WorkflowClient)7 Test (org.junit.Test)7 Worker (com.uber.cadence.worker.Worker)6 ActivityTimeoutException (com.uber.cadence.workflow.ActivityTimeoutException)3 DuplicateWorkflowException (com.uber.cadence.client.DuplicateWorkflowException)2 WorkflowOptions (com.uber.cadence.client.WorkflowOptions)2 EntityNotExistsError (com.uber.cadence.EntityNotExistsError)1 WorkflowClientInterceptorBase (com.uber.cadence.client.WorkflowClientInterceptorBase)1 WorkflowClientOptions (com.uber.cadence.client.WorkflowClientOptions)1 WorkflowFailureException (com.uber.cadence.client.WorkflowFailureException)1 WorkflowNotFoundException (com.uber.cadence.client.WorkflowNotFoundException)1 WorkflowQueryException (com.uber.cadence.client.WorkflowQueryException)1 WorkflowServiceException (com.uber.cadence.client.WorkflowServiceException)1 WorkflowStub (com.uber.cadence.client.WorkflowStub)1 WorkflowTimedOutException (com.uber.cadence.client.WorkflowTimedOutException)1 WorkflowExecutionFailedException (com.uber.cadence.internal.common.WorkflowExecutionFailedException)1 DeterministicRunnerTest (com.uber.cadence.internal.sync.DeterministicRunnerTest)1 Builder (com.uber.cadence.testing.TestEnvironmentOptions.Builder)1 CancellationException (java.util.concurrent.CancellationException)1