Search in sources :

Example 1 with ActivityFailure

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

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

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

Example 4 with ActivityFailure

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

the class LocalActivityThrowingErrorTest method localActivityThrowsError.

@Test
public void localActivityThrowsError() {
    String name = testName.getMethodName();
    WorkflowClient client = testWorkflowRule.getWorkflowClient();
    TestWorkflow4 workflow = client.newWorkflowStub(TestWorkflow4.class, options);
    try {
        workflow.execute(name, true);
    } catch (WorkflowFailedException e) {
        assertTrue(e.getCause() instanceof ActivityFailure);
        assertTrue(e.getCause().getCause() instanceof ApplicationFailure);
        assertEquals(FAILURE_TYPE, ((ApplicationFailure) e.getCause().getCause()).getType());
        assertEquals(3, 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)

Example 5 with ActivityFailure

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

the class ActivityApplicationFailureRetryTest method testActivityApplicationFailureRetry.

@Test
public void testActivityApplicationFailureRetry() {
    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("simulatedType", ((ApplicationFailure) e.getCause().getCause()).getType());
        Assert.assertEquals("io.temporal.failure.ApplicationFailure: message='simulated', type='simulatedType', nonRetryable=true", e.getCause().getCause().toString());
    }
    Assert.assertEquals(3, activitiesImpl.applicationFailureCounter.get());
}
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

ActivityFailure (io.temporal.failure.ActivityFailure)21 Test (org.junit.Test)20 WorkflowException (io.temporal.client.WorkflowException)15 ApplicationFailure (io.temporal.failure.ApplicationFailure)14 TestWorkflow1 (io.temporal.workflow.shared.TestWorkflows.TestWorkflow1)10 WorkflowClient (io.temporal.client.WorkflowClient)6 WorkflowOptions (io.temporal.client.WorkflowOptions)6 TimeoutFailure (io.temporal.failure.TimeoutFailure)6 WorkflowFailedException (io.temporal.client.WorkflowFailedException)5 Worker (io.temporal.worker.Worker)4 TestWorkflow4 (io.temporal.workflow.shared.TestWorkflows.TestWorkflow4)4 ChildWorkflowFailure (io.temporal.failure.ChildWorkflowFailure)3 GreetingWorkflow (io.temporal.samples.hello.HelloException.GreetingWorkflow)2 GreetingActivities (io.temporal.samples.hello.HelloException.GreetingActivities)1 TracingWorkerInterceptor (io.temporal.testing.internal.TracingWorkerInterceptor)1 Saga (io.temporal.workflow.Saga)1 TestWorkflowStringArg (io.temporal.workflow.shared.TestWorkflows.TestWorkflowStringArg)1