@Test public void shutdownHookIsNotRegisteredByDefault() throws Exception { TestLoggingApplicationListener listener = new TestLoggingApplicationListener(); System.setProperty( LoggingSystem.class.getName(), TestShutdownHandlerLoggingSystem.class.getName()); listener.onApplicationEvent(new ApplicationStartedEvent(new SpringApplication(), NO_ARGS)); listener.initialize(this.context.getEnvironment(), this.context.getClassLoader()); assertThat(listener.shutdownHook).isNull(); }
@Test public void shutdownHookCanBeRegistered() throws Exception { TestLoggingApplicationListener listener = new TestLoggingApplicationListener(); System.setProperty( LoggingSystem.class.getName(), TestShutdownHandlerLoggingSystem.class.getName()); EnvironmentTestUtils.addEnvironment(this.context, "logging.register_shutdown_hook:true"); listener.onApplicationEvent(new ApplicationStartedEvent(new SpringApplication(), NO_ARGS)); listener.initialize(this.context.getEnvironment(), this.context.getClassLoader()); assertThat(listener.shutdownHook).isNotNull(); listener.shutdownHook.start(); assertThat(TestShutdownHandlerLoggingSystem.shutdownLatch.await(30, TimeUnit.SECONDS)).isTrue(); }