Java Code Examples for org.springframework.messaging.simp.stomp.StompSession.Receiptable#addReceiptLostTask()
The following examples show how to use
org.springframework.messaging.simp.stomp.StompSession.Receiptable#addReceiptLostTask() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultStompSessionTests.java From spring-analysis-note with MIT License | 5 votes |
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void receiptNotReceived() { TaskScheduler taskScheduler = mock(TaskScheduler.class); this.session.afterConnected(this.connection); this.session.setTaskScheduler(taskScheduler); AtomicReference<Boolean> notReceived = new AtomicReference<>(); ScheduledFuture future = mock(ScheduledFuture.class); given(taskScheduler.schedule(any(Runnable.class), any(Date.class))).willReturn(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); }
Example 2
Source File: DefaultStompSessionTests.java From java-technology-stack with MIT License | 5 votes |
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void receiptNotReceived() { 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); }
Example 3
Source File: DefaultStompSessionTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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(), notNull(Date.class)); Runnable scheduledTask = taskCaptor.getValue(); assertNotNull(scheduledTask); assertNull(notReceived.get()); scheduledTask.run(); assertTrue(notReceived.get()); verify(future).cancel(true); verifyNoMoreInteractions(future); }