WorkFlowExecutionController { @Transactional @SelectDataSource(type = DataSourceType.READ_WRITE, storage = Storage.SHARDED) public void updateTaskStatus(String machineId, Long stateId, ExecutionUpdateData executionUpdateData) { com.flipkart.flux.domain.Status updateStatus = null; switch (executionUpdateData.getStatus()) { case initialized: updateStatus = com.flipkart.flux.domain.Status.initialized; break; case running: updateStatus = com.flipkart.flux.domain.Status.running; break; case completed: updateStatus = com.flipkart.flux.domain.Status.completed; break; case cancelled: updateStatus = com.flipkart.flux.domain.Status.cancelled; break; case errored: updateStatus = com.flipkart.flux.domain.Status.errored; break; case sidelined: updateStatus = com.flipkart.flux.domain.Status.sidelined; break; } metricsClient.markMeter(new StringBuilder(). append("stateMachine."). append(executionUpdateData.getStateMachineName()). append(".task."). append(executionUpdateData.getTaskName()). append(".status."). append(updateStatus.name()). toString()); updateExecutionStatus(machineId, stateId, updateStatus, executionUpdateData.getRetrycount(), executionUpdateData.getCurrentRetryCount(), executionUpdateData.getErrorMessage(), executionUpdateData.isDeleteFromRedriver()); } @Inject  WorkFlowExecutionController(EventsDAO eventsDAO, StateMachinesDAO stateMachinesDAO,
                                       StatesDAO statesDAO, AuditDAO auditDAO, ExecutionNodeTaskDispatcher executionNodeTaskDispatcher,
                                       RedriverRegistry redriverRegistry, MetricsClient metricsClient,
                                       ClientElbPersistenceService clientElbPersistenceService); Set<State> initAndStart(StateMachine stateMachine); void updateTaskStatusAndPostEvent(StateMachine stateMachine, EventAndExecutionData eventAndExecutionData); void updateTaskStatusAndHandlePathCancellation(String stateMachineId, EventAndExecutionData eventAndExecutionData); void handlePathCancellation(String stateMachineId, EventData eventData); Set<State> postEvent(EventData eventData, String stateMachineInstanceId); @Transactional @SelectDataSource(type = DataSourceType.READ_WRITE, storage = Storage.SHARDED) Event persistEvent(String stateMachineInstanceId, EventData eventData); Set<State> processEvent(Event event, String stateMachineInstanceId); @Transactional @SelectDataSource(type = DataSourceType.READ_WRITE, storage = Storage.SHARDED) void updateTaskStatus(String machineId, Long stateId, ExecutionUpdateData executionUpdateData); void updateExecutionStatus(String stateMachineId, Long taskId, Status status, long retryCount, long currentRetryCount, String errorMessage, boolean deleteFromRedriver); @Transactional @SelectDataSource(type = DataSourceType.READ_WRITE, storage = Storage.SHARDED) void updateEventData(String machineId, EventData eventData); void unsidelineState(String stateMachineId, Long stateId); void incrementExecutionRetries(String stateMachineId, Long taskId); void redriveTask(String machineId, Long taskId); void cancelWorkflow(StateMachine stateMachine); static String getRouterName(String taskName);  }
@Test public void testUpdateTaskStatusBehaviourWhenTaskStatusIsUpdatedToRunning() { workFlowExecutionController.updateTaskStatus("random-state-machine", 1L, new ExecutionUpdateData("random-state-machine", "someStateMachine", "someTask", 1L, com.flipkart.flux.api.Status.running, 0, 1, "", false)); verify(statesDAO).updateStatus("random-state-machine", 1L, Status.running); verify(auditDAO).create("random-state-machine", new AuditRecord("random-state-machine", 1L, 1L, Status.running, null , "")); verifyNoMoreInteractions(redriverRegistry); }
@Test public void testUpdateTaskStatusBehaviourWhenTaskStatusIsUpdatedToCompleted() { workFlowExecutionController.updateTaskStatus("random-state-machine", 1L, new ExecutionUpdateData("random-state-machine", "someStateMachine", "someTask", 1L, com.flipkart.flux.api.Status.completed, 0, 1, "", true)); verify(statesDAO).updateStatus("random-state-machine", 1L, Status.completed); verify(auditDAO).create("random-state-machine", new AuditRecord("random-state-machine", 1L, 1L, Status.completed, null , "")); verify(redriverRegistry).deRegisterTask("random-state-machine",1L ); }