Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
public abstract class AbstractJakartaWebSocketFrameHandlerTest
{
protected DummyContainer container;
private WebSocketComponents components;
protected WebSocketComponents components;

@BeforeEach
public void startContainer() throws Exception
{
container = new DummyContainer();
container.start();
components = new WebSocketComponents();
container = new DummyContainer(components);
components.start();
container.start();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting both should not be required. Just start the container

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to do this.

Because in the non-test usage we have the WebSocketComponents managed by the server lifecycle so it can be shared between multiple WebSocket containers. For example if both Jakarta and Jetty websocket containers were used, or WebSocketContainers with different EE versions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jetty's component mechanism can handle this. If the components are managed by the server, then it will be started by server and the auto beans in the containers will be unmanaged.

Embrace the pattern!


endpointConfig = ClientEndpointConfig.Builder.create().build();
encoders = new AvailableEncoders(endpointConfig, coreSession.getWebSocketComponents());
Expand All @@ -48,8 +48,8 @@ public void startContainer() throws Exception
@AfterEach
public void stopContainer()
{
LifeCycle.stop(components);
LifeCycle.stop(container);
LifeCycle.stop(components);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just stop the container

}

protected AvailableEncoders encoders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

public abstract class AbstractSessionTest
{
protected JakartaWebSocketContainer container = new DummyContainer();
protected WebSocketComponents components = new WebSocketComponents();
protected JakartaWebSocketContainer container = new DummyContainer(components);
protected TestCoreSession coreSession = new TestCoreSession(components);
protected JakartaWebSocketSession session;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import jakarta.websocket.DeploymentException;
import jakarta.websocket.Endpoint;
import jakarta.websocket.Session;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;

Expand All @@ -31,15 +30,11 @@
public class DummyContainer extends JakartaWebSocketContainer
{
private final JakartaWebSocketFrameHandlerFactory frameHandlerFactory;
private final QueuedThreadPool executor;

public DummyContainer()
public DummyContainer(WebSocketComponents components)
{
super(new WebSocketComponents());
super(components);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The super constructor should installBean(components), but it does not

this.frameHandlerFactory = new DummyFrameHandlerFactory(this);
this.executor = new QueuedThreadPool();
this.executor.setName("qtp-DummyContainer");
addBean(this.executor, true);
}

@Override
Expand Down Expand Up @@ -113,7 +108,7 @@ public void setDefaultMaxTextMessageBufferSize(int max)
@Override
public Executor getExecutor()
{
return executor;
return getWebSocketComponents().getExecutor();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class JakartaWebSocketFrameHandlerOnMessageBinaryStreamTest extends AbstractJakartaWebSocketFrameHandlerTest
{
@SuppressWarnings("Duplicates")
private TrackingSocket performOnMessageInvocation(TrackingSocket socket, Function<JakartaWebSocketFrameHandler, Void> func) throws Exception
{
assertTrue(components.isStarted());
JakartaWebSocketFrameHandler localEndpoint = newJakartaFrameHandler(socket);

// This invocation is the same for all tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
public abstract class AbstractJakartaWebSocketFrameHandlerTest
{
protected DummyContainer container;
private WebSocketComponents components;
protected WebSocketComponents components;

@BeforeEach
public void startContainer() throws Exception
{
container = new DummyContainer();
container.start();
components = new WebSocketComponents();
container = new DummyContainer(components);
components.start();
container.start();
Comment on lines +39 to +41
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


endpointConfig = ClientEndpointConfig.Builder.create().build();
encoders = new AvailableEncoders(endpointConfig, coreSession.getWebSocketComponents());
Expand All @@ -49,8 +49,8 @@ public void startContainer() throws Exception
@AfterEach
public void stopContainer()
{
LifeCycle.stop(components);
LifeCycle.stop(container);
LifeCycle.stop(components);
}

protected AvailableEncoders encoders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@

public abstract class AbstractSessionTest
{
protected JakartaWebSocketContainer container = new DummyContainer();
protected WebSocketComponents components = new WebSocketComponents();
protected JakartaWebSocketContainer container = new DummyContainer(components);
protected TestCoreSession coreSession = new TestCoreSession(components);
protected JakartaWebSocketSession session;

@BeforeEach
public void initSession() throws Exception
{
container.start();
components.start();
container.start();
Object websocketPojo = new DummyEndpoint();
UpgradeRequest upgradeRequest = new UpgradeRequestAdapter();
JakartaWebSocketFrameHandler frameHandler = container.newFrameHandler(websocketPojo, upgradeRequest);
Expand All @@ -49,8 +49,8 @@ public void initSession() throws Exception
@AfterEach
public void stopContainer() throws Exception
{
components.stop();
container.stop();
components.stop();
}

public static class TestCoreSession extends CoreSession.Empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import jakarta.websocket.DeploymentException;
import jakarta.websocket.Endpoint;
import jakarta.websocket.Session;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;

Expand All @@ -31,15 +30,11 @@
public class DummyContainer extends JakartaWebSocketContainer
{
private final JakartaWebSocketFrameHandlerFactory frameHandlerFactory;
private final QueuedThreadPool executor;

public DummyContainer()
public DummyContainer(WebSocketComponents components)
{
super(new WebSocketComponents());
super(components);
this.frameHandlerFactory = new DummyFrameHandlerFactory(this);
this.executor = new QueuedThreadPool();
this.executor.setName("qtp-DummyContainer");
addBean(this.executor, true);
}

@Override
Expand Down Expand Up @@ -113,7 +108,7 @@ public void setDefaultMaxTextMessageBufferSize(int max)
@Override
public Executor getExecutor()
{
return executor;
return getWebSocketComponents().getExecutor();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class JakartaWebSocketFrameHandlerOnMessageBinaryStreamTest extends AbstractJakartaWebSocketFrameHandlerTest
{
@SuppressWarnings("Duplicates")
private TrackingSocket performOnMessageInvocation(TrackingSocket socket, Function<JakartaWebSocketFrameHandler, Void> func) throws Exception
{
assertTrue(components.isStarted());
JakartaWebSocketFrameHandler localEndpoint = newJakartaFrameHandler(socket);

// This invocation is the same for all tests
Expand Down