in src/main/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateImpl.java [327:395]
public void completeDecisionTask(int historySize, RespondDecisionTaskCompletedRequest request)
throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError,
BadRequestError {
List<Decision> decisions = request.getDecisions();
completeDecisionUpdate(
ctx -> {
if (request.getQueryResultsSize() > 0) {
request
.getQueryResults()
.forEach(
(queryId, queryResult) -> {
completeQuery(queryId, queryResult);
pendingQueries.remove(queryId);
});
}
if (ctx.getInitialEventId() != historySize + 1) {
throw new BadRequestError(
"Expired decision: expectedHistorySize="
+ historySize
+ ","
+ " actualHistorySize="
+ ctx.getInitialEventId());
}
long decisionTaskCompletedId = ctx.getNextEventId() - 1;
// Fail the decision if there are new events and the decision tries to complete the
// workflow
if (!concurrentToDecision.isEmpty() && hasCompleteDecision(request.getDecisions())) {
RespondDecisionTaskFailedRequest failedRequest =
new RespondDecisionTaskFailedRequest()
.setCause(DecisionTaskFailedCause.UNHANDLED_DECISION)
.setIdentity(request.getIdentity());
decision.action(Action.FAIL, ctx, failedRequest, decisionTaskCompletedId);
for (RequestContext deferredCtx : this.concurrentToDecision) {
ctx.add(deferredCtx);
}
this.concurrentToDecision.clear();
// Reset sticky execution attributes on failure
stickyExecutionAttributes = null;
scheduleDecision(ctx);
return;
}
if (decision == null) {
throw new EntityNotExistsError("No outstanding decision");
}
decision.action(StateMachines.Action.COMPLETE, ctx, request, 0);
for (Decision d : decisions) {
processDecision(ctx, d, request.getIdentity(), decisionTaskCompletedId);
}
for (RequestContext deferredCtx : this.concurrentToDecision) {
ctx.add(deferredCtx);
}
lastNonFailedDecisionStartEventId = this.decision.getData().startedEventId;
this.decision = null;
boolean completed =
workflow.getState() == StateMachines.State.COMPLETED
|| workflow.getState() == StateMachines.State.FAILED
|| workflow.getState() == StateMachines.State.CANCELED;
if (!completed
&& ((ctx.isNeedDecision() || !this.concurrentToDecision.isEmpty())
|| request.isForceCreateNewDecisionTask())) {
scheduleDecision(ctx);
}
this.concurrentToDecision.clear();
ctx.unlockTimer();
},
request.getStickyAttributes());
}