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);
}
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);
}
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);
}
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());
}
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());
}
}
Aggregations