use of org.springframework.boot.context.event.ApplicationFailedEvent in project spring-boot by spring-projects.
the class AutoConfigurationReportLoggingInitializerTests method logsInfoOnErrorIfDebugDisabled.
@Test
public void logsInfoOnErrorIfDebugDisabled() {
setupLogging(false, true);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
this.initializer.initialize(context);
context.register(ErrorConfig.class);
try {
context.refresh();
fail("Did not error");
} catch (Exception ex) {
this.initializer.onApplicationEvent(new ApplicationFailedEvent(new SpringApplication(), new String[0], context, ex));
}
assertThat(this.debugLog.size()).isEqualTo(0);
assertThat(this.infoLog.size()).isNotEqualTo(0);
}
use of org.springframework.boot.context.event.ApplicationFailedEvent in project spring-boot by spring-projects.
the class EndpointWebMvcAutoConfigurationTests method onDifferentPortWithPrimaryFailure.
@Test
public void onDifferentPortWithPrimaryFailure() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management);
this.applicationContext.register(RootConfig.class, EndpointConfig.class, DifferentPortConfig.class, BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
this.applicationContext.refresh();
ApplicationContext managementContext = this.applicationContext.getBean(ManagementContextResolver.class).getApplicationContext();
ApplicationFailedEvent event = mock(ApplicationFailedEvent.class);
given(event.getApplicationContext()).willReturn(this.applicationContext);
this.applicationContext.publishEvent(event);
assertThat(((ConfigurableApplicationContext) managementContext).isActive()).isFalse();
}
use of org.springframework.boot.context.event.ApplicationFailedEvent in project pinpoint by naver.
the class EnvironmentLoggingListener method onApplicationEvent.
@Override
public void onApplicationEvent(SpringApplicationEvent event) {
if (event instanceof ApplicationEnvironmentPreparedEvent) {
ApplicationEnvironmentPreparedEvent prepared = (ApplicationEnvironmentPreparedEvent) event;
ConfigurableEnvironment environment = prepared.getEnvironment();
logPropertySource(event, environment);
} else if (event instanceof ApplicationStartedEvent) {
ApplicationStartedEvent started = (ApplicationStartedEvent) event;
ConfigurableEnvironment environment = started.getApplicationContext().getEnvironment();
logPropertySource(event, environment);
} else if (event instanceof ApplicationFailedEvent) {
ApplicationFailedEvent failed = (ApplicationFailedEvent) event;
ConfigurableEnvironment environment = failed.getApplicationContext().getEnvironment();
logPropertySource(event, environment);
} else {
if (logger.isDebugEnabled()) {
logger.debug("ApplicationEvent:{}", event.getClass().getSimpleName());
}
}
}
use of org.springframework.boot.context.event.ApplicationFailedEvent in project spring-boot by spring-projects.
the class LoggingApplicationListenerTests method applicationFailedEventCleansUpLoggingSystem.
@Test
void applicationFailedEventCleansUpLoggingSystem() {
System.setProperty(LoggingSystem.SYSTEM_PROPERTY, TestCleanupLoggingSystem.class.getName());
multicastEvent(new ApplicationStartingEvent(this.bootstrapContext, 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.ApplicationFailedEvent in project spring-boot by spring-projects.
the class ConditionEvaluationReportLoggingListenerTests method noErrorIfNotInitialized.
@Test
void noErrorIfNotInitialized(CapturedOutput output) {
this.initializer.onApplicationEvent(new ApplicationFailedEvent(new SpringApplication(), new String[0], null, new RuntimeException("Planned")));
assertThat(output).contains("Unable to provide the conditions report");
}
Aggregations