Search in sources :

Example 6 with WorkflowExecution

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);
}
Also used : ExternalWorkflowExecutionSignaledEventAttributes(com.uber.cadence.ExternalWorkflowExecutionSignaledEventAttributes) WorkflowExecution(com.uber.cadence.WorkflowExecution) HistoryEvent(com.uber.cadence.HistoryEvent) SignalExternalWorkflowExecutionInitiatedEventAttributes(com.uber.cadence.SignalExternalWorkflowExecutionInitiatedEventAttributes)

Example 7 with WorkflowExecution

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());
}
Also used : StartWorkflowExecutionResponse(com.uber.cadence.StartWorkflowExecutionResponse) WorkflowExecution(com.uber.cadence.WorkflowExecution)

Example 8 with WorkflowExecution

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));
    });
}
Also used : WorkflowOptions(com.uber.cadence.client.WorkflowOptions) WorkflowExecution(com.uber.cadence.WorkflowExecution) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) DeterministicRunnerTest(com.uber.cadence.internal.sync.DeterministicRunnerTest) Test(org.junit.Test)

Example 9 with WorkflowExecution

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);
}
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 10 with WorkflowExecution

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));
}
Also used : WorkflowExecution(com.uber.cadence.WorkflowExecution) WorkflowOptions(com.uber.cadence.client.WorkflowOptions) Worker(com.uber.cadence.worker.Worker) AtomicReference(java.util.concurrent.atomic.AtomicReference) TimeoutException(java.util.concurrent.TimeoutException) ActivityNotExistsException(com.uber.cadence.client.ActivityNotExistsException) CancellationException(java.util.concurrent.CancellationException) FileNotFoundException(java.io.FileNotFoundException) DuplicateWorkflowException(com.uber.cadence.client.DuplicateWorkflowException) WorkflowFailureException(com.uber.cadence.client.WorkflowFailureException) ActivityCancelledException(com.uber.cadence.client.ActivityCancelledException) WorkflowException(com.uber.cadence.client.WorkflowException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) DeterministicRunnerTest(com.uber.cadence.internal.sync.DeterministicRunnerTest) Test(org.junit.Test)

Aggregations

WorkflowExecution (com.uber.cadence.WorkflowExecution)30 CancellationException (java.util.concurrent.CancellationException)11 SignalExternalWorkflowException (com.uber.cadence.workflow.SignalExternalWorkflowException)8 ChildWorkflowTerminatedException (com.uber.cadence.workflow.ChildWorkflowTerminatedException)7 ChildWorkflowTimedOutException (com.uber.cadence.workflow.ChildWorkflowTimedOutException)7 StartChildWorkflowFailedException (com.uber.cadence.workflow.StartChildWorkflowFailedException)7 HistoryEvent (com.uber.cadence.HistoryEvent)6 Test (org.junit.Test)6 TimeoutException (java.util.concurrent.TimeoutException)5 TException (org.apache.thrift.TException)5 WorkflowStub (com.uber.cadence.client.WorkflowStub)4 GetWorkflowExecutionHistoryRequest (com.uber.cadence.GetWorkflowExecutionHistoryRequest)3 History (com.uber.cadence.History)3 StartChildWorkflowExecutionFailedEventAttributes (com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes)3 WorkflowExecutionAlreadyStartedError (com.uber.cadence.WorkflowExecutionAlreadyStartedError)3 WorkflowType (com.uber.cadence.WorkflowType)3 DeterministicRunnerTest (com.uber.cadence.internal.sync.DeterministicRunnerTest)3 ChildWorkflowExecutionCanceledEventAttributes (com.uber.cadence.ChildWorkflowExecutionCanceledEventAttributes)2 ChildWorkflowExecutionCompletedEventAttributes (com.uber.cadence.ChildWorkflowExecutionCompletedEventAttributes)2 ChildWorkflowExecutionFailedCause (com.uber.cadence.ChildWorkflowExecutionFailedCause)2