Search in sources :

Example 11 with WorkflowClient

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

Example 12 with WorkflowClient

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

the class WorkflowTestingTest method testTimer.

@Test
public void testTimer() {
    Worker worker = testEnvironment.newWorker(TASK_LIST);
    worker.registerWorkflowImplementationTypes(TimerWorkflow.class);
    worker.start();
    WorkflowClient client = testEnvironment.newWorkflowClient();
    TestWorkflow workflow = client.newWorkflowStub(TestWorkflow.class);
    long start = testEnvironment.currentTimeMillis();
    String result = workflow.workflow1("input1");
    assertEquals("TestWorkflow::workflow1-input1", result);
    assertTrue(testEnvironment.currentTimeMillis() - start >= Duration.ofHours(2).toMillis());
}
Also used : Worker(com.uber.cadence.worker.Worker) WorkflowClient(com.uber.cadence.client.WorkflowClient) Test(org.junit.Test)

Example 13 with WorkflowClient

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

the class WorkflowTestingTest method testActivityStartToCloseTimeout.

@Test
public void testActivityStartToCloseTimeout() {
    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(10, 10, 1);
        fail("unreacheable");
    } catch (WorkflowException e) {
        assertTrue(e.getCause() instanceof ActivityTimeoutException);
        assertEquals(TimeoutType.START_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 14 with WorkflowClient

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

the class WorkflowTestingTest method testActivityFailure.

@Test
public void testActivityFailure() {
    Worker worker = testEnvironment.newWorker(TASK_LIST);
    worker.registerWorkflowImplementationTypes(ActivityWorkflow.class);
    worker.registerActivitiesImplementations(new FailingActivityImpl());
    worker.start();
    WorkflowClient client = testEnvironment.newWorkflowClient();
    TestWorkflow workflow = client.newWorkflowStub(TestWorkflow.class);
    try {
        workflow.workflow1("input1");
        fail("unreacheable");
    } catch (WorkflowException e) {
        assertEquals("TestActivity::activity1-input1", e.getCause().getCause().getMessage());
    }
}
Also used : WorkflowException(com.uber.cadence.client.WorkflowException) Worker(com.uber.cadence.worker.Worker) WorkflowClient(com.uber.cadence.client.WorkflowClient) Test(org.junit.Test)

Example 15 with WorkflowClient

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

the class WorkflowTestingTest method testWorkflowTimeout.

@Test
public void testWorkflowTimeout() {
    Worker worker = testEnvironment.newWorker(TASK_LIST);
    worker.registerWorkflowImplementationTypes(TimeoutWorkflow.class);
    worker.start();
    WorkflowClient client = testEnvironment.newWorkflowClient();
    WorkflowOptions options = new WorkflowOptions.Builder().setExecutionStartToCloseTimeout(Duration.ofSeconds(1)).build();
    TestWorkflow workflow = client.newWorkflowStub(TestWorkflow.class, options);
    try {
        workflow.workflow1("bar");
        fail("unreacheable");
    } catch (WorkflowException e) {
        assertTrue(e instanceof WorkflowTimedOutException);
        assertEquals(TimeoutType.START_TO_CLOSE, ((WorkflowTimedOutException) e).getTimeoutType());
    }
}
Also used : WorkflowTimedOutException(com.uber.cadence.client.WorkflowTimedOutException) WorkflowException(com.uber.cadence.client.WorkflowException) 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