use of com.uber.cadence.client.WorkflowException in project cadence-client by uber-java.
the class WorkflowTestingTest method testWorkflowTimeout.
@Test
public void testWorkflowTimeout() {
Worker worker = testEnvironment.newWorker(TASK_LIST);
worker.registerWorkflowImplementationTypes(TimeoutWorkflow.class);
worker.start();
WorkflowClient client = testEnvironment.newWorkflowClient();
WorkflowOptions options = new WorkflowOptions.Builder().setExecutionStartToCloseTimeout(Duration.ofSeconds(1)).build();
TestWorkflow workflow = client.newWorkflowStub(TestWorkflow.class, options);
try {
workflow.workflow1("bar");
fail("unreacheable");
} catch (WorkflowException e) {
assertTrue(e instanceof WorkflowTimedOutException);
assertEquals(TimeoutType.START_TO_CLOSE, ((WorkflowTimedOutException) e).getTimeoutType());
}
}
use of com.uber.cadence.client.WorkflowException in project cadence-client by uber-java.
the class WorkflowTest method testChildWorkflowRetry.
@Test
public void testChildWorkflowRetry() {
AngryChildActivityImpl angryChildActivity = new AngryChildActivityImpl();
worker.registerActivitiesImplementations(angryChildActivity);
startWorkerFor(TestChildWorkflowRetryWorkflow.class, AngryChild.class);
WorkflowOptions.Builder options = new WorkflowOptions.Builder();
options.setExecutionStartToCloseTimeout(Duration.ofSeconds(20));
options.setTaskStartToCloseTimeout(Duration.ofSeconds(2));
options.setTaskList(taskList);
AtomicReference<String> capturedWorkflowType = new AtomicReference<>();
WorkflowClientOptions clientOptions = new WorkflowClientOptions.Builder().setInterceptors(new WorkflowClientInterceptorBase() {
@Override
public WorkflowStub newUntypedWorkflowStub(String workflowType, WorkflowOptions options, WorkflowStub next) {
capturedWorkflowType.set(workflowType);
return next;
}
}).build();
WorkflowClient wc;
if (useExternalService) {
wc = WorkflowClient.newInstance(domain, clientOptions);
} else {
wc = testEnvironment.newWorkflowClient(clientOptions);
}
TestWorkflow1 client = wc.newWorkflowStub(TestWorkflow1.class, options.build());
try {
client.execute(taskList);
fail("unreachable");
} catch (WorkflowException e) {
assertTrue(e.getCause() instanceof ChildWorkflowFailureException);
assertTrue(e.getCause().getCause() instanceof UnsupportedOperationException);
assertEquals("simulated failure", e.getCause().getCause().getMessage());
}
assertEquals("TestWorkflow1::execute", capturedWorkflowType.get());
assertEquals(3, angryChildActivity.getInvocationCount());
}
use of com.uber.cadence.client.WorkflowException in project cadence-client by uber-java.
the class WorkflowStubImpl method mapToWorkflowFailureException.
private <R> R mapToWorkflowFailureException(Exception failure, Class<R> returnType) {
failure = CheckedExceptionWrapper.unwrap(failure);
Class<Throwable> detailsClass;
if (failure instanceof WorkflowExecutionFailedException) {
WorkflowExecutionFailedException executionFailed = (WorkflowExecutionFailedException) failure;
try {
@SuppressWarnings("unchecked") Class<Throwable> dc = (Class<Throwable>) Class.forName(executionFailed.getReason());
detailsClass = dc;
} catch (Exception e) {
RuntimeException ee = new RuntimeException("Couldn't deserialize failure cause " + "as the reason field is expected to contain an exception class name", executionFailed);
throw new WorkflowFailureException(execution.get(), workflowType, executionFailed.getDecisionTaskCompletedEventId(), ee);
}
Throwable cause = dataConverter.fromData(executionFailed.getDetails(), detailsClass);
throw new WorkflowFailureException(execution.get(), workflowType, executionFailed.getDecisionTaskCompletedEventId(), cause);
} else if (failure instanceof EntityNotExistsError) {
throw new WorkflowNotFoundException(execution.get(), workflowType, failure.getMessage());
} else if (failure instanceof CancellationException) {
throw (CancellationException) failure;
} else if (failure instanceof WorkflowException) {
throw (WorkflowException) failure;
} else {
throw new WorkflowServiceException(execution.get(), workflowType, failure);
}
}
Aggregations