Search in sources :

Example 1 with StompClientSupport

use of org.springframework.messaging.simp.stomp.StompClientSupport in project spring-integration by spring-projects.

the class StompSessionManagerTests method testDoConnectFailure.

@Test
public void testDoConnectFailure() throws Exception {
    StompClientSupport stompClient = mock(StompClientSupport.class);
    stompClient.setTaskScheduler(new ConcurrentTaskScheduler());
    AbstractStompSessionManager sessionManager = new AbstractStompSessionManager(stompClient) {

        private final AtomicBoolean thrown = new AtomicBoolean();

        @Override
        protected ListenableFuture<StompSession> doConnect(StompSessionHandler handler) {
            if (!this.thrown.getAndSet(true)) {
                throw new RuntimeException("intentional");
            } else {
                SettableListenableFuture<StompSession> future = new SettableListenableFuture<StompSession>();
                StompSession stompSession = mock(StompSession.class);
                future.set(stompSession);
                handler.afterConnected(stompSession, getConnectHeaders());
                return future;
            }
        }
    };
    sessionManager.start();
    final SettableListenableFuture<StompSession> stompSessionFuture = new SettableListenableFuture<StompSession>();
    sessionManager.connect(new StompSessionHandlerAdapter() {

        @Override
        public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
            stompSessionFuture.set(session);
        }
    });
    assertNotNull(stompSessionFuture.get(10, TimeUnit.SECONDS));
    sessionManager.stop();
}
Also used : ConcurrentTaskScheduler(org.springframework.scheduling.concurrent.ConcurrentTaskScheduler) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SettableListenableFuture(org.springframework.util.concurrent.SettableListenableFuture) StompClientSupport(org.springframework.messaging.simp.stomp.StompClientSupport) StompSession(org.springframework.messaging.simp.stomp.StompSession) StompSessionHandler(org.springframework.messaging.simp.stomp.StompSessionHandler) StompHeaders(org.springframework.messaging.simp.stomp.StompHeaders) StompSessionHandlerAdapter(org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter) Test(org.junit.Test)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.Test)1 StompClientSupport (org.springframework.messaging.simp.stomp.StompClientSupport)1 StompHeaders (org.springframework.messaging.simp.stomp.StompHeaders)1 StompSession (org.springframework.messaging.simp.stomp.StompSession)1 StompSessionHandler (org.springframework.messaging.simp.stomp.StompSessionHandler)1 StompSessionHandlerAdapter (org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter)1 ConcurrentTaskScheduler (org.springframework.scheduling.concurrent.ConcurrentTaskScheduler)1 SettableListenableFuture (org.springframework.util.concurrent.SettableListenableFuture)1