Search in sources :

Example 6 with ConcurrentWebSocketSessionDecorator

use of org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator in project spring-framework by spring-projects.

the class OrderedMessageSendingIntegrationTests method exceedBufferSizeLimit.

@Test
void exceedBufferSizeLimit() throws InterruptedException {
    ConcurrentWebSocketSessionDecorator concurrentSessionDecorator = new ConcurrentWebSocketSessionDecorator(this.blockingSession, 60 * 1000, 2 * MESSAGE_SIZE);
    TestMessageHandler messageHandler = new TestMessageHandler(concurrentSessionDecorator);
    subscribableChannel.subscribe(messageHandler);
    // Send one to block
    this.orderedMessageChannel.send(createMessage(0));
    int messageCount = 3;
    CountDownLatch messageLatch = new CountDownLatch(messageCount);
    messageHandler.setMessageLatch(messageLatch);
    for (int i = 1; i <= messageCount; i++) {
        this.orderedMessageChannel.send(createMessage(i));
    }
    messageLatch.await(5, TimeUnit.SECONDS);
    assertThat(messageHandler.getSavedException()).hasMessage("Buffer size " + 3 * MESSAGE_SIZE + " bytes for session '1' exceeds the allowed limit " + 2 * MESSAGE_SIZE);
}
Also used : ConcurrentWebSocketSessionDecorator(org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

ConcurrentWebSocketSessionDecorator (org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator)6 CountDownLatch (java.util.concurrent.CountDownLatch)3 Test (org.junit.jupiter.api.Test)3 Principal (java.security.Principal)1 ArrayList (java.util.ArrayList)1 Message (org.springframework.messaging.Message)1 SimpAttributes (org.springframework.messaging.simp.SimpAttributes)1 StompCommand (org.springframework.messaging.simp.stomp.StompCommand)1 StompHeaderAccessor (org.springframework.messaging.simp.stomp.StompHeaderAccessor)1