Search in sources :

Example 1 with WorkflowClient

use of com.uber.cadence.client.WorkflowClient 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"));
}
Also used : Worker(com.uber.cadence.worker.Worker) WorkflowClient(com.uber.cadence.client.WorkflowClient) Test(org.junit.Test)

Example 2 with WorkflowClient

use of com.uber.cadence.client.WorkflowClient 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));
}
Also used : WorkflowStub(com.uber.cadence.client.WorkflowStub) CancellationException(java.util.concurrent.CancellationException) GetWorkflowExecutionHistoryRequest(com.uber.cadence.GetWorkflowExecutionHistoryRequest) Worker(com.uber.cadence.worker.Worker) WorkflowClient(com.uber.cadence.client.WorkflowClient) WorkflowExecution(com.uber.cadence.WorkflowExecution) History(com.uber.cadence.History) HistoryEvent(com.uber.cadence.HistoryEvent) Test(org.junit.Test)

Example 3 with WorkflowClient

use of com.uber.cadence.client.WorkflowClient 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());
    }
}
Also used : ActivityTimeoutException(com.uber.cadence.workflow.ActivityTimeoutException) WorkflowException(com.uber.cadence.client.WorkflowException) Worker(com.uber.cadence.worker.Worker) WorkflowClient(com.uber.cadence.client.WorkflowClient) Test(org.junit.Test)

Example 4 with WorkflowClient

use of com.uber.cadence.client.WorkflowClient in project cadence-client by uber-java.

the class WorkflowTestingTest method testEmptyWorkflow.

@Test
public void testEmptyWorkflow() {
    Worker worker = testEnvironment.newWorker(TASK_LIST);
    worker.registerWorkflowImplementationTypes(EmptyWorkflowImpl.class);
    worker.start();
    WorkflowClient client = testEnvironment.newWorkflowClient();
    TestWorkflow workflow = client.newWorkflowStub(TestWorkflow.class);
    String result = workflow.workflow1("input1");
    assertEquals("TestWorkflow::workflow1-input1", result);
}
Also used : Worker(com.uber.cadence.worker.Worker) WorkflowClient(com.uber.cadence.client.WorkflowClient) Test(org.junit.Test)

Example 5 with WorkflowClient

use of com.uber.cadence.client.WorkflowClient in project cadence-client by uber-java.

the class WorkflowTestingTest method testChild.

@Test
public void testChild() {
    Worker worker = testEnvironment.newWorker(TASK_LIST);
    worker.registerWorkflowImplementationTypes(ChildWorklfowImpl.class, ParentWorkflowImpl.class);
    worker.start();
    WorkflowClient client = testEnvironment.newWorkflowClient();
    WorkflowOptions options = new WorkflowOptions.Builder().setWorkflowId("parent1").build();
    ParentWorkflow workflow = client.newWorkflowStub(ParentWorkflow.class, options);
    String result = workflow.workflow("input1");
    assertEquals("child input1", result);
}
Also used : Worker(com.uber.cadence.worker.Worker) WorkflowClient(com.uber.cadence.client.WorkflowClient) WorkflowOptions(com.uber.cadence.client.WorkflowOptions) Test(org.junit.Test)

Aggregations

WorkflowClient (com.uber.cadence.client.WorkflowClient)16 Test (org.junit.Test)16 Worker (com.uber.cadence.worker.Worker)15 WorkflowException (com.uber.cadence.client.WorkflowException)7 WorkflowOptions (com.uber.cadence.client.WorkflowOptions)3 WorkflowStub (com.uber.cadence.client.WorkflowStub)3 ActivityTimeoutException (com.uber.cadence.workflow.ActivityTimeoutException)3 WorkflowExecution (com.uber.cadence.WorkflowExecution)2 CancellationException (java.util.concurrent.CancellationException)2 GetWorkflowExecutionHistoryRequest (com.uber.cadence.GetWorkflowExecutionHistoryRequest)1 History (com.uber.cadence.History)1 HistoryEvent (com.uber.cadence.HistoryEvent)1 DuplicateWorkflowException (com.uber.cadence.client.DuplicateWorkflowException)1 WorkflowClientInterceptorBase (com.uber.cadence.client.WorkflowClientInterceptorBase)1 WorkflowClientOptions (com.uber.cadence.client.WorkflowClientOptions)1 WorkflowTimedOutException (com.uber.cadence.client.WorkflowTimedOutException)1 DeterministicRunnerTest (com.uber.cadence.internal.sync.DeterministicRunnerTest)1 Builder (com.uber.cadence.testing.TestEnvironmentOptions.Builder)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1