Search in sources :

Example 1 with WorkflowTimedOutException

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

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

the class WorkflowExecutionUtils method getResultFromCloseEvent.

private static byte[] getResultFromCloseEvent(WorkflowExecution workflowExecution, Optional<String> workflowType, HistoryEvent closeEvent) {
    if (closeEvent == null) {
        throw new IllegalStateException("Workflow is still running");
    }
    switch(closeEvent.getEventType()) {
        case WorkflowExecutionCompleted:
            return closeEvent.getWorkflowExecutionCompletedEventAttributes().getResult();
        case WorkflowExecutionCanceled:
            byte[] details = closeEvent.getWorkflowExecutionCanceledEventAttributes().getDetails();
            String message = details != null ? new String(details, StandardCharsets.UTF_8) : null;
            throw new CancellationException(message);
        case WorkflowExecutionFailed:
            WorkflowExecutionFailedEventAttributes failed = closeEvent.getWorkflowExecutionFailedEventAttributes();
            throw new WorkflowExecutionFailedException(failed.getReason(), failed.getDetails(), failed.getDecisionTaskCompletedEventId());
        case WorkflowExecutionTerminated:
            WorkflowExecutionTerminatedEventAttributes terminated = closeEvent.getWorkflowExecutionTerminatedEventAttributes();
            throw new WorkflowTerminatedException(workflowExecution, workflowType, terminated.getReason(), terminated.getIdentity(), terminated.getDetails());
        case WorkflowExecutionTimedOut:
            WorkflowExecutionTimedOutEventAttributes timedOut = closeEvent.getWorkflowExecutionTimedOutEventAttributes();
            throw new WorkflowTimedOutException(workflowExecution, workflowType, timedOut.getTimeoutType());
        default:
            throw new RuntimeException("Workflow end state is not completed: " + prettyPrintHistoryEvent(closeEvent));
    }
}
Also used : WorkflowExecutionFailedEventAttributes(com.uber.cadence.WorkflowExecutionFailedEventAttributes) WorkflowTimedOutException(com.uber.cadence.client.WorkflowTimedOutException) WorkflowTerminatedException(com.uber.cadence.client.WorkflowTerminatedException) CancellationException(java.util.concurrent.CancellationException) WorkflowExecutionTerminatedEventAttributes(com.uber.cadence.WorkflowExecutionTerminatedEventAttributes) WorkflowExecutionTimedOutEventAttributes(com.uber.cadence.WorkflowExecutionTimedOutEventAttributes)

Aggregations

WorkflowTimedOutException (com.uber.cadence.client.WorkflowTimedOutException)2 WorkflowExecutionFailedEventAttributes (com.uber.cadence.WorkflowExecutionFailedEventAttributes)1 WorkflowExecutionTerminatedEventAttributes (com.uber.cadence.WorkflowExecutionTerminatedEventAttributes)1 WorkflowExecutionTimedOutEventAttributes (com.uber.cadence.WorkflowExecutionTimedOutEventAttributes)1 WorkflowClient (com.uber.cadence.client.WorkflowClient)1 WorkflowException (com.uber.cadence.client.WorkflowException)1 WorkflowOptions (com.uber.cadence.client.WorkflowOptions)1 WorkflowTerminatedException (com.uber.cadence.client.WorkflowTerminatedException)1 Worker (com.uber.cadence.worker.Worker)1 CancellationException (java.util.concurrent.CancellationException)1 Test (org.junit.Test)1