Search in sources :

Example 1 with StickyExecutionAttributes

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

the class ReplayDeciderTaskHandlerTests method ifCacheIsEvictedAndPartialHistoryIsReceivedThenTaskFailedIsReturned.

@Test
public void ifCacheIsEvictedAndPartialHistoryIsReceivedThenTaskFailedIsReturned() throws Throwable {
    // Arrange
    DeciderCache cache = new DeciderCache(10, NoopScope.getInstance());
    StickyExecutionAttributes attributes = new StickyExecutionAttributes();
    attributes.setWorkerTaskList(createStickyTaskList("sticky"));
    DecisionTaskHandler taskHandler = new ReplayDecisionTaskHandler("domain", setUpMockWorkflowFactory(), cache, SingleWorkerOptions.newBuilder().build(), "sticky", Duration.ofSeconds(5), new TestWorkflowService(), null);
    // Act
    DecisionTaskHandler.Result result = taskHandler.handleDecisionTask(HistoryUtils.generateDecisionTaskWithPartialHistory());
    // Assert
    assertEquals(0, cache.size());
    assertNull(result.getTaskCompleted());
    assertNotNull(result.getTaskFailed());
}
Also used : StickyExecutionAttributes(com.uber.cadence.StickyExecutionAttributes) TestWorkflowService(com.uber.cadence.internal.testservice.TestWorkflowService) DecisionTaskHandler(com.uber.cadence.internal.worker.DecisionTaskHandler) Test(org.junit.Test)

Example 2 with StickyExecutionAttributes

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

the class TestWorkflowStoreImpl method save.

@Override
public long save(RequestContext ctx) throws InternalServiceError, EntityNotExistsError, BadRequestError {
    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(), "TestWorkflowStoreImpl save");
        ctx.fireCallbacks(history.getEventsLocked().size());
    } finally {
        if (historiesEmpty && !histories.isEmpty()) {
            timerService.unlockTimeSkipping(// Initially locked in the constructor
            "TestWorkflowStoreImpl save");
        }
        lock.unlock();
    }
    // Push tasks to the queues out of locks
    DecisionTask decisionTask = ctx.getDecisionTask();
    if (decisionTask != null) {
        StickyExecutionAttributes attributes = ctx.getWorkflowMutableState().getStickyExecutionAttributes();
        TaskListId id = new TaskListId(decisionTask.getTaskListId().getDomain(), attributes == null ? decisionTask.getTaskListId().getTaskListName() : attributes.getWorkerTaskList().getName());
        BlockingQueue<PollForDecisionTaskResponse> decisionsQueue = getDecisionTaskListQueue(id);
        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(), t.getTaskInfo());
        }
    }
    return result;
}
Also used : StickyExecutionAttributes(com.uber.cadence.StickyExecutionAttributes) PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) HistoryEvent(com.uber.cadence.HistoryEvent) Timer(com.uber.cadence.internal.testservice.RequestContext.Timer) PollForActivityTaskResponse(com.uber.cadence.PollForActivityTaskResponse)

Example 3 with StickyExecutionAttributes

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

the class ReplayDeciderTaskHandlerTests method ifStickyExecutionAttributesAreSetThenWorkflowsAreCached.

@Test
public void ifStickyExecutionAttributesAreSetThenWorkflowsAreCached() throws Throwable {
    // Arrange
    DeciderCache cache = new DeciderCache(10, NoopScope.getInstance());
    DecisionTaskHandler taskHandler = new ReplayDecisionTaskHandler("domain", setUpMockWorkflowFactory(), cache, SingleWorkerOptions.newBuilder().build(), "sticky", Duration.ofSeconds(5), new TestWorkflowService(), null);
    PollForDecisionTaskResponse decisionTask = HistoryUtils.generateDecisionTaskWithInitialHistory();
    // Act
    DecisionTaskHandler.Result result = taskHandler.handleDecisionTask(decisionTask);
    // Assert
    assertEquals(1, cache.size());
    assertNotNull(result.getTaskCompleted());
    StickyExecutionAttributes attributes = result.getTaskCompleted().getStickyAttributes();
    assertEquals("sticky", attributes.getWorkerTaskList().name);
    assertEquals(5, attributes.getScheduleToStartTimeoutSeconds());
}
Also used : StickyExecutionAttributes(com.uber.cadence.StickyExecutionAttributes) TestWorkflowService(com.uber.cadence.internal.testservice.TestWorkflowService) DecisionTaskHandler(com.uber.cadence.internal.worker.DecisionTaskHandler) PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) Test(org.junit.Test)

Example 4 with StickyExecutionAttributes

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

the class ReplayDecisionTaskHandler method createCompletedRequest.

private Result createCompletedRequest(PollForDecisionTaskResponse decisionTask, Decider.DecisionResult result) {
    RespondDecisionTaskCompletedRequest completedRequest = new RespondDecisionTaskCompletedRequest();
    completedRequest.setTaskToken(decisionTask.getTaskToken());
    completedRequest.setDecisions(result.getDecisions());
    completedRequest.setQueryResults(result.getQueryResults());
    completedRequest.setForceCreateNewDecisionTask(result.getForceCreateNewDecisionTask());
    if (stickyTaskListName != null) {
        StickyExecutionAttributes attributes = new StickyExecutionAttributes();
        attributes.setWorkerTaskList(createStickyTaskList(stickyTaskListName));
        attributes.setScheduleToStartTimeoutSeconds((int) stickyTaskListScheduleToStartTimeout.getSeconds());
        completedRequest.setStickyAttributes(attributes);
    }
    return new Result(completedRequest, null, null);
}
Also used : StickyExecutionAttributes(com.uber.cadence.StickyExecutionAttributes) RespondDecisionTaskCompletedRequest(com.uber.cadence.RespondDecisionTaskCompletedRequest)

Aggregations

StickyExecutionAttributes (com.uber.cadence.StickyExecutionAttributes)4 PollForDecisionTaskResponse (com.uber.cadence.PollForDecisionTaskResponse)2 TestWorkflowService (com.uber.cadence.internal.testservice.TestWorkflowService)2 DecisionTaskHandler (com.uber.cadence.internal.worker.DecisionTaskHandler)2 Test (org.junit.Test)2 HistoryEvent (com.uber.cadence.HistoryEvent)1 PollForActivityTaskResponse (com.uber.cadence.PollForActivityTaskResponse)1 RespondDecisionTaskCompletedRequest (com.uber.cadence.RespondDecisionTaskCompletedRequest)1 Timer (com.uber.cadence.internal.testservice.RequestContext.Timer)1