@Test @RunWithCustomExecutor public void test_onUpdate_when_ProcessWorkflowStatusIsFATAL() { VitamThreadUtils.getVitamSession().setTenantId(1); final ProcessEngine processEngine = mock(ProcessEngine.class); final ProcessWorkflow processWorkflow = processDataAccess.initProcessWorkflow( ProcessPopulator.populate(WORKFLOW_FILE).get(), workParams.getContainerName() ); processWorkflow.setStatus(StatusCode.FATAL); processWorkflow.getSteps().get(0).setStepStatusCode(StatusCode.OK); processWorkflow.getSteps().get(0).setPauseOrCancelAction(PauseOrCancelAction.ACTION_COMPLETE); processWorkflow.getSteps().get(1).setStepStatusCode(StatusCode.FATAL); StateMachine stateMachine = StateMachineFactory.get() .create(processWorkflow, processEngine, dataManagement, workspaceClientFactory, logbookOperationsClientFactory); processEngine.setStateMachineCallback(stateMachine); stateMachine.onUpdate(StatusCode.OK); Assertions.assertThat(processWorkflow.getStatus()).isEqualTo(StatusCode.OK); stateMachine.onUpdate(StatusCode.FATAL); Assertions.assertThat(processWorkflow.getStatus()).isEqualTo(StatusCode.FATAL); stateMachine.onUpdate(StatusCode.WARNING); Assertions.assertThat(processWorkflow.getStatus()).isEqualTo(StatusCode.WARNING); stateMachine.onUpdate(StatusCode.KO); Assertions.assertThat(processWorkflow.getStatus()).isEqualTo(StatusCode.KO); stateMachine.onUpdate(StatusCode.OK); Assertions.assertThat(processWorkflow.getStatus()).isEqualTo(StatusCode.KO); }
@Override synchronized public void onUpdate(StatusCode statusCode) { StatusCode stepStatusCode = currentStep.getStepStatusCode(); boolean replayAfterFatal = StatusCode.FATAL.equals(this.processWorkflow.getStatus()); stepStatusCode = (stepStatusCode.compareTo(statusCode) < 0 || replayAfterFatal) ? statusCode : stepStatusCode; currentStep.setStepStatusCode(stepStatusCode); if (replayAfterFatal) { recomputeProcessWorkflowStatus(statusCode); } else if (this.processWorkflow.getStatus().compareTo(statusCode) < 0) { this.processWorkflow.setStatus(statusCode); } if (!this.tryPersistProcessWorkflow() && StatusCode.STARTED.equals(statusCode)) { throw new VitamRuntimeException( "Operation:" + processWorkflow.getOperationId() + ", stepIndex : " + stepIndex + ", stepIndexName: " + currentStep.getStepName() + ", Cannot continue with unreachable workspace ..."); } }
StateMachine implements IEventsState, IEventsProcessEngine { @Override synchronized public void onUpdate(StatusCode statusCode) { StatusCode stepStatusCode = currentStep.getStepStatusCode(); boolean replayAfterFatal = StatusCode.FATAL.equals(this.processWorkflow.getStatus()); stepStatusCode = (stepStatusCode.compareTo(statusCode) < 0 || replayAfterFatal) ? statusCode : stepStatusCode; currentStep.setStepStatusCode(stepStatusCode); if (replayAfterFatal) { recomputeProcessWorkflowStatus(statusCode); } else if (this.processWorkflow.getStatus().compareTo(statusCode) < 0) { this.processWorkflow.setStatus(statusCode); } if (!this.tryPersistProcessWorkflow() && StatusCode.STARTED.equals(statusCode)) { throw new VitamRuntimeException( "Operation:" + processWorkflow.getOperationId() + ", stepIndex : " + stepIndex + ", stepIndexName: " + currentStep.getStepName() + ", Cannot continue with unreachable workspace ..."); } } }
StateMachine implements IEventsState, IEventsProcessEngine { @Override synchronized public void onUpdate(StatusCode statusCode) { StatusCode stepStatusCode = currentStep.getStepStatusCode(); boolean replayAfterFatal = StatusCode.FATAL.equals(this.processWorkflow.getStatus()); stepStatusCode = (stepStatusCode.compareTo(statusCode) < 0 || replayAfterFatal) ? statusCode : stepStatusCode; currentStep.setStepStatusCode(stepStatusCode); if (replayAfterFatal) { recomputeProcessWorkflowStatus(statusCode); } else if (this.processWorkflow.getStatus().compareTo(statusCode) < 0) { this.processWorkflow.setStatus(statusCode); } if (!this.tryPersistProcessWorkflow() && StatusCode.STARTED.equals(statusCode)) { throw new VitamRuntimeException( "Operation:" + processWorkflow.getOperationId() + ", stepIndex : " + stepIndex + ", stepIndexName: " + currentStep.getStepName() + ", Cannot continue with unreachable workspace ..."); } } StateMachine(ProcessWorkflow processWorkflow, ProcessEngine processEngine); @VisibleForTesting  StateMachine(ProcessWorkflow processWorkflow, ProcessEngine processEngine,
        ProcessDataManagement dataManagement,
        WorkspaceClientFactory workspaceClientFactory, LogbookOperationsClientFactory logbookOperationsClientFactory); }
