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());
}
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;
}
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());
}
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);
}
Aggregations