use of com.uber.cadence.client.WorkflowStub in project cadence-client by uber-java.
the class WorkflowTest method testDetachedScope.
@Test
public void testDetachedScope() throws InterruptedException {
startWorkerFor(TestDetachedCancellationScope.class);
WorkflowStub client = workflowClient.newUntypedWorkflowStub("TestWorkflow1::execute", newWorkflowOptionsBuilder(taskList).build());
client.start();
// To let activityWithDelay start.
Thread.sleep(500);
client.cancel();
try {
client.getResult(String.class);
fail("unreachable");
} catch (CancellationException ignored) {
}
activitiesImpl.assertInvocations("activityWithDelay", "activity1", "activity2", "activity3");
}
use of com.uber.cadence.client.WorkflowStub in project cadence-client by uber-java.
the class WorkflowTest method testSyncUntypedAndStackTrace.
@Test
public void testSyncUntypedAndStackTrace() throws InterruptedException {
startWorkerFor(TestSyncWorkflowImpl.class);
WorkflowStub workflowStub = workflowClient.newUntypedWorkflowStub("TestWorkflow1::execute", newWorkflowOptionsBuilder(taskList).build());
WorkflowExecution execution = workflowStub.start();
Thread.sleep(500);
String stackTrace = workflowStub.query(WorkflowClient.QUERY_TYPE_STACK_TRCE, String.class);
assertTrue(stackTrace, stackTrace.contains("WorkflowTest$TestSyncWorkflowImpl.execute"));
assertTrue(stackTrace, stackTrace.contains("activityWithDelay"));
// Test stub created from workflow execution.
workflowStub = workflowClient.newUntypedWorkflowStub(execution, workflowStub.getWorkflowType());
stackTrace = workflowStub.query(WorkflowClient.QUERY_TYPE_STACK_TRCE, String.class);
assertTrue(stackTrace, stackTrace.contains("WorkflowTest$TestSyncWorkflowImpl.execute"));
assertTrue(stackTrace, stackTrace.contains("activityWithDelay"));
String result = workflowStub.getResult(String.class);
assertEquals("activity10", result);
}
use of com.uber.cadence.client.WorkflowStub in project cadence-client by uber-java.
the class WorkflowTest method testWorkflowCancellation.
@Test
public void testWorkflowCancellation() {
startWorkerFor(TestSyncWorkflowImpl.class);
WorkflowStub client = workflowClient.newUntypedWorkflowStub("TestWorkflow1::execute", newWorkflowOptionsBuilder(taskList).build());
client.start();
client.cancel();
try {
client.getResult(String.class);
fail("unreachable");
} catch (CancellationException ignored) {
}
}
use of com.uber.cadence.client.WorkflowStub in project cadence-client by uber-java.
the class WorkflowTestingTest method testTimerCancellation.
@Test
public void testTimerCancellation() throws TException {
Worker worker = testEnvironment.newWorker(TASK_LIST);
worker.registerWorkflowImplementationTypes(TestTimerCancellationWorkflow.class);
worker.registerActivitiesImplementations(new ActivityImpl());
worker.start();
WorkflowClient client = testEnvironment.newWorkflowClient();
TestWorkflow workflow = client.newWorkflowStub(TestWorkflow.class);
WorkflowExecution execution = WorkflowClient.start(workflow::workflow1, "input1");
WorkflowStub untyped = client.newUntypedWorkflowStub(execution, Optional.empty());
testEnvironment.sleep(Duration.ofHours(1));
untyped.cancel();
try {
untyped.getResult(String.class);
fail("unreacheable");
} catch (CancellationException e) {
}
History history = testEnvironment.getWorkflowService().GetWorkflowExecutionHistory(new GetWorkflowExecutionHistoryRequest().setExecution(execution).setDomain(client.getDomain())).getHistory();
List<HistoryEvent> historyEvents = history.getEvents();
assertTrue(WorkflowExecutionUtils.prettyPrintHistory(history, false), WorkflowExecutionUtils.containsEvent(historyEvents, EventType.TimerCanceled));
}
use of com.uber.cadence.client.WorkflowStub 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) {
}
}
Aggregations