Search in sources :

Example 1 with ApplicationFailure

use of io.temporal.failure.ApplicationFailure 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 2 with ApplicationFailure

use of io.temporal.failure.ApplicationFailure 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 3 with ApplicationFailure

use of io.temporal.failure.ApplicationFailure 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)

Example 4 with ApplicationFailure

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

the class LocalActivityRetryTest method testLocalActivityRetry.

@Test
public void testLocalActivityRetry() {
    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(IOException.class.getName(), ((ApplicationFailure) e.getCause().getCause()).getType());
    }
    Assert.assertEquals(activitiesImpl.toString(), 5, activitiesImpl.invocations.size());
    Assert.assertEquals("last attempt", 5, activitiesImpl.getLastAttempt());
}
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)

Example 5 with ApplicationFailure

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

the class LocalActivityThrowingErrorTest method localActivityNonRetryableThrowsError.

@Test
public void localActivityNonRetryableThrowsError() {
    String name = testName.getMethodName();
    WorkflowClient client = testWorkflowRule.getWorkflowClient();
    TestWorkflow4 workflow = client.newWorkflowStub(TestWorkflow4.class, options);
    try {
        workflow.execute(name, false);
    } catch (WorkflowFailedException e) {
        assertTrue(e.getCause() instanceof ActivityFailure);
        assertTrue(e.getCause().getCause() instanceof ApplicationFailure);
        assertEquals(FAILURE_TYPE, ((ApplicationFailure) e.getCause().getCause()).getType());
        assertEquals(1, ActivityThrowingErrorTest.ApplicationFailureActivity.invocations.get(name).get());
    }
}
Also used : WorkflowFailedException(io.temporal.client.WorkflowFailedException) ApplicationFailure(io.temporal.failure.ApplicationFailure) WorkflowClient(io.temporal.client.WorkflowClient) TestWorkflow4(io.temporal.workflow.shared.TestWorkflows.TestWorkflow4) ActivityFailure(io.temporal.failure.ActivityFailure) Test(org.junit.Test)

Aggregations

ApplicationFailure (io.temporal.failure.ApplicationFailure)27 Test (org.junit.Test)27 WorkflowException (io.temporal.client.WorkflowException)19 TestWorkflow1 (io.temporal.workflow.shared.TestWorkflows.TestWorkflow1)18 ActivityFailure (io.temporal.failure.ActivityFailure)15 WorkflowFailedException (io.temporal.client.WorkflowFailedException)8 WorkflowOptions (io.temporal.client.WorkflowOptions)5 ChildWorkflowFailure (io.temporal.failure.ChildWorkflowFailure)4 TestWorkflow4 (io.temporal.workflow.shared.TestWorkflows.TestWorkflow4)4 WorkflowExecution (io.temporal.api.common.v1.WorkflowExecution)2 WorkflowClient (io.temporal.client.WorkflowClient)2 RetryOptions (io.temporal.common.RetryOptions)2 DeterministicRunnerTest (io.temporal.internal.sync.DeterministicRunnerTest)2 ChildWorkflowOptions (io.temporal.workflow.ChildWorkflowOptions)2 TestTraceWorkflow (io.temporal.workflow.shared.TestWorkflows.TestTraceWorkflow)2 TestWorkflowStringArg (io.temporal.workflow.shared.TestWorkflows.TestWorkflowStringArg)2 GreetingWorkflow (io.temporal.samples.hello.HelloException.GreetingWorkflow)1 TracingWorkerInterceptor (io.temporal.testing.internal.TracingWorkerInterceptor)1 NonDeterministicException (io.temporal.worker.NonDeterministicException)1