ShutdownHook implements Runnable { long shutdownTimeoutInMs(Map<String, String> env) { String shutdownTimeout = env.get("SHUTDOWN_TIMEOUT_IN_SEC"); if (shutdownTimeout != null) { long timeout = Long.parseLong(shutdownTimeout) * 1000; if (timeout <= 0) throw new Error("shutdown timeout must be greater than 0, timeout=" + shutdownTimeout); return timeout; } return 25000; } 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 shutdownTimeoutInMs() { assertThat(shutdownHook.shutdownTimeoutInMs(Map.of())).isEqualTo(Duration.ofSeconds(25).toMillis()); assertThat(shutdownHook.shutdownTimeoutInMs(Map.of("SHUTDOWN_TIMEOUT_IN_SEC", "60"))) .isEqualTo(Duration.ofSeconds(60).toMillis()); assertThatThrownBy(() -> shutdownHook.shutdownTimeoutInMs(Map.of("SHUTDOWN_TIMEOUT_IN_SEC", "-1"))) .isInstanceOf(Error.class) .hasMessageContaining("greater than 0"); }