ShutdownHook implements Runnable { long shutdownDelayInSec(Map<String, String> env) { String shutdownDelay = env.get("SHUTDOWN_DELAY_IN_SEC"); if (shutdownDelay != null) { long delay = Long.parseLong(shutdownDelay); if (delay <= 0) throw new Error("shutdown delay must be greater than 0, delay=" + shutdownDelay); return delay; } return -1; } ShutdownHook(LogManager logManager); void add(int stage, Shutdown shutdown); @Override void run(); static final int STAGE_0; static final int STAGE_1; static final int STAGE_2; static final int STAGE_3; static final int STAGE_4; static final int STAGE_5; static final int STAGE_7; static final int STAGE_8; static final int STAGE_9; }
@Test void shutdownDelayInSec() { assertThat(shutdownHook.shutdownDelayInSec(Map.of())).isEqualTo(-1); assertThat(shutdownHook.shutdownDelayInSec(Map.of("SHUTDOWN_DELAY_IN_SEC", "10"))) .isEqualTo(10); assertThatThrownBy(() -> shutdownHook.shutdownDelayInSec(Map.of("SHUTDOWN_DELAY_IN_SEC", "-1"))) .isInstanceOf(Error.class) .hasMessageContaining("greater than 0"); }