Search in sources :

Example 6 with TaskScheduler

use of org.springframework.scheduling.TaskScheduler 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();
}
Also used : RegistrationApplicationListener(de.codecentric.boot.admin.client.registration.RegistrationApplicationListener) ApplicationRegistrator(de.codecentric.boot.admin.client.registration.ApplicationRegistrator) TaskScheduler(org.springframework.scheduling.TaskScheduler) ContextClosedEvent(org.springframework.context.event.ContextClosedEvent) Test(org.junit.Test)

Example 7 with TaskScheduler

use of org.springframework.scheduling.TaskScheduler 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 8 with TaskScheduler

use of org.springframework.scheduling.TaskScheduler 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 9 with TaskScheduler

use of org.springframework.scheduling.TaskScheduler in project spring-boot-admin by codecentric.

the class RegistrationApplicationListenerTest method test_start_stop.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void test_start_stop() 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.startRegisterTask();
    verify(scheduler).scheduleAtFixedRate(isA(Runnable.class), eq(10_000L));
    listener.stopRegisterTask();
    verify(task).cancel(true);
}
Also used : RegistrationApplicationListener(de.codecentric.boot.admin.client.registration.RegistrationApplicationListener) ApplicationRegistrator(de.codecentric.boot.admin.client.registration.ApplicationRegistrator) TaskScheduler(org.springframework.scheduling.TaskScheduler) ScheduledFuture(java.util.concurrent.ScheduledFuture) Test(org.junit.Test)

Example 10 with TaskScheduler

use of org.springframework.scheduling.TaskScheduler in project spring-framework by spring-projects.

the class DefaultTransportRequestTests method fallbackAfterTimeout.

@Test
public void fallbackAfterTimeout() throws Exception {
    TaskScheduler scheduler = mock(TaskScheduler.class);
    Runnable sessionCleanupTask = mock(Runnable.class);
    DefaultTransportRequest request1 = createTransportRequest(this.webSocketTransport, TransportType.WEBSOCKET);
    DefaultTransportRequest request2 = createTransportRequest(this.xhrTransport, TransportType.XHR_STREAMING);
    request1.setFallbackRequest(request2);
    request1.setTimeoutScheduler(scheduler);
    request1.addTimeoutTask(sessionCleanupTask);
    request1.connect(null, this.connectFuture);
    assertTrue(this.webSocketTransport.invoked());
    assertFalse(this.xhrTransport.invoked());
    // Get and invoke the scheduled timeout task
    ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class);
    verify(scheduler).schedule(taskCaptor.capture(), any(Date.class));
    verifyNoMoreInteractions(scheduler);
    taskCaptor.getValue().run();
    assertTrue(this.xhrTransport.invoked());
    verify(sessionCleanupTask).run();
}
Also used : TaskScheduler(org.springframework.scheduling.TaskScheduler) Date(java.util.Date) Test(org.junit.Test)

Aggregations

TaskScheduler (org.springframework.scheduling.TaskScheduler)11 Test (org.junit.Test)10 ApplicationRegistrator (de.codecentric.boot.admin.client.registration.ApplicationRegistrator)6 RegistrationApplicationListener (de.codecentric.boot.admin.client.registration.RegistrationApplicationListener)6 ScheduledFuture (java.util.concurrent.ScheduledFuture)3 ApplicationReadyEvent (org.springframework.boot.context.event.ApplicationReadyEvent)3 ContextClosedEvent (org.springframework.context.event.ContextClosedEvent)3 SubProtocolWebSocketHandler (org.springframework.web.socket.messaging.SubProtocolWebSocketHandler)3 Date (java.util.Date)2 SubscribableChannel (org.springframework.messaging.SubscribableChannel)2 WebSocketServerSockJsSession (org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Before (org.junit.Before)1 Receiptable (org.springframework.messaging.simp.stomp.StompSession.Receiptable)1 WebSocketHandler (org.springframework.web.socket.WebSocketHandler)1 TextWebSocketHandler (org.springframework.web.socket.handler.TextWebSocketHandler)1 StompSubProtocolHandler (org.springframework.web.socket.messaging.StompSubProtocolHandler)1