ShutdownHook implements Runnable { void logContext(ActionLog actionLog) { actionLog.action("app:stop"); actionLog.context("start_time", Instant.ofEpochMilli(ManagementFactory.getRuntimeMXBean().getStartTime())); actionLog.stats.put("uptime", ManagementFactory.getRuntimeMXBean().getUptime() * 1_000_000d); } 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 logContext() { var actionLog = new ActionLog(null, null); shutdownHook.logContext(actionLog); assertThat(actionLog.action).isEqualTo("app:stop"); assertThat(actionLog.context).containsKey("start_time"); assertThat(actionLog.stats).containsKey("uptime"); }