@Test @RunWithCustomExecutor public void testWhenStepKOBlockingThenExecuteFinallyStep() throws ProcessingException, StateNotAllowedException, InterruptedException { VitamThreadUtils.getVitamSession().setTenantId(1); final ProcessWorkflow processWorkflow = processDataAccess.initProcessWorkflow( ProcessPopulator.populate(WORKFLOW_FINALLY_STEP_FILE).get(), workParams.getContainerName() ); workParams.setLogbookTypeProcess(LogbookTypeProcess.INGEST); final ProcessDistributor distributorMock = mock(ProcessDistributorImpl.class); final ProcessEngineImpl processEngine = ProcessEngineFactory.get().create(workParams, distributorMock); StateMachine stateMachine = StateMachineFactory.get() .create(processWorkflow, processEngine, dataManagement, workspaceClientFactory, logbookOperationsClientFactory); processEngine.setStateMachineCallback(stateMachine); final ProcessStep firstStep = processWorkflow.getSteps().get(0); final ProcessStep lastStep = processWorkflow.getSteps().get(1); when(distributorMock.distribute(workParams, firstStep, workParams.getContainerName(), PauseRecover.NO_RECOVER)) .thenReturn(new ItemStatus(firstStep.getStepName()).increment(StatusCode.KO)); when(distributorMock.distribute(workParams, lastStep, workParams.getContainerName(), PauseRecover.NO_RECOVER)) .thenReturn(new ItemStatus(lastStep.getStepName()).increment(StatusCode.OK)); stateMachine.resume(workParams); int nbtry = 50; while (!ProcessState.COMPLETED.equals(processWorkflow.getState())) { Thread.sleep(20); nbtry--; if (nbtry < 0) break; } assertEquals(ProcessState.COMPLETED, processWorkflow.getState()); assertEquals(StatusCode.KO, processWorkflow.getStatus()); assertEquals(StatusCode.KO, firstStep.getStepStatusCode()); assertEquals(StatusCode.OK, lastStep.getStepStatusCode()); processDataAccess.clearWorkflow(); }
@Override synchronized public void resume(WorkerParameters workerParameters) throws StateNotAllowedException, ProcessingException { this.processWorkflow.getState().eval(ProcessState.RUNNING); this.doRunning(workerParameters, ProcessState.RUNNING); }
StateMachine implements IEventsState, IEventsProcessEngine { @Override synchronized public void resume(WorkerParameters workerParameters) throws StateNotAllowedException, ProcessingException { this.processWorkflow.getState().eval(ProcessState.RUNNING); this.doRunning(workerParameters, ProcessState.RUNNING); } }
StateMachine implements IEventsState, IEventsProcessEngine { @Override synchronized public void resume(WorkerParameters workerParameters) throws StateNotAllowedException, ProcessingException { this.processWorkflow.getState().eval(ProcessState.RUNNING); this.doRunning(workerParameters, ProcessState.RUNNING); } 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 resume(WorkerParameters workerParameters) throws StateNotAllowedException, ProcessingException { this.processWorkflow.getState().eval(ProcessState.RUNNING); this.doRunning(workerParameters, ProcessState.RUNNING); } 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 resume(WorkerParameters workerParameters) throws StateNotAllowedException, ProcessingException { this.processWorkflow.getState().eval(ProcessState.RUNNING); this.doRunning(workerParameters, ProcessState.RUNNING); } 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();  }