AbstractRunnerHandler implements OutputHandler { @Override public final void transitionInto(RunState state, EventRouter eventRouter) { var stateData = state.data(); var workflowInstance = state.workflowInstance(); var maybeExecutionId = stateData.executionId(); var maybeExecutionDescription = stateData.executionDescription(); switch (state.state()) { case SUBMITTING: case SUBMITTED: case RUNNING: if (maybeExecutionId.isEmpty()) { LOG.error("Unable to start procedure. Missing execution id for " + workflowInstance); eventRouter.receiveIgnoreClosed(Event.halt(workflowInstance), state.counter()); return; } if (maybeExecutionDescription.isEmpty()) { LOG.error("Unable to start procedure. Missing execution description for " + workflowInstance); eventRouter.receiveIgnoreClosed(Event.halt(workflowInstance), state.counter()); return; } if(!applicableFn.test(maybeExecutionDescription.orElseThrow())) { return; } safeTransitionInto(state, eventRouter); break; case FAILED: if (maybeExecutionId.isEmpty() || maybeExecutionDescription.isEmpty() || !applicableFn.test(maybeExecutionDescription.orElseThrow())) { return; } safeTransitionInto(state, eventRouter); break; default: } } protected  AbstractRunnerHandler(Predicate<ExecutionDescription> applicableFn); @Override final void transitionInto(RunState state, EventRouter eventRouter);  }
@Test @Parameters(method = "relevantRunnerHandlerStates") public void shouldCallSafeTransitionForValidState(RunState.State state) { var runState = runState(state, VALID_STATE_DATA); handler.transitionInto(runState, router); verifyNoInteractions(router); assertTrue(handler.reached); }
@Test @Parameters(method = "execRunnerHandlerStates") public void shouldRejectStateWithNoExecutionId(RunState.State state) { var runState = runState(state, NO_EXEC_ID_STATE_DATA); handler.transitionInto(runState, router); verify(router).receiveIgnoreClosed(Event.halt(WORKFLOW_INSTANCE), runState.counter()); assertFalse(handler.reached); }
@Test @Parameters(method = "execRunnerHandlerStates") public void shouldRejectStateWithNoExecutionDescription(RunState.State state) { var runState = runState(state, NO_EXEC_DESC_STATE_DATA); handler.transitionInto(runState, router); verify(router).receiveIgnoreClosed(Event.halt(WORKFLOW_INSTANCE), runState.counter()); assertFalse(handler.reached); }
@Test @Parameters(method = "relevantRunnerHandlerStates") public void shouldSkipNonApplicableStateWithExecutionIdAndExecutionDescription(RunState.State state) { var nonApplicableHandler = new TestRunnerHandler(false); var runState = runState(state, VALID_STATE_DATA); nonApplicableHandler.transitionInto(runState, router); verifyNoInteractions(router); assertFalse(nonApplicableHandler.reached); }
@Test @Parameters(method = "irrelevantRunnerHandlerStates") public void shouldCallSafeTransitionForIrrelevantState(RunState.State state) { var runState = runState(state, VALID_STATE_DATA); handler.transitionInto(runState, router); verifyNoInteractions(router); assertFalse(handler.reached); }