From e64b390fd601d35c785c16a816b443b88fc62aef Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Mon, 30 Aug 2021 11:11:20 +1000 Subject: [PATCH 1/3] Issue #6601 - add proper JPMS testing for websocket-core Signed-off-by: Lachlan Roberts --- pom.xml | 1 + tests/pom.xml | 1 + tests/test-jpms/pom.xml | 33 +++++++++ tests/test-jpms/test-websocket-core/pom.xml | 25 +++++++ .../src/main/java/module-info.java | 7 ++ .../org/example/websocket/MyFrameHandler.java | 62 ++++++++++++++++ .../src/test/java/WebSocketCoreJpmsTest.java | 72 +++++++++++++++++++ 7 files changed, 201 insertions(+) create mode 100644 tests/test-jpms/pom.xml create mode 100644 tests/test-jpms/test-websocket-core/pom.xml create mode 100644 tests/test-jpms/test-websocket-core/src/main/java/module-info.java create mode 100644 tests/test-jpms/test-websocket-core/src/main/java/org/example/websocket/MyFrameHandler.java create mode 100644 tests/test-jpms/test-websocket-core/src/test/java/WebSocketCoreJpmsTest.java diff --git a/pom.xml b/pom.xml index 7f3a5be5a4e..885e54b8fd5 100644 --- a/pom.xml +++ b/pom.xml @@ -153,6 +153,7 @@ documentation jetty-keystore jetty-unixdomain-server + test-websocket-core diff --git a/tests/pom.xml b/tests/pom.xml index 36993d7cc35..a8140e9c0bd 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -56,5 +56,6 @@ test-http-client-transport test-distribution test-cdi + test-jpms diff --git a/tests/test-jpms/pom.xml b/tests/test-jpms/pom.xml new file mode 100644 index 00000000000..abe7e8d2b0c --- /dev/null +++ b/tests/test-jpms/pom.xml @@ -0,0 +1,33 @@ + + + + org.eclipse.jetty.tests + tests-parent + 10.0.7-SNAPSHOT + + 4.0.0 + test-jpms + pom + Jetty Tests :: JPMS Parent + + test-websocket-core + + + + + org.eclipse.jetty + jetty-slf4j-impl + + + org.junit.jupiter + junit-jupiter + test + + + org.eclipse.jetty.toolchain + jetty-test-helper + test + + + + diff --git a/tests/test-jpms/test-websocket-core/pom.xml b/tests/test-jpms/test-websocket-core/pom.xml new file mode 100644 index 00000000000..903d38e64fd --- /dev/null +++ b/tests/test-jpms/test-websocket-core/pom.xml @@ -0,0 +1,25 @@ + + + + test-jpms + org.eclipse.jetty.tests + 10.0.7-SNAPSHOT + + 4.0.0 + test-websocket-core + jar + Jetty Tests :: JPMS :: WebSocket Core Tests + + + + org.eclipse.jetty.websocket + websocket-core-server + ${project.version} + + + org.eclipse.jetty.websocket + websocket-core-client + ${project.version} + + + \ No newline at end of file diff --git a/tests/test-jpms/test-websocket-core/src/main/java/module-info.java b/tests/test-jpms/test-websocket-core/src/main/java/module-info.java new file mode 100644 index 00000000000..33471bc1ce4 --- /dev/null +++ b/tests/test-jpms/test-websocket-core/src/main/java/module-info.java @@ -0,0 +1,7 @@ +module org.eclipse.jetty.websocket.core.tests +{ + exports org.example.websocket; + + requires org.eclipse.jetty.websocket.core.server; + requires org.eclipse.jetty.websocket.core.client; +} \ No newline at end of file diff --git a/tests/test-jpms/test-websocket-core/src/main/java/org/example/websocket/MyFrameHandler.java b/tests/test-jpms/test-websocket-core/src/main/java/org/example/websocket/MyFrameHandler.java new file mode 100644 index 00000000000..d02b7e593bd --- /dev/null +++ b/tests/test-jpms/test-websocket-core/src/main/java/org/example/websocket/MyFrameHandler.java @@ -0,0 +1,62 @@ +// +// ======================================================================== +// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.example.websocket; + +import org.eclipse.jetty.util.Callback; +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.FrameHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MyFrameHandler implements FrameHandler +{ + private static final Logger LOG = LoggerFactory.getLogger(MyFrameHandler.class); + + private final String _id; + + public MyFrameHandler(String id) + { + _id = id; + } + + @Override + public void onOpen(CoreSession coreSession, Callback callback) + { + LOG.info(_id + " onOpen"); + callback.succeeded(); + } + + @Override + public void onFrame(Frame frame, Callback callback) + { + LOG.info(_id + " onFrame"); + callback.succeeded(); + } + + @Override + public void onError(Throwable cause, Callback callback) + { + LOG.info(_id + " onError"); + callback.succeeded(); + } + + @Override + public void onClosed(CloseStatus closeStatus, Callback callback) + { + LOG.info(_id + " onClosed"); + callback.succeeded(); + } +} diff --git a/tests/test-jpms/test-websocket-core/src/test/java/WebSocketCoreJpmsTest.java b/tests/test-jpms/test-websocket-core/src/test/java/WebSocketCoreJpmsTest.java new file mode 100644 index 00000000000..c3884154246 --- /dev/null +++ b/tests/test-jpms/test-websocket-core/src/test/java/WebSocketCoreJpmsTest.java @@ -0,0 +1,72 @@ +// +// ======================================================================== +// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +import java.net.URI; +import java.util.concurrent.TimeUnit; + +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.util.Callback; +import org.eclipse.jetty.websocket.core.CoreSession; +import org.eclipse.jetty.websocket.core.FrameHandler; +import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest; +import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient; +import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator; +import org.eclipse.jetty.websocket.core.server.WebSocketUpgradeHandler; +import org.example.websocket.MyFrameHandler; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class WebSocketCoreJpmsTest +{ + private Server _server; + private ServerConnector _serverConnector; + private WebSocketCoreClient _client; + + @BeforeEach + public void before() throws Exception + { + _server = new Server(); + _serverConnector = new ServerConnector(_server); + _server.addConnector(_serverConnector); + + WebSocketUpgradeHandler webSocketUpgradeHandler = new WebSocketUpgradeHandler(); + FrameHandler myFrameHandler = new MyFrameHandler("Server"); + webSocketUpgradeHandler.addMapping("/ws", WebSocketNegotiator.from(negotiation -> myFrameHandler)); + + _server.setHandler(webSocketUpgradeHandler); + _server.start(); + + _client = new WebSocketCoreClient(); + _client.start(); + } + + @AfterEach + public void after() throws Exception + { + _client.stop(); + _server.stop(); + } + + @Test + public void testSimpleEcho() throws Exception + { + MyFrameHandler frameHandler = new MyFrameHandler("Client"); + URI uri = URI.create("ws://localhost:" + _serverConnector.getLocalPort() + "/ws"); + CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, uri, frameHandler); + upgradeRequest.addExtensions("permessage-deflate"); + CoreSession coreSession = _client.connect(upgradeRequest).get(5, TimeUnit.SECONDS); + coreSession.close(Callback.NOOP); + } +} From ead1f6b16073f799cc0523814b5b17bee513b8de Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Mon, 30 Aug 2021 11:12:22 +1000 Subject: [PATCH 2/3] Issue #6601 - export websocket-core-common to jetty-util for DecoratedObjectFactory Signed-off-by: Lachlan Roberts --- .../src/main/java/module-info.java | 3 ++- pom.xml | 1 - .../src/main/java/module-info.java | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/jetty-websocket/websocket-core-common/src/main/java/module-info.java b/jetty-websocket/websocket-core-common/src/main/java/module-info.java index 9afd3e526aa..822e3c6c6ac 100644 --- a/jetty-websocket/websocket-core-common/src/main/java/module-info.java +++ b/jetty-websocket/websocket-core-common/src/main/java/module-info.java @@ -24,7 +24,8 @@ module org.eclipse.jetty.websocket.core.common exports org.eclipse.jetty.websocket.core.internal to org.eclipse.jetty.websocket.core.client, - org.eclipse.jetty.websocket.core.server; + org.eclipse.jetty.websocket.core.server, + org.eclipse.jetty.util; // Export to DecoratedObjectFactory. // The Jetty & Javax API Layers need to access both access some internal utilities which we don't want to expose. exports org.eclipse.jetty.websocket.core.internal.util to diff --git a/pom.xml b/pom.xml index 885e54b8fd5..7f3a5be5a4e 100644 --- a/pom.xml +++ b/pom.xml @@ -153,7 +153,6 @@ documentation jetty-keystore jetty-unixdomain-server - test-websocket-core diff --git a/tests/test-jpms/test-websocket-core/src/main/java/module-info.java b/tests/test-jpms/test-websocket-core/src/main/java/module-info.java index 33471bc1ce4..bf90ab65d56 100644 --- a/tests/test-jpms/test-websocket-core/src/main/java/module-info.java +++ b/tests/test-jpms/test-websocket-core/src/main/java/module-info.java @@ -1,3 +1,16 @@ +// +// ======================================================================== +// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + module org.eclipse.jetty.websocket.core.tests { exports org.example.websocket; From 59a5b7c9efce41638c0eb88605a11c1792551af8 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Tue, 31 Aug 2021 11:28:59 +1000 Subject: [PATCH 3/3] Changes from review. Signed-off-by: Lachlan Roberts --- tests/test-jpms/pom.xml | 2 +- .../pom.xml | 4 +- .../src/main/java/module-info.java | 8 ++- .../src/test/java/WebSocketCoreJPMSTest.java} | 51 +++++++++++++-- .../org/example/websocket/MyFrameHandler.java | 62 ------------------- 5 files changed, 55 insertions(+), 72 deletions(-) rename tests/test-jpms/{test-websocket-core => test-jpms-websocket-core}/pom.xml (93%) rename tests/test-jpms/{test-websocket-core => test-jpms-websocket-core}/src/main/java/module-info.java (81%) rename tests/test-jpms/{test-websocket-core/src/test/java/WebSocketCoreJpmsTest.java => test-jpms-websocket-core/src/test/java/WebSocketCoreJPMSTest.java} (65%) delete mode 100644 tests/test-jpms/test-websocket-core/src/main/java/org/example/websocket/MyFrameHandler.java diff --git a/tests/test-jpms/pom.xml b/tests/test-jpms/pom.xml index abe7e8d2b0c..0acfe67a511 100644 --- a/tests/test-jpms/pom.xml +++ b/tests/test-jpms/pom.xml @@ -10,7 +10,7 @@ pom Jetty Tests :: JPMS Parent - test-websocket-core + test-jpms-websocket-core diff --git a/tests/test-jpms/test-websocket-core/pom.xml b/tests/test-jpms/test-jpms-websocket-core/pom.xml similarity index 93% rename from tests/test-jpms/test-websocket-core/pom.xml rename to tests/test-jpms/test-jpms-websocket-core/pom.xml index 903d38e64fd..93f862c4c1e 100644 --- a/tests/test-jpms/test-websocket-core/pom.xml +++ b/tests/test-jpms/test-jpms-websocket-core/pom.xml @@ -6,7 +6,7 @@ 10.0.7-SNAPSHOT 4.0.0 - test-websocket-core + test-jpms-websocket-core jar Jetty Tests :: JPMS :: WebSocket Core Tests @@ -22,4 +22,4 @@ ${project.version} - \ No newline at end of file + diff --git a/tests/test-jpms/test-websocket-core/src/main/java/module-info.java b/tests/test-jpms/test-jpms-websocket-core/src/main/java/module-info.java similarity index 81% rename from tests/test-jpms/test-websocket-core/src/main/java/module-info.java rename to tests/test-jpms/test-jpms-websocket-core/src/main/java/module-info.java index bf90ab65d56..c10573d1531 100644 --- a/tests/test-jpms/test-websocket-core/src/main/java/module-info.java +++ b/tests/test-jpms/test-jpms-websocket-core/src/main/java/module-info.java @@ -11,10 +11,12 @@ // ======================================================================== // +/** + * This module-info.java exists so that the tests can be run in JPMS mode, + * therefore testing the JPMS module descriptors of the dependencies involved. + */ module org.eclipse.jetty.websocket.core.tests { - exports org.example.websocket; - requires org.eclipse.jetty.websocket.core.server; requires org.eclipse.jetty.websocket.core.client; -} \ No newline at end of file +} diff --git a/tests/test-jpms/test-websocket-core/src/test/java/WebSocketCoreJpmsTest.java b/tests/test-jpms/test-jpms-websocket-core/src/test/java/WebSocketCoreJPMSTest.java similarity index 65% rename from tests/test-jpms/test-websocket-core/src/test/java/WebSocketCoreJpmsTest.java rename to tests/test-jpms/test-jpms-websocket-core/src/test/java/WebSocketCoreJPMSTest.java index c3884154246..f5533189a2d 100644 --- a/tests/test-jpms/test-websocket-core/src/test/java/WebSocketCoreJpmsTest.java +++ b/tests/test-jpms/test-jpms-websocket-core/src/test/java/WebSocketCoreJPMSTest.java @@ -17,18 +17,21 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.util.Callback; +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.FrameHandler; import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest; import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient; import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator; import org.eclipse.jetty.websocket.core.server.WebSocketUpgradeHandler; -import org.example.websocket.MyFrameHandler; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -public class WebSocketCoreJpmsTest +public class WebSocketCoreJPMSTest { private Server _server; private ServerConnector _serverConnector; @@ -42,7 +45,7 @@ public class WebSocketCoreJpmsTest _server.addConnector(_serverConnector); WebSocketUpgradeHandler webSocketUpgradeHandler = new WebSocketUpgradeHandler(); - FrameHandler myFrameHandler = new MyFrameHandler("Server"); + FrameHandler myFrameHandler = new TestFrameHandler("Server"); webSocketUpgradeHandler.addMapping("/ws", WebSocketNegotiator.from(negotiation -> myFrameHandler)); _server.setHandler(webSocketUpgradeHandler); @@ -62,11 +65,51 @@ public class WebSocketCoreJpmsTest @Test public void testSimpleEcho() throws Exception { - MyFrameHandler frameHandler = new MyFrameHandler("Client"); + TestFrameHandler frameHandler = new TestFrameHandler("Client"); URI uri = URI.create("ws://localhost:" + _serverConnector.getLocalPort() + "/ws"); CoreClientUpgradeRequest upgradeRequest = CoreClientUpgradeRequest.from(_client, uri, frameHandler); upgradeRequest.addExtensions("permessage-deflate"); CoreSession coreSession = _client.connect(upgradeRequest).get(5, TimeUnit.SECONDS); coreSession.close(Callback.NOOP); } + + public static class TestFrameHandler implements FrameHandler + { + private static final Logger LOG = LoggerFactory.getLogger(TestFrameHandler.class); + + private final String _id; + + public TestFrameHandler(String id) + { + _id = id; + } + + @Override + public void onOpen(CoreSession coreSession, Callback callback) + { + LOG.info(_id + " onOpen"); + callback.succeeded(); + } + + @Override + public void onFrame(Frame frame, Callback callback) + { + LOG.info(_id + " onFrame"); + callback.succeeded(); + } + + @Override + public void onError(Throwable cause, Callback callback) + { + LOG.info(_id + " onError"); + callback.succeeded(); + } + + @Override + public void onClosed(CloseStatus closeStatus, Callback callback) + { + LOG.info(_id + " onClosed"); + callback.succeeded(); + } + } } diff --git a/tests/test-jpms/test-websocket-core/src/main/java/org/example/websocket/MyFrameHandler.java b/tests/test-jpms/test-websocket-core/src/main/java/org/example/websocket/MyFrameHandler.java deleted file mode 100644 index d02b7e593bd..00000000000 --- a/tests/test-jpms/test-websocket-core/src/main/java/org/example/websocket/MyFrameHandler.java +++ /dev/null @@ -1,62 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.example.websocket; - -import org.eclipse.jetty.util.Callback; -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.FrameHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class MyFrameHandler implements FrameHandler -{ - private static final Logger LOG = LoggerFactory.getLogger(MyFrameHandler.class); - - private final String _id; - - public MyFrameHandler(String id) - { - _id = id; - } - - @Override - public void onOpen(CoreSession coreSession, Callback callback) - { - LOG.info(_id + " onOpen"); - callback.succeeded(); - } - - @Override - public void onFrame(Frame frame, Callback callback) - { - LOG.info(_id + " onFrame"); - callback.succeeded(); - } - - @Override - public void onError(Throwable cause, Callback callback) - { - LOG.info(_id + " onError"); - callback.succeeded(); - } - - @Override - public void onClosed(CloseStatus closeStatus, Callback callback) - { - LOG.info(_id + " onClosed"); - callback.succeeded(); - } -}