Search in sources :

Example 1 with TaskScheduler

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

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

the class RegistrationApplicationListenerTest method test_no_deregister.

@Test
public void test_no_deregister() throws Exception {
    ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
    TaskScheduler scheduler = mock(TaskScheduler.class);
    RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, scheduler);
    listener.onClosedContext(new ContextClosedEvent(mock(EmbeddedWebApplicationContext.class)));
    verify(registrator, never()).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 3 with TaskScheduler

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

the class DefaultStompSessionTests method receiptNotReceived.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void receiptNotReceived() throws Exception {
    TaskScheduler taskScheduler = mock(TaskScheduler.class);
    this.session.afterConnected(this.connection);
    this.session.setTaskScheduler(taskScheduler);
    AtomicReference<Boolean> notReceived = new AtomicReference<>();
    ScheduledFuture future = mock(ScheduledFuture.class);
    when(taskScheduler.schedule(any(Runnable.class), any(Date.class))).thenReturn(future);
    StompHeaders headers = new StompHeaders();
    headers.setDestination("/topic/foo");
    headers.setReceipt("my-receipt");
    Receiptable receiptable = this.session.send(headers, "payload");
    receiptable.addReceiptLostTask(() -> notReceived.set(true));
    ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class);
    verify(taskScheduler).schedule(taskCaptor.capture(), (Date) notNull());
    Runnable scheduledTask = taskCaptor.getValue();
    assertNotNull(scheduledTask);
    assertNull(notReceived.get());
    scheduledTask.run();
    assertTrue(notReceived.get());
    verify(future).cancel(true);
    verifyNoMoreInteractions(future);
}
Also used : Receiptable(org.springframework.messaging.simp.stomp.StompSession.Receiptable) AtomicReference(java.util.concurrent.atomic.AtomicReference) TaskScheduler(org.springframework.scheduling.TaskScheduler) ScheduledFuture(java.util.concurrent.ScheduledFuture) Date(java.util.Date) Test(org.junit.Test)

Example 4 with TaskScheduler

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

the class SockJsWebSocketHandlerTests method getSubProtocolsNone.

@Test
public void getSubProtocolsNone() throws Exception {
    WebSocketHandler handler = new TextWebSocketHandler();
    TaskScheduler scheduler = mock(TaskScheduler.class);
    DefaultSockJsService service = new DefaultSockJsService(scheduler);
    WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
    SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);
    assertNull(sockJsHandler.getSubProtocols());
}
Also used : WebSocketServerSockJsSession(org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) SubProtocolWebSocketHandler(org.springframework.web.socket.messaging.SubProtocolWebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) TaskScheduler(org.springframework.scheduling.TaskScheduler) Test(org.junit.Test)

Example 5 with TaskScheduler

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

the class SockJsWebSocketHandlerTests method getSubProtocols.

@Test
public void getSubProtocols() throws Exception {
    SubscribableChannel channel = mock(SubscribableChannel.class);
    SubProtocolWebSocketHandler handler = new SubProtocolWebSocketHandler(channel, channel);
    StompSubProtocolHandler stompHandler = new StompSubProtocolHandler();
    handler.addProtocolHandler(stompHandler);
    TaskScheduler scheduler = mock(TaskScheduler.class);
    DefaultSockJsService service = new DefaultSockJsService(scheduler);
    WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
    SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);
    assertEquals(stompHandler.getSupportedProtocols(), sockJsHandler.getSubProtocols());
}
Also used : WebSocketServerSockJsSession(org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession) SubProtocolWebSocketHandler(org.springframework.web.socket.messaging.SubProtocolWebSocketHandler) StompSubProtocolHandler(org.springframework.web.socket.messaging.StompSubProtocolHandler) TaskScheduler(org.springframework.scheduling.TaskScheduler) SubscribableChannel(org.springframework.messaging.SubscribableChannel) 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