Search in sources :

Example 6 with ApplicationReadyEvent

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

the class RegistrationApplicationListenerTest method test_register.

@Test
public void test_register() throws Exception {
    ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
    TaskScheduler scheduler = mock(TaskScheduler.class);
    RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, scheduler);
    listener.onApplicationReady(new ApplicationReadyEvent(mock(SpringApplication.class), null, mock(ConfigurableWebApplicationContext.class)));
    verify(scheduler).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 7 with ApplicationReadyEvent

use of org.springframework.boot.context.event.ApplicationReadyEvent 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);
}
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) ScheduledFuture(java.util.concurrent.ScheduledFuture) ContextClosedEvent(org.springframework.context.event.ContextClosedEvent) Test(org.junit.Test)

Example 8 with ApplicationReadyEvent

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

the class SpringApplicationAdminMXBeanRegistrarTests method eventsFromOtherContextsAreIgnored.

@Test
public void eventsFromOtherContextsAreIgnored() throws MalformedObjectNameException {
    SpringApplicationAdminMXBeanRegistrar registrar = new SpringApplicationAdminMXBeanRegistrar(OBJECT_NAME);
    ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
    registrar.setApplicationContext(context);
    registrar.onApplicationEvent(new ApplicationReadyEvent(new SpringApplication(), null, mock(ConfigurableApplicationContext.class)));
    assertThat(isApplicationReady(registrar)).isFalse();
    registrar.onApplicationEvent(new ApplicationReadyEvent(new SpringApplication(), null, context));
    assertThat(isApplicationReady(registrar)).isTrue();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) Test(org.junit.Test)

Example 9 with ApplicationReadyEvent

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

the class RestartApplicationListenerTests method testInitialize.

private void testInitialize(boolean failed) {
    Restarter.clearInstance();
    RestartApplicationListener listener = new RestartApplicationListener();
    SpringApplication application = new SpringApplication();
    ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
    listener.onApplicationEvent(new ApplicationStartingEvent(application, ARGS));
    assertThat(Restarter.getInstance()).isNotEqualTo(nullValue());
    assertThat(Restarter.getInstance().isFinished()).isFalse();
    listener.onApplicationEvent(new ApplicationPreparedEvent(application, ARGS, context));
    if (failed) {
        listener.onApplicationEvent(new ApplicationFailedEvent(application, ARGS, context, new RuntimeException()));
    } else {
        listener.onApplicationEvent(new ApplicationReadyEvent(application, ARGS, context));
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) SpringApplication(org.springframework.boot.SpringApplication) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) ApplicationPreparedEvent(org.springframework.boot.context.event.ApplicationPreparedEvent) ApplicationStartingEvent(org.springframework.boot.context.event.ApplicationStartingEvent)

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