StateMachine implements IEventsState, IEventsProcessEngine { @Override synchronized public void onUpdate(StatusCode statusCode) { StatusCode stepStatusCode = currentStep.getStepStatusCode(); boolean replayAfterFatal = StatusCode.FATAL.equals(this.processWorkflow.getStatus()); stepStatusCode = (stepStatusCode.compareTo(statusCode) < 0 || replayAfterFatal) ? statusCode : stepStatusCode; currentStep.setStepStatusCode(stepStatusCode); if (replayAfterFatal) { recomputeProcessWorkflowStatus(statusCode); } else if (this.processWorkflow.getStatus().compareTo(statusCode) < 0) { this.processWorkflow.setStatus(statusCode); } if (!this.tryPersistProcessWorkflow() && StatusCode.STARTED.equals(statusCode)) { throw new VitamRuntimeException( "Operation:" + processWorkflow.getOperationId() + ", stepIndex : " + stepIndex + ", stepIndexName: " + currentStep.getStepName() + ", Cannot continue with unreachable workspace ..."); } } StateMachine(ProcessWorkflow processWorkflow, ProcessEngine processEngine); @VisibleForTesting  StateMachine(ProcessWorkflow processWorkflow, ProcessEngine processEngine,
        ProcessDataManagement dataManagement,
        WorkspaceClientFactory workspaceClientFactory, LogbookOperationsClientFactory logbookOperationsClientFactory); @Override synchronized void resume(WorkerParameters workerParameters); @Override synchronized void next(WorkerParameters workerParameters); @Override synchronized void replay(WorkerParameters workerParameters); @Override synchronized void pause(); @Override void shutdown(); @Override synchronized void cancel(); @Override boolean isDone(); @Override int getTenant(); @Override String getWorkflowId(); @Override String getContextId(); @Override Map<String, String> getWorkflowParameters(); @Override boolean isStepByStep(); @Override LogbookTypeProcess getLogbookTypeProcess(); @Override synchronized void onUpdate(StatusCode statusCode); @Override StatusCode getCurrentProcessWorkflowStatus(); @Override synchronized void onUpdate(String messageIdentifier, String originatingAgency); @Override synchronized void onError(Throwable throwable); @Override synchronized void onProcessEngineCancel(WorkerParameters workerParameters); @Override synchronized void onProcessEngineCompleteStep(ItemStatus itemStatus, WorkerParameters workerParameters); boolean isCompleted(); @Override boolean isRecover(); }
StateMachine implements IEventsState, IEventsProcessEngine { @Override synchronized public void onUpdate(StatusCode statusCode) { StatusCode stepStatusCode = currentStep.getStepStatusCode(); boolean replayAfterFatal = StatusCode.FATAL.equals(this.processWorkflow.getStatus()); stepStatusCode = (stepStatusCode.compareTo(statusCode) < 0 || replayAfterFatal) ? statusCode : stepStatusCode; currentStep.setStepStatusCode(stepStatusCode); if (replayAfterFatal) { recomputeProcessWorkflowStatus(statusCode); } else if (this.processWorkflow.getStatus().compareTo(statusCode) < 0) { this.processWorkflow.setStatus(statusCode); } if (!this.tryPersistProcessWorkflow() && StatusCode.STARTED.equals(statusCode)) { throw new VitamRuntimeException( "Operation:" + processWorkflow.getOperationId() + ", stepIndex : " + stepIndex + ", stepIndexName: " + currentStep.getStepName() + ", Cannot continue with unreachable workspace ..."); } } StateMachine(ProcessWorkflow processWorkflow, ProcessEngine processEngine); @VisibleForTesting  StateMachine(ProcessWorkflow processWorkflow, ProcessEngine processEngine,
        ProcessDataManagement dataManagement,
        WorkspaceClientFactory workspaceClientFactory, LogbookOperationsClientFactory logbookOperationsClientFactory); @Override synchronized void resume(WorkerParameters workerParameters); @Override synchronized void next(WorkerParameters workerParameters); @Override synchronized void replay(WorkerParameters workerParameters); @Override synchronized void pause(); @Override void shutdown(); @Override synchronized void cancel(); @Override boolean isDone(); @Override int getTenant(); @Override String getWorkflowId(); @Override String getContextId(); @Override Map<String, String> getWorkflowParameters(); @Override boolean isStepByStep(); @Override LogbookTypeProcess getLogbookTypeProcess(); @Override synchronized void onUpdate(StatusCode statusCode); @Override StatusCode getCurrentProcessWorkflowStatus(); @Override synchronized void onUpdate(String messageIdentifier, String originatingAgency); @Override synchronized void onError(Throwable throwable); @Override synchronized void onProcessEngineCancel(WorkerParameters workerParameters); @Override synchronized void onProcessEngineCompleteStep(ItemStatus itemStatus, WorkerParameters workerParameters); boolean isCompleted(); @Override boolean isRecover();  }