Skip to content

Commit

Permalink
Issue #4226 - fix test failures
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Jan 30, 2020
1 parent 82c61c4 commit 006fd3f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ 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)
public void onMessage(String message) throws IOException
{
}

@OnMessage(maxMessageSize = -1)
@OnMessage()
public void onMessage(ByteBuffer message) throws IOException
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String>
@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())
Expand All @@ -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));
}
}

0 comments on commit 006fd3f

Please sign in to comment.