Search in sources :

Example 21 with HistoryEvent

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

the class StateMachines method startChildWorkflowFailed.

private static void startChildWorkflowFailed(RequestContext ctx, ChildWorkflowData data, StartChildWorkflowExecutionFailedEventAttributes a, long notUsed) {
    HistoryEvent event = new HistoryEvent().setEventType(EventType.StartChildWorkflowExecutionFailed).setStartChildWorkflowExecutionFailedEventAttributes(a);
    ctx.addEvent(event);
}
Also used : HistoryEvent(com.uber.cadence.HistoryEvent)

Example 22 with HistoryEvent

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

the class TestWorkflowMutableStateImpl method addExecutionSignaledByExternalEvent.

private void addExecutionSignaledByExternalEvent(RequestContext ctx, SignalExternalWorkflowExecutionDecisionAttributes d) {
    WorkflowExecutionSignaledEventAttributes a = new WorkflowExecutionSignaledEventAttributes().setInput(startRequest.getInput()).setInput(d.getInput()).setSignalName(d.getSignalName());
    HistoryEvent executionSignaled = new HistoryEvent().setEventType(EventType.WorkflowExecutionSignaled).setWorkflowExecutionSignaledEventAttributes(a);
    ctx.addEvent(executionSignaled);
}
Also used : WorkflowExecutionSignaledEventAttributes(com.uber.cadence.WorkflowExecutionSignaledEventAttributes) HistoryEvent(com.uber.cadence.HistoryEvent)

Example 23 with HistoryEvent

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

the class TestWorkflowMutableStateImpl method addExecutionSignaledEvent.

private void addExecutionSignaledEvent(RequestContext ctx, SignalWorkflowExecutionRequest signalRequest) {
    WorkflowExecutionSignaledEventAttributes a = new WorkflowExecutionSignaledEventAttributes().setInput(startRequest.getInput()).setIdentity(signalRequest.getIdentity()).setInput(signalRequest.getInput()).setSignalName(signalRequest.getSignalName());
    HistoryEvent executionSignaled = new HistoryEvent().setEventType(EventType.WorkflowExecutionSignaled).setWorkflowExecutionSignaledEventAttributes(a);
    ctx.addEvent(executionSignaled);
}
Also used : WorkflowExecutionSignaledEventAttributes(com.uber.cadence.WorkflowExecutionSignaledEventAttributes) HistoryEvent(com.uber.cadence.HistoryEvent)

Example 24 with HistoryEvent

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

the class TestWorkflowStoreImpl method save.

@Override
public long save(RequestContext ctx) throws InternalServiceError, EntityNotExistsError {
    long result;
    lock.lock();
    boolean historiesEmpty = histories.isEmpty();
    try {
        ExecutionId executionId = ctx.getExecutionId();
        HistoryStore history = histories.get(executionId);
        List<HistoryEvent> events = ctx.getEvents();
        if (history == null) {
            if (events.isEmpty() || events.get(0).getEventType() != EventType.WorkflowExecutionStarted) {
                throw new IllegalStateException("No history found for " + executionId);
            }
            history = new HistoryStore(executionId, lock);
            histories.put(executionId, history);
        }
        history.checkNextEventId(ctx.getInitialEventId());
        history.addAllLocked(events, ctx.currentTimeInNanoseconds());
        result = history.getNextEventIdLocked();
        timerService.updateLocks(ctx.getTimerLocks());
        ctx.fireCallbacks(history.getEventsLocked().size());
    } finally {
        if (historiesEmpty && !histories.isEmpty()) {
            // Initially locked in the constructor
            timerService.unlockTimeSkipping();
        }
        lock.unlock();
    }
    // Push tasks to the queues out of locks
    DecisionTask decisionTask = ctx.getDecisionTask();
    if (decisionTask != null) {
        BlockingQueue<PollForDecisionTaskResponse> decisionsQueue = getDecisionTaskListQueue(decisionTask.getTaskListId());
        decisionsQueue.add(decisionTask.getTask());
    }
    List<ActivityTask> activityTasks = ctx.getActivityTasks();
    if (activityTasks != null) {
        for (ActivityTask activityTask : activityTasks) {
            BlockingQueue<PollForActivityTaskResponse> activitiesQueue = getActivityTaskListQueue(activityTask.getTaskListId());
            activitiesQueue.add(activityTask.getTask());
        }
    }
    List<Timer> timers = ctx.getTimers();
    if (timers != null) {
        for (Timer t : timers) {
            timerService.schedule(Duration.ofSeconds(t.getDelaySeconds()), t.getCallback());
        }
    }
    return result;
}
Also used : PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) HistoryEvent(com.uber.cadence.HistoryEvent) Timer(com.uber.cadence.internal.testservice.RequestContext.Timer) PollForActivityTaskResponse(com.uber.cadence.PollForActivityTaskResponse)

Example 25 with HistoryEvent

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

Aggregations

HistoryEvent (com.uber.cadence.HistoryEvent)49 History (com.uber.cadence.History)5 WorkflowExecution (com.uber.cadence.WorkflowExecution)5 GetWorkflowExecutionHistoryRequest (com.uber.cadence.GetWorkflowExecutionHistoryRequest)4 GetWorkflowExecutionHistoryResponse (com.uber.cadence.GetWorkflowExecutionHistoryResponse)3 SignalExternalWorkflowExecutionInitiatedEventAttributes (com.uber.cadence.SignalExternalWorkflowExecutionInitiatedEventAttributes)3 ActivityTaskCompletedEventAttributes (com.uber.cadence.ActivityTaskCompletedEventAttributes)2 ActivityTaskFailedEventAttributes (com.uber.cadence.ActivityTaskFailedEventAttributes)2 ChildWorkflowExecutionTimedOutEventAttributes (com.uber.cadence.ChildWorkflowExecutionTimedOutEventAttributes)2 EntityNotExistsError (com.uber.cadence.EntityNotExistsError)2 PollForActivityTaskResponse (com.uber.cadence.PollForActivityTaskResponse)2 PollForDecisionTaskResponse (com.uber.cadence.PollForDecisionTaskResponse)2 SignalExternalWorkflowExecutionFailedEventAttributes (com.uber.cadence.SignalExternalWorkflowExecutionFailedEventAttributes)2 StartChildWorkflowExecutionInitiatedEventAttributes (com.uber.cadence.StartChildWorkflowExecutionInitiatedEventAttributes)2 StartWorkflowExecutionRequest (com.uber.cadence.StartWorkflowExecutionRequest)2 WorkflowExecutionContinuedAsNewEventAttributes (com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes)2 WorkflowExecutionSignaledEventAttributes (com.uber.cadence.WorkflowExecutionSignaledEventAttributes)2 WorkflowExecutionStartedEventAttributes (com.uber.cadence.WorkflowExecutionStartedEventAttributes)2 TaskListId (com.uber.cadence.internal.testservice.TestWorkflowStore.TaskListId)2 ArrayList (java.util.ArrayList)2