Search in sources :

Example 1 with ApplicationReadyEvent

use of org.springframework.boot.context.event.ApplicationReadyEvent in project spring-boot-admin by codecentric.

the class StatusUpdateApplicationListenerTest method test_start_stop.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void test_start_stop() throws Exception {
    StatusUpdater statusUpdater = mock(StatusUpdater.class);
    ThreadPoolTaskScheduler scheduler = mock(ThreadPoolTaskScheduler.class);
    StatusUpdateApplicationListener listener = new StatusUpdateApplicationListener(statusUpdater, 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.onContextClosed(new ContextClosedEvent(mock(EmbeddedWebApplicationContext.class)));
    verify(task).cancel(true);
}
Also used : ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) ScheduledFuture(java.util.concurrent.ScheduledFuture) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) ContextClosedEvent(org.springframework.context.event.ContextClosedEvent) Test(org.junit.Test)

Example 2 with ApplicationReadyEvent

use of org.springframework.boot.context.event.ApplicationReadyEvent in project spring-boot-admin by codecentric.

the class RegistrationApplicationListenerTest method test_no_register.

@Test
public void test_no_register() throws Exception {
    ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
    TaskScheduler scheduler = mock(TaskScheduler.class);
    RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, scheduler);
    listener.setAutoRegister(false);
    listener.onApplicationReady(new ApplicationReadyEvent(mock(SpringApplication.class), null, mock(ConfigurableWebApplicationContext.class)));
    verify(scheduler, never()).scheduleAtFixedRate(isA(Runnable.class), eq(10_000L));
}
Also used : RegistrationApplicationListener(de.codecentric.boot.admin.client.registration.RegistrationApplicationListener) ApplicationRegistrator(de.codecentric.boot.admin.client.registration.ApplicationRegistrator) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) TaskScheduler(org.springframework.scheduling.TaskScheduler) Test(org.junit.Test)

Example 3 with ApplicationReadyEvent

use of org.springframework.boot.context.event.ApplicationReadyEvent in project zipkin by openzipkin.

the class RegisterZipkinHealthIndicators method onApplicationEvent.

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (!(event instanceof ApplicationReadyEvent))
        return;
    ConfigurableListableBeanFactory beanFactory = ((ApplicationReadyEvent) event).getApplicationContext().getBeanFactory();
    ZipkinHealthIndicator healthIndicator = beanFactory.getBean(ZipkinHealthIndicator.class);
    for (Component component : beanFactory.getBeansOfType(Component.class).values()) {
        healthIndicator.addComponent(component);
    }
}
Also used : ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) Component(zipkin.Component) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 4 with ApplicationReadyEvent

use of org.springframework.boot.context.event.ApplicationReadyEvent in project spring-boot by spring-projects.

the class ApplicationPidFileWriterTests method createReadyEvent.

private SpringApplicationEvent createReadyEvent(String propName, String propValue) {
    ConfigurableEnvironment environment = createEnvironment(propName, propValue);
    ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
    given(context.getEnvironment()).willReturn(environment);
    return new ApplicationReadyEvent(new SpringApplication(), new String[] {}, context);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) SpringApplication(org.springframework.boot.SpringApplication) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent)

Example 5 with ApplicationReadyEvent

use of org.springframework.boot.context.event.ApplicationReadyEvent in project spring-boot-admin by codecentric.

the class DefaultApplicationFactoryTest method publishApplicationReadyEvent.

private void publishApplicationReadyEvent(DefaultApplicationFactory factory, Integer serverport, Integer managementport) {
    MockEnvironment env = new MockEnvironment();
    if (serverport != null) {
        env.setProperty("local.server.port", serverport.toString());
    }
    if (managementport != null) {
        env.setProperty("local.management.port", managementport.toString());
    }
    ConfigurableWebApplicationContext context = mock(ConfigurableWebApplicationContext.class);
    when(context.getEnvironment()).thenReturn(env);
    factory.onApplicationReady(new ApplicationReadyEvent(mock(SpringApplication.class), new String[] {}, context));
}
Also used : ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Aggregations

ApplicationReadyEvent (org.springframework.boot.context.event.ApplicationReadyEvent)9 Test (org.junit.Test)5 ApplicationRegistrator (de.codecentric.boot.admin.client.registration.ApplicationRegistrator)3 RegistrationApplicationListener (de.codecentric.boot.admin.client.registration.RegistrationApplicationListener)3 SpringApplication (org.springframework.boot.SpringApplication)3 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)3 TaskScheduler (org.springframework.scheduling.TaskScheduler)3 ScheduledFuture (java.util.concurrent.ScheduledFuture)2 ContextClosedEvent (org.springframework.context.event.ContextClosedEvent)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1 ApplicationFailedEvent (org.springframework.boot.context.event.ApplicationFailedEvent)1 ApplicationPreparedEvent (org.springframework.boot.context.event.ApplicationPreparedEvent)1 ApplicationStartingEvent (org.springframework.boot.context.event.ApplicationStartingEvent)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1 MockEnvironment (org.springframework.mock.env.MockEnvironment)1 ThreadPoolTaskScheduler (org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)1 ConfigurableWebApplicationContext (org.springframework.web.context.ConfigurableWebApplicationContext)1 Component (zipkin.Component)1