TimeoutHandler implements OutputHandler { @Override public void transitionInto(RunState runState, EventRouter eventRouter) { var workflow = Optional.ofNullable(workflows.get().get(runState.workflowInstance().workflowId())); if (hasTimedOut(workflow, runState, time.get(), ttls.ttlOf(runState.state()))) { sendTimeout(runState.workflowInstance(), runState, eventRouter); } } TimeoutHandler(TimeoutConfig ttls, Time time,
                        Supplier<Map<WorkflowId, Workflow>> workflows); @Override void transitionInto(RunState runState, EventRouter eventRouter);  }
@Parameters(source = State.class) @Test public void shouldTimeoutActiveState(State state) { assumeFalse(state.isTerminal()); setUpWithTimeoutSeconds(5); var runState = RunState.create(WORKFLOW_INSTANCE, state, now, counter); now = now.plus(5, ChronoUnit.SECONDS); timeoutHandler.transitionInto(runState, eventRouter); verify(eventRouter).receiveIgnoreClosed(Event.timeout(WORKFLOW_INSTANCE), counter); }
@Parameters(source = State.class) @Test public void shouldNotTimeoutTerminalState(State state) { assumeTrue(state.isTerminal()); setUpWithTimeoutSeconds(0); now = now.plus(5, ChronoUnit.SECONDS); var runState = RunState.create(WORKFLOW_INSTANCE, state, now, counter); timeoutHandler.transitionInto(runState, eventRouter); verify(eventRouter, never()).receiveIgnoreClosed(any()); }
@Parameters(source = State.class) @Test public void shouldNotTransitionIfNotTimedOut(State state) { setUpWithTimeoutSeconds(20); var runState = RunState.create(WORKFLOW_INSTANCE, State.RUNNING, now, counter); timeoutHandler.transitionInto(runState, eventRouter); verify(eventRouter, never()).receiveIgnoreClosed(any()); }