use of com.uber.cadence.client.WorkflowClient in project cadence-client by uber-java.
the class WorkflowTestingTest method testActivityCancellation.
@Test
public void testActivityCancellation() {
Worker worker = testEnvironment.newWorker(TASK_LIST);
worker.registerWorkflowImplementationTypes(TestCancellationWorkflow.class);
worker.registerActivitiesImplementations(new TestCancellationActivityImpl());
worker.start();
WorkflowClient client = testEnvironment.newWorkflowClient();
TestWorkflow workflow = client.newWorkflowStub(TestWorkflow.class);
try {
WorkflowExecution execution = WorkflowClient.start(workflow::workflow1, "input1");
WorkflowStub untyped = client.newUntypedWorkflowStub(execution, Optional.empty());
// While activity is running time skipping is disabled.
// So sleep for 1 second after it is scheduled.
testEnvironment.sleep(Duration.ofSeconds(3601));
untyped.cancel();
untyped.getResult(String.class);
fail("unreacheable");
} catch (CancellationException e) {
}
}
use of com.uber.cadence.client.WorkflowClient in project cadence-client by uber-java.
the class WorkflowTestingTest method testTimer.
@Test
public void testTimer() {
Worker worker = testEnvironment.newWorker(TASK_LIST);
worker.registerWorkflowImplementationTypes(TimerWorkflow.class);
worker.start();
WorkflowClient client = testEnvironment.newWorkflowClient();
TestWorkflow workflow = client.newWorkflowStub(TestWorkflow.class);
long start = testEnvironment.currentTimeMillis();
String result = workflow.workflow1("input1");
assertEquals("TestWorkflow::workflow1-input1", result);
assertTrue(testEnvironment.currentTimeMillis() - start >= Duration.ofHours(2).toMillis());
}
use of com.uber.cadence.client.WorkflowClient in project cadence-client by uber-java.
the class WorkflowTestingTest method testActivityStartToCloseTimeout.
@Test
public void testActivityStartToCloseTimeout() {
Worker worker = testEnvironment.newWorker(TASK_LIST);
worker.registerWorkflowImplementationTypes(TestActivityTimeoutWorkflowImpl.class);
worker.registerActivitiesImplementations(new TimingOutActivityImpl());
worker.start();
WorkflowClient client = testEnvironment.newWorkflowClient();
TestActivityTimeoutWorkflow workflow = client.newWorkflowStub(TestActivityTimeoutWorkflow.class);
try {
workflow.workflow(10, 10, 1);
fail("unreacheable");
} catch (WorkflowException e) {
assertTrue(e.getCause() instanceof ActivityTimeoutException);
assertEquals(TimeoutType.START_TO_CLOSE, ((ActivityTimeoutException) e.getCause()).getTimeoutType());
}
}
use of com.uber.cadence.client.WorkflowClient in project cadence-client by uber-java.
the class WorkflowTestingTest method testActivityFailure.
@Test
public void testActivityFailure() {
Worker worker = testEnvironment.newWorker(TASK_LIST);
worker.registerWorkflowImplementationTypes(ActivityWorkflow.class);
worker.registerActivitiesImplementations(new FailingActivityImpl());
worker.start();
WorkflowClient client = testEnvironment.newWorkflowClient();
TestWorkflow workflow = client.newWorkflowStub(TestWorkflow.class);
try {
workflow.workflow1("input1");
fail("unreacheable");
} catch (WorkflowException e) {
assertEquals("TestActivity::activity1-input1", e.getCause().getCause().getMessage());
}
}
use of com.uber.cadence.client.WorkflowClient 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());
}
}
Aggregations