Fix broken websocket tests.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2021-04-06 23:18:41 +10:00
parent bda4c21bcb
commit 02ef27246c
3 changed files with 36 additions and 19 deletions

View File

@ -74,8 +74,8 @@ public class JavaxWebSocketSession implements javax.websocket.Session
this.coreSession = coreSession;
this.frameHandler = frameHandler;
this.sessionId = UUID.randomUUID().toString();
this.availableDecoders = new AvailableDecoders(endpointConfig, coreSession.getWebSocketComponents());
this.availableEncoders = new AvailableEncoders(endpointConfig, coreSession.getWebSocketComponents());
this.availableDecoders = new AvailableDecoders(endpointConfig, container.getWebSocketComponents());
this.availableEncoders = new AvailableEncoders(endpointConfig, container.getWebSocketComponents());
if (endpointConfig instanceof PathParamProvider)
{

View File

@ -46,14 +46,22 @@ public abstract class AbstractJavaxWebSocketFrameHandlerTest
protected AvailableDecoders decoders;
protected Map<String, String> uriParams;
protected EndpointConfig endpointConfig;
protected CoreSession coreSession = new CoreSession.Empty();
private WebSocketComponents components = new WebSocketComponents();
protected CoreSession coreSession = new CoreSession.Empty()
{
private final WebSocketComponents components = new WebSocketComponents();
@Override
public WebSocketComponents getWebSocketComponents()
{
return components;
}
};
public AbstractJavaxWebSocketFrameHandlerTest()
{
endpointConfig = ClientEndpointConfig.Builder.create().build();
encoders = new AvailableEncoders(endpointConfig, components);
decoders = new AvailableDecoders(endpointConfig, components);
encoders = new AvailableEncoders(endpointConfig, coreSession.getWebSocketComponents());
decoders = new AvailableDecoders(endpointConfig, coreSession.getWebSocketComponents());
uriParams = new HashMap<>();
}

View File

@ -32,6 +32,7 @@ import org.eclipse.jetty.websocket.core.CloseStatus;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@ -39,6 +40,7 @@ import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.jupiter.api.Assertions.assertTimeout;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class JettyWebSocketFrameHandlerTest
{
@ -57,20 +59,27 @@ public class JettyWebSocketFrameHandlerTest
container.stop();
}
private JettyWebSocketFrameHandlerFactory endpointFactory = new JettyWebSocketFrameHandlerFactory(container);
private CoreSession coreSession = new CoreSession.Empty()
private final JettyWebSocketFrameHandlerFactory endpointFactory = new JettyWebSocketFrameHandlerFactory(container);
private final CoreSession coreSession = new CoreSession.Empty()
{
private final WebSocketComponents components = new WebSocketComponents();
@Override
public Behavior getBehavior()
{
return Behavior.CLIENT;
}
@Override
public WebSocketComponents getWebSocketComponents()
{
return components;
}
};
private JettyWebSocketFrameHandler newLocalFrameHandler(Object wsEndpoint)
{
JettyWebSocketFrameHandler localEndpoint = endpointFactory.newJettyFrameHandler(wsEndpoint);
return localEndpoint;
return endpointFactory.newJettyFrameHandler(wsEndpoint);
}
public static class ConnectionOnly implements WebSocketConnectionListener
@ -97,7 +106,7 @@ public class JettyWebSocketFrameHandlerTest
}
@Test
public void testConnectionListener() throws Exception
public void testConnectionListener()
{
ConnectionOnly socket = new ConnectionOnly();
JettyWebSocketFrameHandler localEndpoint = newLocalFrameHandler(socket);
@ -138,7 +147,7 @@ public class JettyWebSocketFrameHandlerTest
}
@Test
public void testAnnotatedStreamedTextSingle() throws Exception
public void testAnnotatedStreamedTextSingle()
{
assertTimeout(Duration.ofMillis(1000), () ->
{
@ -160,7 +169,7 @@ public class JettyWebSocketFrameHandlerTest
}
@Test
public void testAnnotatedStreamedTextMultipleParts() throws Exception
public void testAnnotatedStreamedTextMultipleParts()
{
assertTimeout(Duration.ofMillis(1000), () ->
{
@ -177,7 +186,7 @@ public class JettyWebSocketFrameHandlerTest
localEndpoint.onFrame(CloseStatus.toFrame(StatusCode.NORMAL, "Normal"), Callback.NOOP);
// Await completion (of threads)
socket.streamLatch.await(2, TimeUnit.SECONDS);
assertTrue(socket.streamLatch.await(2, TimeUnit.SECONDS));
// Validate Events
socket.events.assertEvents("onTextStream\\(Hello World\\)");
@ -185,7 +194,7 @@ public class JettyWebSocketFrameHandlerTest
}
@Test
public void testListenerPartialSocket() throws Exception
public void testListenerPartialSocket()
{
// Setup
EndPoints.ListenerPartialSocket socket = new EndPoints.ListenerPartialSocket();
@ -216,7 +225,7 @@ public class JettyWebSocketFrameHandlerTest
}
@Test
public void testListenerBasicSocket() throws Exception
public void testListenerBasicSocket()
{
// Setup
EndPoints.ListenerBasicSocket socket = new EndPoints.ListenerBasicSocket();
@ -242,7 +251,7 @@ public class JettyWebSocketFrameHandlerTest
}
@Test
public void testListenerBasicSocketError() throws Exception
public void testListenerBasicSocketError()
{
// Setup
EndPoints.ListenerBasicSocket socket = new EndPoints.ListenerBasicSocket();
@ -262,7 +271,7 @@ public class JettyWebSocketFrameHandlerTest
}
@Test
public void testListenerFrameSocket() throws Exception
public void testListenerFrameSocket()
{
// Setup
EndPoints.ListenerFrameSocket socket = new EndPoints.ListenerFrameSocket();
@ -292,7 +301,7 @@ public class JettyWebSocketFrameHandlerTest
}
@Test
public void testListenerPingPongSocket() throws Exception
public void testListenerPingPongSocket()
{
// Setup
EndPoints.ListenerPingPongSocket socket = new EndPoints.ListenerPingPongSocket();