|
|
|
@ -17,7 +17,6 @@ package org.springframework.web.reactive.socket.server; |
|
|
|
|
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; |
|
|
|
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; |
|
|
|
@ -38,11 +37,12 @@ import org.springframework.web.reactive.socket.WebSocketSession; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Basic WebSocket integration tests. |
|
|
|
* Integration tests with server-side {@link WebSocketHandler}s. |
|
|
|
|
|
|
|
* |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings({"unused", "WeakerAccess"}) |
|
|
|
@SuppressWarnings({"unused", "WeakerAccess"}) |
|
|
|
public class BasicWebSocketHandlerIntegrationTests extends AbstractWebSocketHandlerIntegrationTests { |
|
|
|
public class ServerWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@ -53,26 +53,22 @@ public class BasicWebSocketHandlerIntegrationTests extends AbstractWebSocketHand |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void echo() throws Exception { |
|
|
|
public void echo() throws Exception { |
|
|
|
Observable<String> messages = Observable.range(1, 10).map(i -> "Interval " + i); |
|
|
|
int count = 100; |
|
|
|
List<String> actual = HttpClient.newClient("localhost", this.port) |
|
|
|
Observable<String> input = Observable.range(1, count).map(index -> "msg-" + index); |
|
|
|
|
|
|
|
Observable<String> output = HttpClient.newClient("localhost", this.port) |
|
|
|
.createGet("/echo") |
|
|
|
.createGet("/echo") |
|
|
|
.requestWebSocketUpgrade() |
|
|
|
.requestWebSocketUpgrade() |
|
|
|
.flatMap(WebSocketResponse::getWebSocketConnection) |
|
|
|
.flatMap(WebSocketResponse::getWebSocketConnection) |
|
|
|
.flatMap(conn -> conn.write(messages |
|
|
|
.flatMap(conn -> conn |
|
|
|
.map(TextWebSocketFrame::new) |
|
|
|
.write(input.map(TextWebSocketFrame::new)).cast(WebSocketFrame.class) |
|
|
|
.cast(WebSocketFrame.class)) |
|
|
|
|
|
|
|
.cast(WebSocketFrame.class) |
|
|
|
|
|
|
|
.mergeWith(conn.getInput()) |
|
|
|
.mergeWith(conn.getInput()) |
|
|
|
) |
|
|
|
.take(count) |
|
|
|
.take(10) |
|
|
|
.map(frame -> { |
|
|
|
.map(frame -> { |
|
|
|
String text = frame.content().toString(StandardCharsets.UTF_8); |
|
|
|
String text = frame.content().toString(StandardCharsets.UTF_8); |
|
|
|
frame.release(); |
|
|
|
frame.release(); |
|
|
|
return text; |
|
|
|
return text; |
|
|
|
})); |
|
|
|
}) |
|
|
|
assertEquals(input.toList().toBlocking().first(), output.toList().toBlocking().first()); |
|
|
|
.toList().toBlocking().first(); |
|
|
|
|
|
|
|
List<String> expected = messages.toList().toBlocking().first(); |
|
|
|
|
|
|
|
assertEquals(expected, actual); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|