TransitionLogger implements EventConsumer { @VisibleForTesting static String stateInfo(RunState state) { switch (state.state()) { case NEW: case PREPARE: case ERROR: case DONE: return format("tries:%d", state.data().tries()); case SUBMITTED: case RUNNING: case FAILED: return format("tries:%d execId:%s", state.data().tries(), state.data().executionId()); case TERMINATED: return format("tries:%d execId:%s exitCode:%s", state.data().tries(), state.data().executionId(), state.data().lastExit().map( String::valueOf).orElse("-")); case QUEUED: return format("tries:%d delayMs:%s", state.data().tries(), state.data().retryDelayMillis()); default: return ""; } } TransitionLogger();   TransitionLogger(Logger log); @Override void accept(SequenceEvent sequenceEvent, RunState state);  }
@Test public void shouldReturnTries() { assertThat(stateInfo(RunState.fresh(WORKFLOW_INSTANCE)), is("tries:0")); assertThat(stateInfo(RunState.create(WORKFLOW_INSTANCE, PREPARE)), is("tries:0")); assertThat(stateInfo(RunState.create(WORKFLOW_INSTANCE, ERROR)), is("tries:0")); assertThat(stateInfo(RunState.create(WORKFLOW_INSTANCE, DONE)), is("tries:0")); }
@Test public void shouldReturnTriesAndExecId() { final StateData stateData = StateData.newBuilder().executionId("exec-1").build(); assertThat(stateInfo(RunState.create(WORKFLOW_INSTANCE, SUBMITTED, stateData)), is(format("tries:0 execId:%s", stateData.executionId()))); assertThat(stateInfo(RunState.create(WORKFLOW_INSTANCE, RUNNING, stateData)), is(format("tries:0 execId:%s", stateData.executionId()))); assertThat(stateInfo(RunState.create(WORKFLOW_INSTANCE, FAILED, stateData)), is(format("tries:0 execId:%s", stateData.executionId()))); }
@Test public void shouldReturnTriesExecIdAndExitCode() { final StateData stateData = StateData.newBuilder().executionId("exec-1").build(); assertThat(stateInfo(RunState.create(WORKFLOW_INSTANCE, TERMINATED, stateData)), is(format("tries:0 execId:%s exitCode:-", stateData.executionId()))); assertThat(stateInfo( RunState.create(WORKFLOW_INSTANCE, TERMINATED, stateData.builder().lastExit(10).build())), is(format("tries:0 execId:%s exitCode:10", stateData.executionId()))); }
@Test public void shouldReturnTriesAndDelayMs() { final StateData stateData = StateData.newBuilder().executionId("exec-1").retryDelayMillis(1000L).build(); assertThat(stateInfo( RunState.create(WORKFLOW_INSTANCE, QUEUED, stateData)), is(format("tries:0 delayMs:%s", stateData.retryDelayMillis()))); }
@Test public void shouldReturnEmptyString() { assertThat(stateInfo(RunState.create(WORKFLOW_INSTANCE, SUBMITTING)), is("")); }