Search in sources :

Example 1 with WorkflowException

use of io.temporal.client.WorkflowException in project sdk-java by temporalio.

the class SyncWorkflowContext method mapChildWorkflowException.

private RuntimeException mapChildWorkflowException(Exception failure) {
    if (failure == null) {
        return null;
    }
    if (failure instanceof TemporalFailure) {
        ((TemporalFailure) failure).setDataConverter(getDataConverter());
    }
    if (failure instanceof CanceledFailure) {
        return (CanceledFailure) failure;
    }
    if (failure instanceof WorkflowException) {
        return (RuntimeException) failure;
    }
    if (failure instanceof ChildWorkflowFailure) {
        return (ChildWorkflowFailure) failure;
    }
    if (!(failure instanceof ChildWorkflowTaskFailedException)) {
        return new IllegalArgumentException("Unexpected exception type: ", failure);
    }
    ChildWorkflowTaskFailedException taskFailed = (ChildWorkflowTaskFailedException) failure;
    Throwable cause = FailureConverter.failureToException(taskFailed.getFailure(), getDataConverter());
    // To support WorkflowExecutionAlreadyStarted set at handleStartChildWorkflowExecutionFailed
    if (cause == null) {
        cause = failure.getCause();
    }
    return new ChildWorkflowFailure(0, 0, taskFailed.getWorkflowType().getName(), taskFailed.getWorkflowExecution(), null, taskFailed.getRetryState(), cause);
}
Also used : ChildWorkflowFailure(io.temporal.failure.ChildWorkflowFailure) CanceledFailure(io.temporal.failure.CanceledFailure) WorkflowException(io.temporal.client.WorkflowException) ChildWorkflowTaskFailedException(io.temporal.internal.replay.ChildWorkflowTaskFailedException) TemporalFailure(io.temporal.failure.TemporalFailure)

Example 2 with WorkflowException

use of io.temporal.client.WorkflowException in project sdk-java by temporalio.

the class WorkflowFailureNonStandardThrowableTest method nonStandardThrowable.

@Test
public void nonStandardThrowable() {
    TestWorkflow1 workflowStub = testWorkflowRule.getWorkflowClient().newWorkflowStub(TestWorkflow1.class, SDKTestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()));
    try {
        workflowStub.execute(testName.getMethodName());
        fail();
    } catch (WorkflowException e) {
        assertTrue(e.getCause() instanceof ApplicationFailure);
        ApplicationFailure applicationFailure = (ApplicationFailure) e.getCause();
        assertEquals(NonStandardThrowable.class.getName(), applicationFailure.getType());
    }
}
Also used : WorkflowException(io.temporal.client.WorkflowException) ApplicationFailure(io.temporal.failure.ApplicationFailure) TestWorkflow1(io.temporal.workflow.shared.TestWorkflows.TestWorkflow1) Test(org.junit.Test)

Example 3 with WorkflowException

use of io.temporal.client.WorkflowException in project sdk-java by temporalio.

the class ChildWorkflowAsyncRetryTest method testChildWorkflowAsyncRetry.

@Test
public void testChildWorkflowAsyncRetry() {
    WorkflowOptions options = WorkflowOptions.newBuilder().setWorkflowRunTimeout(Duration.ofSeconds(20)).setWorkflowTaskTimeout(Duration.ofSeconds(2)).setTaskQueue(testWorkflowRule.getTaskQueue()).build();
    TestWorkflow1 client = testWorkflowRule.getWorkflowClient().newWorkflowStub(TestWorkflow1.class, options);
    try {
        client.execute(testWorkflowRule.getTaskQueue());
        fail("unreachable");
    } catch (WorkflowException e) {
        assertTrue(String.valueOf(e.getCause()), e.getCause() instanceof ChildWorkflowFailure);
        assertTrue(e.getCause().getCause() instanceof ApplicationFailure);
        assertEquals("test", ((ApplicationFailure) e.getCause().getCause()).getType());
        assertEquals("message='simulated failure', type='test', nonRetryable=false", e.getCause().getCause().getMessage());
    }
    assertEquals(3, angryChildActivity.getInvocationCount());
}
Also used : ChildWorkflowFailure(io.temporal.failure.ChildWorkflowFailure) WorkflowException(io.temporal.client.WorkflowException) ApplicationFailure(io.temporal.failure.ApplicationFailure) ChildWorkflowOptions(io.temporal.workflow.ChildWorkflowOptions) WorkflowOptions(io.temporal.client.WorkflowOptions) TestWorkflow1(io.temporal.workflow.shared.TestWorkflows.TestWorkflow1) Test(org.junit.Test)

