use of org.springframework.boot.context.event.ApplicationStartingEvent in project spring-boot by spring-projects.
the class LoggingApplicationListenerTests method applicationFailedEventCleansUpLoggingSystem.
@Test
public void applicationFailedEventCleansUpLoggingSystem() {
System.setProperty(LoggingSystem.SYSTEM_PROPERTY, TestCleanupLoggingSystem.class.getName());
multicastEvent(new ApplicationStartingEvent(this.springApplication, new String[0]));
TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils.getField(this.initializer, "loggingSystem");
assertThat(loggingSystem.cleanedUp).isFalse();
multicastEvent(new ApplicationFailedEvent(this.springApplication, new String[0], new GenericApplicationContext(), new Exception()));
assertThat(loggingSystem.cleanedUp).isTrue();
}
use of org.springframework.boot.context.event.ApplicationStartingEvent in project spring-boot by spring-projects.
the class LoggingApplicationListenerTests method shutdownHookIsNotRegisteredByDefault.
@Test
public void shutdownHookIsNotRegisteredByDefault() throws Exception {
TestLoggingApplicationListener listener = new TestLoggingApplicationListener();
System.setProperty(LoggingSystem.class.getName(), TestShutdownHandlerLoggingSystem.class.getName());
multicastEvent(listener, new ApplicationStartingEvent(new SpringApplication(), NO_ARGS));
listener.initialize(this.context.getEnvironment(), this.context.getClassLoader());
assertThat(listener.shutdownHook).isNull();
}
use of org.springframework.boot.context.event.ApplicationStartingEvent in project spring-boot by spring-projects.
the class LoggingApplicationListenerTests method shutdownHookCanBeRegistered.
@Test
public void shutdownHookCanBeRegistered() throws Exception {
TestLoggingApplicationListener listener = new TestLoggingApplicationListener();
System.setProperty(LoggingSystem.class.getName(), TestShutdownHandlerLoggingSystem.class.getName());
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "logging.register_shutdown_hook=true");
multicastEvent(listener, new ApplicationStartingEvent(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();
}
use of org.springframework.boot.context.event.ApplicationStartingEvent in project spring-boot by spring-projects.
the class LoggingApplicationListenerTests method closingChildContextDoesNotCleanUpLoggingSystem.
@Test
public void closingChildContextDoesNotCleanUpLoggingSystem() {
System.setProperty(LoggingSystem.SYSTEM_PROPERTY, TestCleanupLoggingSystem.class.getName());
multicastEvent(new ApplicationStartingEvent(this.springApplication, new String[0]));
TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils.getField(this.initializer, "loggingSystem");
assertThat(loggingSystem.cleanedUp).isFalse();
GenericApplicationContext childContext = new GenericApplicationContext();
childContext.setParent(this.context);
multicastEvent(new ContextClosedEvent(childContext));
assertThat(loggingSystem.cleanedUp).isFalse();
multicastEvent(new ContextClosedEvent(this.context));
assertThat(loggingSystem.cleanedUp).isTrue();
childContext.close();
}
use of org.springframework.boot.context.event.ApplicationStartingEvent in project spring-boot by spring-projects.
the class LoggingApplicationListenerIntegrationTests method loggingPerformedDuringChildApplicationStartIsNotLost.
@Test
public void loggingPerformedDuringChildApplicationStartIsNotLost() {
new SpringApplicationBuilder(Config.class).web(WebApplicationType.NONE).child(Config.class).web(WebApplicationType.NONE).listeners(new ApplicationListener<ApplicationStartingEvent>() {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Override
public void onApplicationEvent(ApplicationStartingEvent event) {
this.logger.info("Child application starting");
}
}).run();
assertThat(this.outputCapture.toString()).contains("Child application starting");
}
Aggregations