Search in sources :

Example 1 with Receiptable

use of org.springframework.messaging.simp.stomp.StompSession.Receiptable 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)

Aggregations

Date (java.util.Date)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.junit.Test)1 Receiptable (org.springframework.messaging.simp.stomp.StompSession.Receiptable)1 TaskScheduler (org.springframework.scheduling.TaskScheduler)1