Issue #3835 - fix SessionTracker dump, add test assertions

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2019-07-02 18:32:22 +10:00
parent 2383bf4974
commit 196833d15e
2 changed files with 27 additions and 11 deletions

View File

@ -27,10 +27,12 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.common.WebSocketSessionListener;
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
import org.junit.jupiter.api.AfterEach;
@ -48,6 +50,7 @@ public class ConcurrentConnectTest
private Server server;
private WebSocketClient client;
private URI uri;
private WebSocketServerFactory serverFactory;
@BeforeEach
public void start() throws Exception
@ -59,7 +62,17 @@ public class ConcurrentConnectTest
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
context.addServlet(MyWebSocketServlet.class, "/");
WebSocketServlet servlet = new WebSocketServlet() {
@Override
public void configure(WebSocketServletFactory factory)
{
factory.register(EventSocket.EchoSocket.class);
serverFactory = (WebSocketServerFactory)factory;
}
};
context.addServlet(new ServletHolder(servlet), "/");
server.setHandler(context);
server.start();
@ -124,6 +137,10 @@ public class ConcurrentConnectTest
{
assertTrue(((WebSocketSession)l.session).isStopped());
}
assertTrue(client.getOpenSessions().isEmpty());
assertTrue(client.getContainedBeans(WebSocketSession.class).isEmpty());
assertTrue(serverFactory.getContainedBeans(WebSocketSession.class).isEmpty());
}
public static class CloseListener implements WebSocketSessionListener
@ -146,13 +163,4 @@ public class ConcurrentConnectTest
closeLatch.countDown();
}
}
public static class MyWebSocketServlet extends WebSocketServlet
{
@Override
public void configure(WebSocketServletFactory factory)
{
factory.register(EventSocket.EchoSocket.class);
}
}
}

View File

@ -18,14 +18,16 @@
package org.eclipse.jetty.websocket.common;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.component.LifeCycle;
public class SessionTracker extends AbstractLifeCycle implements WebSocketSessionListener
public class SessionTracker extends AbstractLifeCycle implements WebSocketSessionListener, Dumpable
{
private CopyOnWriteArraySet<WebSocketSession> sessions = new CopyOnWriteArraySet<>();
@ -63,4 +65,10 @@ public class SessionTracker extends AbstractLifeCycle implements WebSocketSessio
}
super.doStop();
}
@Override
public void dump(Appendable out, String indent) throws IOException
{
Dumpable.dumpObjects(out, indent, this, sessions);
}
}