Search in sources :

Example 1 with ChildWorkflowFailure

use of io.temporal.failure.ChildWorkflowFailure in project sdk-java by temporalio.

the class ChildWorkflowStateMachine method notifyTerminated.

private void notifyTerminated() {
    ChildWorkflowExecutionTerminatedEventAttributes attributes = currentEvent.getChildWorkflowExecutionTerminatedEventAttributes();
    RuntimeException failure = new ChildWorkflowFailure(attributes.getInitiatedEventId(), attributes.getStartedEventId(), attributes.getWorkflowType().getName(), attributes.getWorkflowExecution(), attributes.getNamespace(), RetryState.RETRY_STATE_NON_RETRYABLE_FAILURE, new TerminatedFailure(null, null));
    completionCallback.apply(Optional.empty(), failure);
}
Also used : ChildWorkflowFailure(io.temporal.failure.ChildWorkflowFailure) TerminatedFailure(io.temporal.failure.TerminatedFailure) ChildWorkflowExecutionTerminatedEventAttributes(io.temporal.api.history.v1.ChildWorkflowExecutionTerminatedEventAttributes)

Example 2 with ChildWorkflowFailure

use of io.temporal.failure.ChildWorkflowFailure in project sdk-java by temporalio.

the class ChildWorkflowStateMachine method cancelStartChildCommand.

private void cancelStartChildCommand() {
    cancelCommand();
    RuntimeException failure = new ChildWorkflowFailure(0, 0, workflowType, WorkflowExecution.newBuilder().setWorkflowId(workflowId).build(), namespace, RetryState.RETRY_STATE_NON_RETRYABLE_FAILURE, new CanceledFailure("Child immediately canceled", null, null));
    completionCallback.apply(Optional.empty(), failure);
}
Also used : ChildWorkflowFailure(io.temporal.failure.ChildWorkflowFailure) CanceledFailure(io.temporal.failure.CanceledFailure)

Example 3 with ChildWorkflowFailure

use of io.temporal.failure.ChildWorkflowFailure 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 4 with ChildWorkflowFailure

use of io.temporal.failure.ChildWorkflowFailure 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 5 with ChildWorkflowFailure

use of io.temporal.failure.ChildWorkflowFailure in project sdk-java by temporalio.

the class ExceptionPropagationTest method testExceptionPropagation.

/**
 * Test that an NPE thrown in an activity executed from a child workflow results in the following
 * chain of exceptions when an exception is received in an external client that executed workflow
 * through a WorkflowClient:
 *
 * <pre>
 * {@link WorkflowFailedException}
 *     ->{@link ChildWorkflowFailure}
 *         ->{@link ActivityFailure}
 *             ->OriginalActivityException
 * </pre>
 *
 * <p>This test also tests that Checked exception wrapping and unwrapping works producing a nice
 * exception chain without the wrappers.
 */
@Test
public void testExceptionPropagation() {
    TestWorkflowStringArg client = testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflowStringArg.class);
    try {
        client.execute(testWorkflowRule.getTaskQueue());
        Assert.fail("Unreachable");
    } catch (WorkflowFailedException e) {
        // Rethrow the assertion failure
        Throwable c1 = e.getCause();
        Throwable c2 = c1.getCause();
        Throwable c3 = c2.getCause();
        Throwable c4 = c3.getCause();
        Throwable c5 = c4.getCause();
        Throwable c6 = c5.getCause();
        if (c2 instanceof AssertionError) {
            throw (AssertionError) c2;
        }
        assertNoEmptyStacks(e);
        // Uncomment to see the actual trace.
        // e.printStackTrace();
        Assert.assertTrue(e.getMessage(), e.getMessage().contains("TestWorkflowStringArg"));
        Assert.assertTrue(e.getStackTrace().length > 0);
        Assert.assertTrue(c1 instanceof ApplicationFailure);
        Assert.assertEquals(FileNotFoundException.class.getName(), ((ApplicationFailure) c1).getType());
        Assert.assertTrue(c2 instanceof ChildWorkflowFailure);
        Assert.assertTrue(c3 instanceof ApplicationFailure);
        Assert.assertEquals(NumberFormatException.class.getName(), ((ApplicationFailure) c3).getType());
        Assert.assertEquals(Throwable.class.getName(), ((ApplicationFailure) c4).getType());
        Assert.assertTrue(c5 instanceof ActivityFailure);
        Assert.assertTrue(c6 instanceof ApplicationFailure);
        Assert.assertEquals(IOException.class.getName(), ((ApplicationFailure) c6).getType());
        Assert.assertEquals("message='simulated IO problem', type='java.io.IOException', nonRetryable=false", c6.getMessage());
    }
}
Also used : WorkflowFailedException(io.temporal.client.WorkflowFailedException) ChildWorkflowFailure(io.temporal.failure.ChildWorkflowFailure) ApplicationFailure(io.temporal.failure.ApplicationFailure) TestWorkflowStringArg(io.temporal.workflow.shared.TestWorkflows.TestWorkflowStringArg) ActivityFailure(io.temporal.failure.ActivityFailure) Test(org.junit.Test)

Aggregations

ChildWorkflowFailure (io.temporal.failure.ChildWorkflowFailure)13 Test (org.junit.Test)8 WorkflowException (io.temporal.client.WorkflowException)7 WorkflowOptions (io.temporal.client.WorkflowOptions)7 TimeoutFailure (io.temporal.failure.TimeoutFailure)5 ApplicationFailure (io.temporal.failure.ApplicationFailure)4 ActivityFailure (io.temporal.failure.ActivityFailure)3 CanceledFailure (io.temporal.failure.CanceledFailure)3 GreetingWorkflow (io.temporal.samples.hello.HelloException.GreetingWorkflow)3 WorkflowClient (io.temporal.client.WorkflowClient)2 WorkflowFailedException (io.temporal.client.WorkflowFailedException)2 Worker (io.temporal.worker.Worker)2 ChildWorkflowOptions (io.temporal.workflow.ChildWorkflowOptions)2 TestWorkflow1 (io.temporal.workflow.shared.TestWorkflows.TestWorkflow1)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 WorkflowExecution (io.temporal.api.common.v1.WorkflowExecution)1 ChildWorkflowExecutionCanceledEventAttributes (io.temporal.api.history.v1.ChildWorkflowExecutionCanceledEventAttributes)1 ChildWorkflowExecutionTerminatedEventAttributes (io.temporal.api.history.v1.ChildWorkflowExecutionTerminatedEventAttributes)1 ChildWorkflowExecutionTimedOutEventAttributes (io.temporal.api.history.v1.ChildWorkflowExecutionTimedOutEventAttributes)1 WorkflowExecutionInfo (io.temporal.api.workflow.v1.WorkflowExecutionInfo)1