Search in sources :

Example 1 with WorkflowStub

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

the class WorkflowTest method testDetachedScope.

@Test
public void testDetachedScope() throws InterruptedException {
    startWorkerFor(TestDetachedCancellationScope.class);
    WorkflowStub client = workflowClient.newUntypedWorkflowStub("TestWorkflow1::execute", newWorkflowOptionsBuilder(taskList).build());
    client.start();
    // To let activityWithDelay start.
    Thread.sleep(500);
    client.cancel();
    try {
        client.getResult(String.class);
        fail("unreachable");
    } catch (CancellationException ignored) {
    }
    activitiesImpl.assertInvocations("activityWithDelay", "activity1", "activity2", "activity3");
}
Also used : WorkflowStub(com.uber.cadence.client.WorkflowStub) CancellationException(java.util.concurrent.CancellationException) DeterministicRunnerTest(com.uber.cadence.internal.sync.DeterministicRunnerTest) Test(org.junit.Test)

Example 2 with WorkflowStub

use of com.uber.cadence.client.WorkflowStub 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);
}
Also used : WorkflowStub(com.uber.cadence.client.WorkflowStub) WorkflowExecution(com.uber.cadence.WorkflowExecution) DeterministicRunnerTest(com.uber.cadence.internal.sync.DeterministicRunnerTest) Test(org.junit.Test)

Example 3 with WorkflowStub

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

the class WorkflowTest method testWorkflowCancellation.

@Test
public void testWorkflowCancellation() {
    startWorkerFor(TestSyncWorkflowImpl.class);
    WorkflowStub client = workflowClient.newUntypedWorkflowStub("TestWorkflow1::execute", newWorkflowOptionsBuilder(taskList).build());
    client.start();
    client.cancel();
    try {
        client.getResult(String.class);
        fail("unreachable");
    } catch (CancellationException ignored) {
    }
}
Also used : WorkflowStub(com.uber.cadence.client.WorkflowStub) CancellationException(java.util.concurrent.CancellationException) DeterministicRunnerTest(com.uber.cadence.internal.sync.DeterministicRunnerTest) Test(org.junit.Test)

Example 4 with WorkflowStub

use of com.uber.cadence.client.WorkflowStub 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 5 with WorkflowStub

use of com.uber.cadence.client.WorkflowStub 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)

Aggregations

WorkflowStub (com.uber.cadence.client.WorkflowStub)8 Test (org.junit.Test)8 DeterministicRunnerTest (com.uber.cadence.internal.sync.DeterministicRunnerTest)6 CancellationException (java.util.concurrent.CancellationException)5 WorkflowExecution (com.uber.cadence.WorkflowExecution)4 WorkflowClient (com.uber.cadence.client.WorkflowClient)3 Worker (com.uber.cadence.worker.Worker)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)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 WorkflowException (com.uber.cadence.client.WorkflowException)1 WorkflowOptions (com.uber.cadence.client.WorkflowOptions)1 Builder (com.uber.cadence.testing.TestEnvironmentOptions.Builder)1