use of com.uber.cadence.WorkflowExecution 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.WorkflowExecution 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.WorkflowExecution in project cadence-client by uber-java.
the class WorkflowTest method testSignalUntyped.
@Test
public void testSignalUntyped() {
startWorkerFor(TestSignalWorkflowImpl.class);
String workflowType = QueryableWorkflow.class.getSimpleName() + "::execute";
AtomicReference<WorkflowExecution> execution = new AtomicReference<>();
WorkflowStub client = workflowClient.newUntypedWorkflowStub(workflowType, newWorkflowOptionsBuilder(taskList).build());
// To execute workflow client.execute() would do. But we want to start workflow and immediately return.
registerDelayedCallback(Duration.ofSeconds(1), () -> {
assertEquals("initial", client.query("QueryableWorkflow::getState", String.class));
client.signal("testSignal", "Hello ");
while (!"Hello ".equals(client.query("QueryableWorkflow::getState", String.class))) {
}
assertEquals("Hello ", client.query("QueryableWorkflow::getState", String.class));
client.signal("testSignal", "World!");
while (!"World!".equals(client.query("QueryableWorkflow::getState", String.class))) {
}
assertEquals("World!", client.query("QueryableWorkflow::getState", String.class));
assertEquals("Hello World!", workflowClient.newUntypedWorkflowStub(execution.get(), Optional.of(workflowType)).getResult(String.class));
});
execution.set(client.start());
assertEquals("Hello World!", client.getResult(String.class));
}
use of com.uber.cadence.WorkflowExecution in project cadence-client by uber-java.
the class TestWorkflowService method startWorkflowExecutionImpl.
StartWorkflowExecutionResponse startWorkflowExecutionImpl(StartWorkflowExecutionRequest startRequest, Optional<TestWorkflowMutableState> parent) throws BadRequestError, WorkflowExecutionAlreadyStartedError, InternalServiceError {
String requestWorkflowId = requireNotNull("WorkflowId", startRequest.getWorkflowId());
String domain = requireNotNull("Domain", startRequest.getDomain());
WorkflowId workflowId = new WorkflowId(domain, requestWorkflowId);
TestWorkflowMutableState running;
lock.lock();
try {
running = openExecutions.get(workflowId);
} finally {
lock.unlock();
}
if (running != null) {
WorkflowExecutionAlreadyStartedError error = new WorkflowExecutionAlreadyStartedError();
WorkflowExecution execution = running.getExecutionId().getExecution();
error.setMessage(String.format("Workflow execution already running. WorkflowId: %s, " + "RunId: %s", execution.getWorkflowId(), execution.getRunId()));
error.setRunId(execution.getRunId());
error.setStartRequestId(startRequest.getRequestId());
throw error;
}
return startWorkflowExecutionNoRunningCheck(startRequest, parent, workflowId);
}
use of com.uber.cadence.WorkflowExecution in project cadence-client by uber-java.
the class WorkflowClientInternal method newWorkflowStub.
@Override
public <T> T newWorkflowStub(Class<T> workflowInterface, String workflowId, Optional<String> runId) {
checkAnnotation(workflowInterface, WorkflowMethod.class, QueryMethod.class);
if (Strings.isNullOrEmpty(workflowId)) {
throw new IllegalArgumentException("workflowId is null or empty");
}
WorkflowExecution execution = new WorkflowExecution();
execution.setWorkflowId(workflowId);
if (runId.isPresent()) {
execution.setRunId(runId.get());
}
WorkflowInvocationHandler invocationHandler = new WorkflowInvocationHandler(workflowInterface, genericClient, execution, dataConverter, interceptors);
@SuppressWarnings("unchecked") T result = (T) Proxy.newProxyInstance(WorkflowInternal.class.getClassLoader(), new Class<?>[] { workflowInterface }, invocationHandler);
return result;
}
Aggregations