From 006fd3f913d2403d32d2f73313f7ab27cd1c9380 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 30 Jan 2020 11:26:51 +1100 Subject: [PATCH] Issue #4226 - fix test failures Signed-off-by: Lachlan Roberts --- .../javax/tests/ServerConfigTest.java | 4 +- .../javax/tests/client/WriteTimeoutTest.java | 92 +++++++------------ 2 files changed, 36 insertions(+), 60 deletions(-) diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/ServerConfigTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/ServerConfigTest.java index 4b1e59b25efd..8c03beb12ee8 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/ServerConfigTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/ServerConfigTest.java @@ -106,7 +106,7 @@ public static class AnnotatedOnMessageSocket public void onOpen(Session session) { assertThat(session.getMaxTextMessageBufferSize(), is(111)); - assertThat(session.getMaxBinaryMessageBufferSize(), is(-1)); + assertThat(session.getMaxBinaryMessageBufferSize(), is(maxBinaryMessageSize)); } @OnMessage(maxMessageSize = 111) @@ -114,7 +114,7 @@ public void onMessage(String message) throws IOException { } - @OnMessage(maxMessageSize = -1) + @OnMessage() public void onMessage(ByteBuffer message) throws IOException { } diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/WriteTimeoutTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/WriteTimeoutTest.java index b3ea7642b412..17df21ec9368 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/WriteTimeoutTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/WriteTimeoutTest.java @@ -19,23 +19,17 @@ package org.eclipse.jetty.websocket.javax.tests.client; import java.util.concurrent.TimeUnit; -import javax.websocket.ContainerProvider; import javax.websocket.EndpointConfig; -import javax.websocket.MessageHandler; -import javax.websocket.OnError; -import javax.websocket.OnMessage; import javax.websocket.Session; -import javax.websocket.WebSocketContainer; import javax.websocket.server.ServerEndpoint; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.exception.WebSocketWriteTimeoutException; +import org.eclipse.jetty.websocket.javax.client.JavaxWebSocketClientContainer; +import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketContainer; +import org.eclipse.jetty.websocket.javax.tests.EventSocket; import org.eclipse.jetty.websocket.javax.tests.LocalServer; -import org.eclipse.jetty.websocket.javax.tests.WSEndpointTracker; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.instanceOf; @@ -44,49 +38,48 @@ public class WriteTimeoutTest { - private static LocalServer server; + @ServerEndpoint("/logSocket") + public static class ServerSocket extends EventSocket + { + @Override + public void onOpen(Session session, EndpointConfig endpointConfig) + { + session.setMaxIdleTimeout(-1); + session.setMaxTextMessageBufferSize(-1); + super.onOpen(session, endpointConfig); + } + } + + private LocalServer server; + private JavaxWebSocketContainer client; - @BeforeAll - public static void startServer() throws Exception + @BeforeEach + public void start() throws Exception { server = new LocalServer(); server.start(); - server.getServerContainer().addEndpoint(LoggingSocket.class); - } + server.getServerContainer().addEndpoint(ServerSocket.class); - @AfterAll - public static void stopServer() throws Exception - { - server.stop(); + client = new JavaxWebSocketClientContainer(); + client.start(); } - public static class ClientEndpoint extends WSEndpointTracker implements MessageHandler.Whole + @AfterEach + public void stop() throws Exception { - @Override - public void onOpen(Session session, EndpointConfig config) - { - super.onOpen(session, config); - session.addMessageHandler(this); - } - - @Override - public void onMessage(String message) - { - super.onWsText(message); - } + client.stop(); + server.stop(); } @Test - public void testEchoInstance() throws Exception + public void testTimeoutOnLargeMessage() throws Exception { - WebSocketContainer container = ContainerProvider.getWebSocketContainer(); - ClientEndpoint clientEndpoint = new ClientEndpoint(); - assertThat(clientEndpoint, Matchers.instanceOf(javax.websocket.Endpoint.class)); - Session session = container.connectToServer(clientEndpoint, null, server.getWsUri().resolve("/logSocket")); + EventSocket clientEndpoint = new EventSocket(); + Session session = client.connectToServer(clientEndpoint, server.getWsUri().resolve("/logSocket")); session.getAsyncRemote().setSendTimeout(5); + session.setMaxTextMessageBufferSize(1024 * 1024 * 6); - session.setMaxTextMessageBufferSize(1000000); String string = "xxxxxxx"; StringBuilder sb = new StringBuilder(); while (sb.length() < session.getMaxTextMessageBufferSize() - string.length()) @@ -101,24 +94,7 @@ public void testEchoInstance() throws Exception } assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); - assertThat(clientEndpoint.error.get(), instanceOf(WebSocketWriteTimeoutException.class)); - } - - @ServerEndpoint("/logSocket") - public static class LoggingSocket - { - private final Logger log = Log.getLogger(LoggingSocket.class); - - @OnMessage - public void onMessage(String msg) - { - log.debug("onMessage(): {}", msg); - } - - @OnError - public void onError(Throwable t) - { - log.debug("onError(): {}", t); - } + assertTrue(clientEndpoint.errorLatch.await(5, TimeUnit.SECONDS)); + assertThat(clientEndpoint.error, instanceOf(WebSocketWriteTimeoutException.class)); } }