use of org.springframework.context.event.ContextClosedEvent in project spring-boot-admin by codecentric.
the class RegistrationApplicationListenerTest method test_deregister.
@Test
public void test_deregister() throws Exception {
ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
TaskScheduler scheduler = mock(TaskScheduler.class);
RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, scheduler);
listener.setAutoDeregister(true);
listener.onClosedContext(new ContextClosedEvent(mock(EmbeddedWebApplicationContext.class)));
verify(registrator).deregister();
}
use of org.springframework.context.event.ContextClosedEvent in project spring-boot-admin by codecentric.
the class RegistrationApplicationListenerTest method test_no_register_after_close.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void test_no_register_after_close() throws Exception {
ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
TaskScheduler scheduler = mock(TaskScheduler.class);
RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, scheduler);
ScheduledFuture task = mock(ScheduledFuture.class);
when(scheduler.scheduleAtFixedRate(isA(Runnable.class), eq(10_000L))).thenReturn(task);
listener.onApplicationReady(new ApplicationReadyEvent(mock(SpringApplication.class), null, mock(ConfigurableWebApplicationContext.class)));
verify(scheduler).scheduleAtFixedRate(isA(Runnable.class), eq(10_000L));
listener.onClosedContext(new ContextClosedEvent(mock(EmbeddedWebApplicationContext.class)));
verify(task).cancel(true);
}
use of org.springframework.context.event.ContextClosedEvent in project incubator-servicecomb-java-chassis by apache.
the class RawSpringMvcIntegrationTest method shutdown.
@AfterClass
public static void shutdown() throws Exception {
CseApplicationListener cal = BeanUtils.getBean("org.apache.servicecomb.core.CseApplicationListener");
ContextClosedEvent event = new ContextClosedEvent(BeanUtils.getContext());
cal.onApplicationEvent(event);
}
use of org.springframework.context.event.ContextClosedEvent in project Saturn by vipshop.
the class EmbeddedSpringSaturnApplication method onApplicationEvent.
@Override
public void onApplicationEvent(ApplicationEvent event) {
try {
if (event instanceof ContextRefreshedEvent) {
ContextRefreshedEvent contextRefreshedEvent = (ContextRefreshedEvent) event;
applicationContext = contextRefreshedEvent.getApplicationContext();
if (embeddedSaturn == null) {
embeddedSaturn = new EmbeddedSaturn();
embeddedSaturn.setSaturnApplication(this);
embeddedSaturn.start();
}
} else if (event instanceof ContextClosedEvent) {
if (embeddedSaturn != null) {
embeddedSaturn.stopGracefully();
embeddedSaturn = null;
}
}
} catch (Exception e) {
logger.warn("exception happened on event: " + event, e);
if (!ignoreExceptions) {
throw new RuntimeException(e);
}
}
}
use of org.springframework.context.event.ContextClosedEvent in project spring-boot by spring-projects.
the class LoggingApplicationListenerTests method closingContextCleansUpLoggingSystem.
@Test
void closingContextCleansUpLoggingSystem() {
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 ContextClosedEvent(this.context));
assertThat(loggingSystem.cleanedUp).isTrue();
}
Aggregations