Improving WebSocketAdapter test reliability

This commit is contained in:
Joakim Erdfelt 2016-03-25 13:25:08 -07:00
parent 9116f792fd
commit 80eefb5257
4 changed files with 12 additions and 2 deletions

View File

@ -31,6 +31,7 @@ public class EchoHandler extends WebSocketHandler implements WebSocketCreator
@Override
public void configure(WebSocketServletFactory factory)
{
factory.getPolicy().setMaxTextMessageSize(2 * 1024 * 1024);
factory.setCreator(this);
}

View File

@ -38,6 +38,9 @@ public class JettyEchoSocket extends WebSocketAdapter
@Override
public void onWebSocketBinary(byte[] payload, int offset, int len)
{
if (isNotConnected())
return;
try
{
RemoteEndpoint remote = getRemote();
@ -60,6 +63,9 @@ public class JettyEchoSocket extends WebSocketAdapter
@Override
public void onWebSocketText(String message)
{
if (isNotConnected())
return;
try
{
RemoteEndpoint remote = getRemote();

View File

@ -68,6 +68,7 @@ public class MessageReceivingTest {
public static void startServer() throws Exception {
server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
server.addConnector(connector);
handler = new EchoHandler();

View File

@ -26,11 +26,11 @@ package org.eclipse.jetty.websocket.api;
public class WebSocketAdapter implements WebSocketListener
{
private volatile Session session;
private RemoteEndpoint remote;
public RemoteEndpoint getRemote()
{
Session sess = this.session;
return sess == null?null:session.getRemote();
return remote;
}
public Session getSession()
@ -60,12 +60,14 @@ public class WebSocketAdapter implements WebSocketListener
public void onWebSocketClose(int statusCode, String reason)
{
this.session = null;
this.remote = null;
}
@Override
public void onWebSocketConnect(Session sess)
{
this.session = sess;
this.remote = sess.getRemote();
}
@Override