Skip to content

Commit de1eb34

Browse files
committed
Polish WebSocketIntegrationTests
1 parent 417bb30 commit de1eb34

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/ReactorNettyWebSocketSession.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.reactivestreams.Publisher;
2121
import reactor.core.publisher.Flux;
2222
import reactor.core.publisher.Mono;
23-
import reactor.core.publisher.MonoProcessor;
2423
import reactor.ipc.netty.NettyInbound;
2524
import reactor.ipc.netty.NettyOutbound;
2625
import reactor.ipc.netty.NettyPipeline;
@@ -35,17 +34,15 @@
3534

3635

3736
/**
38-
* Spring {@link WebSocketSession} implementation that adapts to Reactor Netty's
39-
* WebSocket {@link NettyInbound} and {@link NettyOutbound}.
37+
* {@link WebSocketSession} implementation for use with the Reactor Netty's
38+
* {@link NettyInbound} and {@link NettyOutbound}.
4039
*
4140
* @author Rossen Stoyanchev
4241
* @since 5.0
4342
*/
4443
public class ReactorNettyWebSocketSession
4544
extends NettyWebSocketSessionSupport<ReactorNettyWebSocketSession.WebSocketConnection> {
4645

47-
private final MonoProcessor<WebSocketFrame> closeMono = MonoProcessor.create();
48-
4946

5047
public ReactorNettyWebSocketSession(WebsocketInbound inbound, WebsocketOutbound outbound,
5148
HandshakeInfo info, NettyDataBufferFactory bufferFactory) {

spring-webflux/src/test/java/org/springframework/web/reactive/socket/WebSocketIntegrationTests.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@
4343

4444
/**
4545
* Integration tests with server-side {@link WebSocketHandler}s.
46-
*
4746
* @author Rossen Stoyanchev
4847
*/
4948
public class WebSocketIntegrationTests extends AbstractWebSocketIntegrationTests {
5049

5150
private static final Log logger = LogFactory.getLog(WebSocketIntegrationTests.class);
5251

52+
private static final Duration TIMEOUT = Duration.ofMillis(5000);
53+
5354

5455
@Override
5556
protected Class<?> getWebConfigClass() {
@@ -71,14 +72,12 @@ public void echo() throws Exception {
7172
.thenMany(session.receive().take(count).map(WebSocketMessage::getPayloadAsText))
7273
.subscribeWith(output)
7374
.doOnNext(s -> logger.debug("inbound " + s))
74-
.then()
75-
.doOnSuccessOrError((aVoid, ex) ->
76-
logger.debug("Done with " + (ex != null ? ex.getMessage() : "success")));
75+
.then();
7776
})
78-
.block(Duration.ofMillis(5000));
77+
.doOnSuccessOrError((aVoid, ex) -> logger.debug("Done: " + (ex != null ? ex.getMessage() : "success")))
78+
.block(TIMEOUT);
7979

80-
assertEquals(input.collectList().block(Duration.ofMillis(5000)),
81-
output.collectList().block(Duration.ofMillis(5000)));
80+
assertEquals(input.collectList().block(TIMEOUT), output.collectList().block(TIMEOUT));
8281
}
8382

8483
@Test
@@ -102,13 +101,13 @@ public Mono<Void> handle(WebSocketSession session) {
102101
.then();
103102
}
104103
})
105-
.block(Duration.ofMillis(5000));
104+
.block(TIMEOUT);
106105

107106
HandshakeInfo info = infoRef.get();
108107
assertThat(info.getHeaders().getFirst("Upgrade"), Matchers.equalToIgnoringCase("websocket"));
109108
assertEquals(protocol, info.getHeaders().getFirst("Sec-WebSocket-Protocol"));
110109
assertEquals("Wrong protocol accepted", protocol, info.getSubProtocol());
111-
assertEquals("Wrong protocol detected on the server side", protocol, output.block(Duration.ofMillis(5000)));
110+
assertEquals("Wrong protocol detected on the server side", protocol, output.block(TIMEOUT));
112111
}
113112

114113
@Test
@@ -122,9 +121,9 @@ public void customHeader() throws Exception {
122121
.map(WebSocketMessage::getPayloadAsText)
123122
.subscribeWith(output)
124123
.then())
125-
.block(Duration.ofMillis(5000));
124+
.block(TIMEOUT);
126125

127-
assertEquals("my-header:my-value", output.block(Duration.ofMillis(5000)));
126+
assertEquals("my-header:my-value", output.block(TIMEOUT));
128127
}
129128

130129
@Test
@@ -139,7 +138,7 @@ public void sessionClosing() throws Exception {
139138
logger.debug("Completed with: " + signalType);
140139
});
141140
})
142-
.block(Duration.ofMillis(5000));
141+
.block(TIMEOUT);
143142
}
144143

145144

0 commit comments

Comments
 (0)