use of com.uber.cadence.worker.Worker 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));
}
use of com.uber.cadence.worker.Worker in project cadence-client by uber-java.
the class WorkflowTest method setUp.
@Before
public void setUp() {
if (testName.getMethodName().equals("testExecute[TestService]") || testName.getMethodName().equals("testStart[TestService]")) {
taskList = ANNOTATION_TASK_LIST;
} else {
taskList = "WorkflowTest-" + testName.getMethodName();
}
if (useExternalService) {
worker = new Worker(domain, taskList);
workflowClient = WorkflowClient.newInstance(domain);
WorkflowClientOptions clientOptions = new WorkflowClientOptions.Builder().setDataConverter(JsonDataConverter.getInstance()).build();
workflowClientWithOptions = WorkflowClient.newInstance(domain, clientOptions);
scheduledExecutor = new ScheduledThreadPoolExecutor(1);
} else {
TestEnvironmentOptions testOptions = new Builder().setDomain(domain).build();
testEnvironment = TestWorkflowEnvironment.newInstance(testOptions);
worker = testEnvironment.newWorker(taskList);
workflowClient = testEnvironment.newWorkflowClient();
workflowClientWithOptions = testEnvironment.newWorkflowClient();
}
ActivityCompletionClient completionClient = workflowClient.newActivityCompletionClient();
activitiesImpl = new TestActivitiesImpl(completionClient);
worker.registerActivitiesImplementations(activitiesImpl);
newWorkflowOptionsBuilder(taskList);
newActivityOptions1(taskList);
activitiesImpl.invocations.clear();
activitiesImpl.procResult.clear();
}
use of com.uber.cadence.worker.Worker in project cadence-client by uber-java.
the class WorkflowTestingTest method testSignalWithDelayedCallback.
@Test
public void testSignalWithDelayedCallback() {
Worker worker = testEnvironment.newWorker(TASK_LIST);
worker.registerWorkflowImplementationTypes(SignaledWorkflowImpl.class);
worker.start();
WorkflowClient client = testEnvironment.newWorkflowClient();
SignaledWorkflow workflow = client.newWorkflowStub(SignaledWorkflow.class);
testEnvironment.registerDelayedCallback(Duration.ofMinutes(65), () -> workflow.ProcessSignal("signalInput"));
assertEquals("signalInput-input1", workflow.workflow1("input1"));
}
use of com.uber.cadence.worker.Worker 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.worker.Worker in project cadence-client by uber-java.
the class WorkflowTestingTest method testActivityScheduleToCloseTimeout.
@Test
public void testActivityScheduleToCloseTimeout() {
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(1, 10, 10);
fail("unreacheable");
} catch (WorkflowException e) {
assertTrue(e.getCause() instanceof ActivityTimeoutException);
assertEquals(TimeoutType.SCHEDULE_TO_CLOSE, ((ActivityTimeoutException) e.getCause()).getTimeoutType());
}
}
Aggregations