Example 4 with WorkflowException

use of io.temporal.client.WorkflowException in project sdk-java by temporalio.

the class WorkflowRetryTest method testWorkflowRetry.

@Test
public void testWorkflowRetry() {
    RetryOptions workflowRetryOptions = RetryOptions.newBuilder().setInitialInterval(Duration.ofSeconds(1)).setMaximumAttempts(3).setBackoffCoefficient(1.0).build();
    TestWorkflow1 workflowStub = testWorkflowRule.getWorkflowClient().newWorkflowStub(TestWorkflow1.class, SDKTestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()).toBuilder().setRetryOptions(workflowRetryOptions).build());
    long start = testWorkflowRule.getTestEnvironment().currentTimeMillis();
    try {
        workflowStub.execute(testName.getMethodName());
        Assert.fail("unreachable");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.toString(), "message='simulated 3', type='test', nonRetryable=false", e.getCause().getMessage());
    } finally {
        long elapsed = testWorkflowRule.getTestEnvironment().currentTimeMillis() - start;
        Assert.assertTrue(String.valueOf(elapsed), // Ensure that retry delays the restart
        elapsed >= 2000);
    }
}
Also used : WorkflowException(io.temporal.client.WorkflowException) RetryOptions(io.temporal.common.RetryOptions) TestWorkflow1(io.temporal.workflow.shared.TestWorkflows.TestWorkflow1) Test(org.junit.Test)

Example 5 with WorkflowException

use of io.temporal.client.WorkflowException in project sdk-java by temporalio.

the class ActivityApplicationFailureNonRetryableTest method testActivityApplicationFailureNonRetryable.

@Test
public void testActivityApplicationFailureNonRetryable() {
    TestWorkflow1 workflowStub = testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflow1.class);
    try {
        workflowStub.execute(testWorkflowRule.getTaskQueue());
        Assert.fail("unreachable");
    } catch (WorkflowException e) {
        Assert.assertTrue(e.getCause() instanceof ActivityFailure);
        Assert.assertTrue(e.getCause().getCause() instanceof ApplicationFailure);
        Assert.assertEquals("java.io.IOException", ((ApplicationFailure) e.getCause().getCause()).getType());
        Assert.assertEquals(RetryState.RETRY_STATE_NON_RETRYABLE_FAILURE, ((ActivityFailure) e.getCause()).getRetryState());
    }
    Assert.assertEquals(activitiesImpl.toString(), 1, activitiesImpl.invocations.size());
}
Also used : WorkflowException(io.temporal.client.WorkflowException) ApplicationFailure(io.temporal.failure.ApplicationFailure) TestWorkflow1(io.temporal.workflow.shared.TestWorkflows.TestWorkflow1) ActivityFailure(io.temporal.failure.ActivityFailure) Test(org.junit.Test)

Aggregations

WorkflowException (io.temporal.client.WorkflowException)40 Test (org.junit.Test)34 TestWorkflow1 (io.temporal.workflow.shared.TestWorkflows.TestWorkflow1)24 ApplicationFailure (io.temporal.failure.ApplicationFailure)19 ActivityFailure (io.temporal.failure.ActivityFailure)16 WorkflowOptions (io.temporal.client.WorkflowOptions)15 WorkflowClient (io.temporal.client.WorkflowClient)12 Worker (io.temporal.worker.Worker)11 TimeoutFailure (io.temporal.failure.TimeoutFailure)10 ChildWorkflowFailure (io.temporal.failure.ChildWorkflowFailure)7 RetryOptions (io.temporal.common.RetryOptions)3 GreetingWorkflow (io.temporal.samples.hello.HelloException.GreetingWorkflow)3 CanceledFailure (io.temporal.failure.CanceledFailure)2 DeterministicRunnerTest (io.temporal.internal.sync.DeterministicRunnerTest)2 WorkflowServiceStubs (io.temporal.serviceclient.WorkflowServiceStubs)2 WorkerFactory (io.temporal.worker.WorkerFactory)2 TestTraceWorkflow (io.temporal.workflow.shared.TestWorkflows.TestTraceWorkflow)2 Test (org.junit.jupiter.api.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 StatusRuntimeException (io.grpc.StatusRuntimeException)1