use of com.uber.cadence.WorkflowExecution in project cadence-client by uber-java.
the class StateMachines method completeExternalSignal.
private static void completeExternalSignal(RequestContext ctx, SignalExternalData data, String runId, long notUsed) {
SignalExternalWorkflowExecutionInitiatedEventAttributes initiatedEvent = data.initiatedEvent;
WorkflowExecution signaledExecution = initiatedEvent.getWorkflowExecution().deepCopy().setRunId(runId);
ExternalWorkflowExecutionSignaledEventAttributes a = new ExternalWorkflowExecutionSignaledEventAttributes().setInitiatedEventId(data.initiatedEventId).setWorkflowExecution(signaledExecution).setControl(initiatedEvent.getControl()).setDomain(initiatedEvent.getDomain());
HistoryEvent event = new HistoryEvent().setEventType(EventType.ExternalWorkflowExecutionSignaled).setExternalWorkflowExecutionSignaledEventAttributes(a);
ctx.addEvent(event);
}
use of com.uber.cadence.WorkflowExecution in project cadence-client by uber-java.
the class TestWorkflowService method startWorkflowExecutionNoRunningCheck.
private StartWorkflowExecutionResponse startWorkflowExecutionNoRunningCheck(StartWorkflowExecutionRequest startRequest, Optional<TestWorkflowMutableState> parent, WorkflowId workflowId) throws InternalServiceError, BadRequestError {
String domain = startRequest.getDomain();
TestWorkflowMutableState result = new TestWorkflowMutableStateImpl(startRequest, parent, this, store);
WorkflowExecution execution = result.getExecutionId().getExecution();
ExecutionId executionId = new ExecutionId(domain, execution);
lock.lock();
try {
openExecutions.put(workflowId, result);
executions.put(executionId, result);
} finally {
lock.unlock();
}
result.startWorkflow();
return new StartWorkflowExecutionResponse().setRunId(execution.getRunId());
}
use of com.uber.cadence.WorkflowExecution in project cadence-client by uber-java.
the class WorkflowTest method testSignalDuringLastDecision.
@Test
public void testSignalDuringLastDecision() throws InterruptedException {
startWorkerFor(TestSignalDuringLastDecisionWorkflowImpl.class);
WorkflowOptions.Builder options = newWorkflowOptionsBuilder(taskList);
options.setWorkflowId("testSignalDuringLastDecision-" + UUID.randomUUID().toString());
TestWorkflowSignaled client = workflowClient.newWorkflowStub(TestWorkflowSignaled.class, options.build());
WorkflowExecution execution = WorkflowClient.start(client::execute);
registerDelayedCallback(Duration.ofSeconds(1), () -> {
try {
try {
sendSignal.get(2, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
client.signal1("Signal Input");
} catch (TimeoutException | ExecutionException e) {
throw new RuntimeException(e);
}
assertEquals("Signal Input", workflowClient.newUntypedWorkflowStub(execution, Optional.empty()).getResult(String.class));
});
}
use of com.uber.cadence.WorkflowExecution 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.WorkflowExecution in project cadence-client by uber-java.
the class WorkflowTest method testSignal.
@Test
public void testSignal() throws Exception {
AtomicReference<WorkflowExecution> execution = new AtomicReference<>();
startWorkerFor(TestSignalWorkflowImpl.class);
WorkflowOptions.Builder optionsBuilder = newWorkflowOptionsBuilder(taskList);
String workflowId = UUID.randomUUID().toString();
optionsBuilder.setWorkflowId(workflowId);
AtomicReference<QueryableWorkflow> client = new AtomicReference<>();
registerDelayedCallback(Duration.ofSeconds(1), () -> {
assertEquals(workflowId, execution.get().getWorkflowId());
assertEquals("initial", client.get().getState());
client.get().mySignal("Hello ");
try {
Thread.sleep(200);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// Test client.get() created using WorkflowExecution
client.set(workflowClient.newWorkflowStub(QueryableWorkflow.class, execution.get().getWorkflowId(), Optional.of(execution.get().getRunId())));
assertEquals("Hello ", client.get().getState());
// Test getTrace through replay by a local worker.
Worker queryWorker;
if (useExternalService) {
queryWorker = new Worker(domain, taskList);
} else {
queryWorker = testEnvironment.newWorker(taskList);
}
queryWorker.registerWorkflowImplementationTypes(TestSignalWorkflowImpl.class);
String queryResult = null;
try {
queryResult = queryWorker.queryWorkflowExecution(execution.get(), "QueryableWorkflow::getState", String.class);
} catch (Exception e) {
throw new RuntimeException(e);
}
assertEquals("Hello ", queryResult);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
client.get().mySignal("World!");
assertEquals("World!", client.get().getState());
assertEquals("Hello World!", workflowClient.newUntypedWorkflowStub(execution.get(), Optional.empty()).getResult(String.class));
});
client.set(workflowClient.newWorkflowStub(QueryableWorkflow.class, optionsBuilder.build()));
// To execute workflow client.execute() would do. But we want to start workflow and immediately return.
execution.set(WorkflowClient.start(client.get()::execute));
}
Aggregations