Skip to content

Commit 140ff7c

Browse files
committed
Polish reactive WebSocket integration tests
1 parent 4c005e6 commit 140ff7c

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,15 @@
4646
import org.springframework.web.reactive.socket.server.upgrade.UndertowRequestUpgradeStrategy;
4747

4848
/**
49-
* Base class for WebSocket integration tests involving a server-side
50-
* {@code WebSocketHandler}. Sub-classes to return a Spring configuration class
51-
* via {@link #getWebConfigClass()} containing a SimpleUrlHandlerMapping with
52-
* pattern-to-WebSocketHandler mappings.
49+
* Base class for WebSocket integration tests.
50+
* Sub-classes must implement {@link #getWebConfigClass()} to return Spring
51+
* config class with handler mappings to {@code WebSocketHandler}'s.
5352
*
5453
* @author Rossen Stoyanchev
5554
*/
5655
@RunWith(Parameterized.class)
5756
@SuppressWarnings({"unused", "WeakerAccess"})
58-
public abstract class AbstractWebSocketHandlerIntegrationTests {
57+
public abstract class AbstractWebSocketIntegrationTests {
5958

6059
protected int port;
6160

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.nio.charset.StandardCharsets;
1919
import java.util.HashMap;
20-
import java.util.List;
2120
import java.util.Map;
2221

2322
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
@@ -38,11 +37,12 @@
3837
import static org.junit.Assert.assertEquals;
3938

4039
/**
41-
* Basic WebSocket integration tests.
40+
* Integration tests with server-side {@link WebSocketHandler}s.
41+
*
4242
* @author Rossen Stoyanchev
4343
*/
4444
@SuppressWarnings({"unused", "WeakerAccess"})
45-
public class BasicWebSocketHandlerIntegrationTests extends AbstractWebSocketHandlerIntegrationTests {
45+
public class ServerWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests {
4646

4747

4848
@Override
@@ -53,26 +53,22 @@ protected Class<?> getWebConfigClass() {
5353

5454
@Test
5555
public void echo() throws Exception {
56-
Observable<String> messages = Observable.range(1, 10).map(i -> "Interval " + i);
57-
List<String> actual = HttpClient.newClient("localhost", this.port)
56+
int count = 100;
57+
Observable<String> input = Observable.range(1, count).map(index -> "msg-" + index);
58+
Observable<String> output = HttpClient.newClient("localhost", this.port)
5859
.createGet("/echo")
5960
.requestWebSocketUpgrade()
6061
.flatMap(WebSocketResponse::getWebSocketConnection)
61-
.flatMap(conn -> conn.write(messages
62-
.map(TextWebSocketFrame::new)
63-
.cast(WebSocketFrame.class))
64-
.cast(WebSocketFrame.class)
62+
.flatMap(conn -> conn
63+
.write(input.map(TextWebSocketFrame::new)).cast(WebSocketFrame.class)
6564
.mergeWith(conn.getInput())
66-
)
67-
.take(10)
68-
.map(frame -> {
69-
String text = frame.content().toString(StandardCharsets.UTF_8);
70-
frame.release();
71-
return text;
72-
})
73-
.toList().toBlocking().first();
74-
List<String> expected = messages.toList().toBlocking().first();
75-
assertEquals(expected, actual);
65+
.take(count)
66+
.map(frame -> {
67+
String text = frame.content().toString(StandardCharsets.UTF_8);
68+
frame.release();
69+
return text;
70+
}));
71+
assertEquals(input.toList().toBlocking().first(), output.toList().toBlocking().first());
7672
}
7773

7874

0 commit comments

Comments
 (0)