diff --git a/Jenkinsfile-autobahn b/Jenkinsfile-autobahn
index 0e92efd217d..eee85b9bbbe 100644
--- a/Jenkinsfile-autobahn
+++ b/Jenkinsfile-autobahn
@@ -10,8 +10,17 @@ pipeline {
// save some io during the build
durabilityHint( 'PERFORMANCE_OPTIMIZED' )
}
+ parameters {
+ string( defaultValue: 'jetty-10.0.x', description: 'GIT branch name to build (jetty-10.0.x/jetty-11.0.x/etc.)',
+ name: 'JETTY_BRANCH' )
+ }
stages {
+ stage("Checkout Jetty Branch") {
+ steps {
+ git url: 'https://github.com/eclipse/jetty.project/', branch: '${JETTY_BRANCH}'
+ }
+ }
stage( "Build / Test - JDK11" ) {
agent {
node { label 'linux' }
@@ -19,8 +28,14 @@ pipeline {
steps {
container( 'jetty-build' ) {
timeout( time: 120, unit: 'MINUTES' ) {
- mavenBuild( "jdk11", "-T3 clean install -Djacoco.skip=true -Pautobahn", "maven3", true ) //
+ mavenBuild( "jdk11", "-T3 clean install -Djacoco.skip=true -pl :test-websocket-autobahn -am -Pautobahn -Dtest=AutobahnTests", "maven3" ) //
junit testResults: '**/target/surefire-reports/*.xml,**/target/invoker-reports/TEST*.xml,**/target/autobahntestsuite-reports/*.xml'
+ publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, keepAll: true, reportDir: "${env.WORKSPACE}/tests/test-websocket-autobahn/target/reports/core/servers", reportFiles: 'index.html', reportName: 'Autobahn Report Core Server', reportTitles: ''])
+ publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, keepAll: true, reportDir: "${env.WORKSPACE}/tests/test-websocket-autobahn/target/reports/core/clients", reportFiles: 'index.html', reportName: 'Autobahn Report Core Client', reportTitles: ''])
+ publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, keepAll: true, reportDir: "${env.WORKSPACE}/tests/test-websocket-autobahn/target/reports/javax/servers", reportFiles: 'index.html', reportName: 'Autobahn Report Javax Server', reportTitles: ''])
+ publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, keepAll: true, reportDir: "${env.WORKSPACE}/tests/test-websocket-autobahn/target/reports/javax/clients", reportFiles: 'index.html', reportName: 'Autobahn Report Javax Client', reportTitles: ''])
+ publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, keepAll: true, reportDir: "${env.WORKSPACE}/tests/test-websocket-autobahn/target/reports/jetty/servers", reportFiles: 'index.html', reportName: 'Autobahn Report Jetty Server', reportTitles: ''])
+ publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, keepAll: true, reportDir: "${env.WORKSPACE}/tests/test-websocket-autobahn/target/reports/jetty/clients", reportFiles: 'index.html', reportName: 'Autobahn Report Jetty Client', reportTitles: ''])
}
}
}
@@ -68,19 +83,16 @@ def slackNotif() {
* @paran mvnName maven installation to use
* @return the Jenkinsfile step representing a maven build
*/
-def mavenBuild(jdk, cmdline, mvnName, junitPublishDisabled) {
- def localRepo = ".repository"
- def mavenOpts = '-Xms1g -Xmx4g -Djava.awt.headless=true'
-
- withMaven(
- maven: mvnName,
- jdk: "$jdk",
- publisherStrategy: 'EXPLICIT',
- options: [junitPublisher(disabled: junitPublishDisabled), mavenLinkerPublisher(disabled: false), pipelineGraphPublisher(disabled: false)],
- mavenOpts: mavenOpts,
- mavenLocalRepo: localRepo) {
- // Some common Maven command line + provided command line
- sh "mvn -Pci -V -B -e -fae -Dmaven.test.failure.ignore=true -Djetty.testtracker.log=true $cmdline"
+def mavenBuild(jdk, cmdline, mvnName) {
+ script {
+ withEnv(["JAVA_HOME=${ tool "$jdk" }",
+ "PATH+MAVEN=${ tool "$jdk" }/bin:${tool "$mvnName"}/bin",
+ "MAVEN_OPTS=-Xms2g -Xmx8g -Djava.awt.headless=true"]) {
+ configFileProvider(
+ [configFile(fileId: 'oss-settings.xml', variable: 'GLOBAL_MVN_SETTINGS')]) {
+ sh "mvn -Denforcer.skip=true -Dlicense.skip=true -Dspotbugs.skip=true -Dcheckstyle.skip=true --no-transfer-progress -s $GLOBAL_MVN_SETTINGS -Dmaven.repo.local=.repository -Pci -V -B -e -Djetty.testtracker.log=true $cmdline"
+ }
+ }
}
}
diff --git a/jetty-websocket/websocket-core-tests/pom.xml b/jetty-websocket/websocket-core-tests/pom.xml
index 29c9f54648c..de45c23180e 100644
--- a/jetty-websocket/websocket-core-tests/pom.xml
+++ b/jetty-websocket/websocket-core-tests/pom.xml
@@ -37,42 +37,9 @@
jetty-slf4j-impl
test
-
- org.testcontainers
- testcontainers
- test
-
-
- org.testcontainers
- junit-jupiter
- test
-
-
- com.googlecode.json-simple
- json-simple
- test
-
-
- org.codehaus.plexus
- plexus-utils
- test
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
- **/AutobahnTests**
-
-
-
-
-
org.apache.maven.plugins
@@ -92,30 +59,4 @@
-
-
- autobahn
-
-
- autobahn
- true
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
- none
-
-
-
-
-
-
-
-
diff --git a/jetty-websocket/websocket-jakarta-tests/fuzzingclient.json b/jetty-websocket/websocket-jakarta-tests/fuzzingclient.json
deleted file mode 100644
index 74ebfa90a9c..00000000000
--- a/jetty-websocket/websocket-jakarta-tests/fuzzingclient.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "options": {
- "failByDrop": false
- },
- "outdir": "./target/reports/servers",
- "servers": [
- {
- "agent": "Jetty-11.0.0-SNAPSHOT",
- "url": "ws://127.0.0.1:9001",
- "options": {
- "version": 18
- }
- }
- ],
- "cases": ["*"],
- "exclude-cases": [],
- "exclude-agent-cases": {}
-}
diff --git a/jetty-websocket/websocket-jakarta-tests/fuzzingserver.json b/jetty-websocket/websocket-jakarta-tests/fuzzingserver.json
deleted file mode 100644
index ade31281937..00000000000
--- a/jetty-websocket/websocket-jakarta-tests/fuzzingserver.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "options": {
- "failByDrop": false
- },
- "url": "ws://127.0.0.1:9001",
- "outdir": "./target/reports/clients",
- "cases": ["*"],
- "exclude-cases": [],
- "exclude-agent-cases": {}
-}
diff --git a/jetty-websocket/websocket-jetty-tests/fuzzingclient.json b/jetty-websocket/websocket-jetty-tests/fuzzingclient.json
deleted file mode 100644
index 74ebfa90a9c..00000000000
--- a/jetty-websocket/websocket-jetty-tests/fuzzingclient.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "options": {
- "failByDrop": false
- },
- "outdir": "./target/reports/servers",
- "servers": [
- {
- "agent": "Jetty-11.0.0-SNAPSHOT",
- "url": "ws://127.0.0.1:9001",
- "options": {
- "version": 18
- }
- }
- ],
- "cases": ["*"],
- "exclude-cases": [],
- "exclude-agent-cases": {}
-}
diff --git a/jetty-websocket/websocket-jetty-tests/fuzzingserver.json b/jetty-websocket/websocket-jetty-tests/fuzzingserver.json
deleted file mode 100644
index ade31281937..00000000000
--- a/jetty-websocket/websocket-jetty-tests/fuzzingserver.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "options": {
- "failByDrop": false
- },
- "url": "ws://127.0.0.1:9001",
- "outdir": "./target/reports/clients",
- "cases": ["*"],
- "exclude-cases": [],
- "exclude-agent-cases": {}
-}
diff --git a/pom.xml b/pom.xml
index b637bf4f675..67ab1766a25 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,7 +33,7 @@
4.1.1
5.3.0
1.5
- 9.2.1
+ 9.3
1.15
1.21
2.11.0
diff --git a/tests/pom.xml b/tests/pom.xml
index 7bf99d5e104..e6a6f5a5346 100644
--- a/tests/pom.xml
+++ b/tests/pom.xml
@@ -58,5 +58,7 @@
test-cdi
test-jndi
test-jpms
+ test-websocket-autobahn
+
diff --git a/tests/test-distribution/pom.xml b/tests/test-distribution/pom.xml
index 82d9420e229..f1ca3ee927d 100644
--- a/tests/test-distribution/pom.xml
+++ b/tests/test-distribution/pom.xml
@@ -7,6 +7,7 @@
4.0.0
test-distribution
+ Jetty Tests :: Distribution Tests
jar
diff --git a/tests/test-jpms/pom.xml b/tests/test-jpms/pom.xml
index 08e668b23e2..a96bbd81960 100644
--- a/tests/test-jpms/pom.xml
+++ b/tests/test-jpms/pom.xml
@@ -8,7 +8,7 @@
4.0.0
test-jpms
pom
- Jetty Tests :: JPMS Parent
+ Jetty Tests :: JPMS
test-jpms-websocket-core
diff --git a/jetty-websocket/websocket-core-tests/fuzzingclient.json b/tests/test-websocket-autobahn/fuzzingclient.json
similarity index 100%
rename from jetty-websocket/websocket-core-tests/fuzzingclient.json
rename to tests/test-websocket-autobahn/fuzzingclient.json
diff --git a/jetty-websocket/websocket-core-tests/fuzzingserver.json b/tests/test-websocket-autobahn/fuzzingserver.json
similarity index 100%
rename from jetty-websocket/websocket-core-tests/fuzzingserver.json
rename to tests/test-websocket-autobahn/fuzzingserver.json
diff --git a/tests/test-websocket-autobahn/pom.xml b/tests/test-websocket-autobahn/pom.xml
new file mode 100644
index 00000000000..fe9020d3d98
--- /dev/null
+++ b/tests/test-websocket-autobahn/pom.xml
@@ -0,0 +1,143 @@
+
+
+
+ org.eclipse.jetty.tests
+ tests-parent
+ 11.0.8-SNAPSHOT
+
+
+ 4.0.0
+ test-websocket-autobahn
+ Jetty Tests :: WebSocket Autobahn Tests
+ Run of Autobahn Testsuite for Jetty
+
+
+
+ org.eclipse.jetty
+ jetty-server
+ test
+
+
+ org.eclipse.jetty
+ jetty-servlet
+ test
+
+
+ org.eclipse.jetty
+ jetty-util
+ test
+
+
+ org.eclipse.jetty.websocket
+ websocket-jetty-client
+ test
+
+
+ org.eclipse.jetty.websocket
+ websocket-jetty-server
+ test
+
+
+ org.eclipse.jetty.websocket
+ websocket-jakarta-client
+ test
+
+
+ org.eclipse.jetty.websocket
+ websocket-jakarta-server
+ test
+
+
+ org.testcontainers
+ testcontainers
+ test
+
+
+ org.testcontainers
+ junit-jupiter
+ test
+
+
+ org.codehaus.plexus
+ plexus-utils
+ test
+
+
+ com.googlecode.json-simple
+ json-simple
+ test
+
+
+ org.slf4j
+ slf4j-simple
+ test
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ **/AutobahnTests**
+
+
+
+
+
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ true
+
+
+
+ manifest
+
+
+
+ jetty.websocket Autobahn Tests
+
+ org.eclipse.jetty.websocket.jetty.tests.*;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}"
+
+
+
+
+
+
+
+
+
+
+
+ autobahn
+
+
+ autobahn
+ true
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ 10800
+
+ none
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/AutobahnClient.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/AutobahnClient.java
new file mode 100644
index 00000000000..db77cc086d2
--- /dev/null
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/AutobahnClient.java
@@ -0,0 +1,19 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2022 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.eclipse.jetty.websocket.tests;
+
+public interface AutobahnClient
+{
+ void runAutobahnClient(String hostname, int port, int[] caseNumbers);
+}
diff --git a/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/AutobahnServer.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/AutobahnServer.java
new file mode 100644
index 00000000000..c7481b3dd38
--- /dev/null
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/AutobahnServer.java
@@ -0,0 +1,21 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2022 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.eclipse.jetty.websocket.tests;
+
+public interface AutobahnServer
+{
+ void startAutobahnServer(int port) throws Exception;
+
+ void stopAutobahnServer() throws Exception;
+}
diff --git a/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/AutobahnTests.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/AutobahnTests.java
new file mode 100644
index 00000000000..44ac7993802
--- /dev/null
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/AutobahnTests.java
@@ -0,0 +1,160 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2022 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.eclipse.jetty.websocket.tests;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.time.Duration;
+import java.util.List;
+
+import com.github.dockerjava.api.DockerClient;
+import org.eclipse.jetty.util.IO;
+import org.eclipse.jetty.websocket.tests.core.CoreAutobahnClient;
+import org.eclipse.jetty.websocket.tests.core.CoreAutobahnServer;
+import org.eclipse.jetty.websocket.tests.jakarta.JakartaAutobahnClient;
+import org.eclipse.jetty.websocket.tests.jakarta.JakartaAutobahnServer;
+import org.eclipse.jetty.websocket.tests.jetty.JettyAutobahnClient;
+import org.eclipse.jetty.websocket.tests.jetty.JettyAutobahnServer;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.utility.DockerImageName;
+import org.testcontainers.utility.MountableFile;
+
+import static org.eclipse.jetty.websocket.tests.AutobahnUtils.copyFromContainer;
+import static org.eclipse.jetty.websocket.tests.AutobahnUtils.parseResults;
+import static org.eclipse.jetty.websocket.tests.AutobahnUtils.throwIfFailed;
+import static org.eclipse.jetty.websocket.tests.AutobahnUtils.writeJUnitXmlReport;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@Testcontainers(disabledWithoutDocker = true)
+public class AutobahnTests
+{
+ private static final Logger LOG = LoggerFactory.getLogger(AutobahnTests.class);
+ private static final Path USER_DIR = Paths.get(System.getProperty("user.dir"));
+
+ private Path reportDir;
+ private Path fuzzingServer;
+ private Path fuzzingClient;
+
+ private AutobahnServer server;
+ private AutobahnClient client;
+
+ @BeforeAll
+ public static void clean()
+ {
+ Path reportDir = USER_DIR.resolve("target/reports");
+ IO.delete(reportDir.toFile());
+ }
+
+ public void setup(String version) throws Exception
+ {
+ fuzzingServer = USER_DIR.resolve("fuzzingserver.json");
+ assertTrue(Files.exists(fuzzingServer), fuzzingServer + " not exists");
+
+ fuzzingClient = USER_DIR.resolve("fuzzingclient.json");
+ assertTrue(Files.exists(fuzzingClient), fuzzingClient + " not exists");
+
+ reportDir = USER_DIR.resolve("target/reports/" + version);
+ if (!Files.exists(reportDir))
+ Files.createDirectories(reportDir);
+
+ switch (version)
+ {
+ case "jetty":
+ server = new JettyAutobahnServer();
+ client = new JettyAutobahnClient();
+ break;
+ case "jakarta":
+ server = new JakartaAutobahnServer();
+ client = new JakartaAutobahnClient();
+ break;
+ case "core":
+ server = new CoreAutobahnServer();
+ client = new CoreAutobahnClient();
+ break;
+ default:
+ throw new IllegalStateException(version);
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"core", "jetty", "jakarta"})
+ public void testClient(String version) throws Exception
+ {
+ setup(version);
+
+ try (GenericContainer> container = new GenericContainer<>(DockerImageName.parse("jettyproject/autobahn-testsuite:latest"))
+ .withCommand("/bin/bash", "-c", "wstest -m fuzzingserver -s /config/fuzzingserver.json")
+ .withExposedPorts(9001)
+ .withCopyFileToContainer(MountableFile.forHostPath(fuzzingServer), "/config/fuzzingserver.json")
+ .withLogConsumer(new Slf4jLogConsumer(LOG))
+ .withStartupTimeout(Duration.ofHours(2)))
+ {
+ container.start();
+ Integer mappedPort = container.getMappedPort(9001);
+ client.runAutobahnClient(container.getContainerIpAddress(), mappedPort, null);
+
+ DockerClient dockerClient = container.getDockerClient();
+ String containerId = container.getContainerId();
+ copyFromContainer(dockerClient, containerId, reportDir, Paths.get("/target/reports/clients"));
+ }
+
+ LOG.info("Test Result Overview {}", reportDir.resolve("clients/index.html").toUri());
+ List results = parseResults(reportDir.resolve("clients/index.json"));
+ String className = getClass().getName();
+ writeJUnitXmlReport(results, version + "-autobahn-client", className + ".client");
+ throwIfFailed(results);
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"core", "jetty", "jakarta"})
+ public void testServer(String version) throws Exception
+ {
+ setup(version);
+
+ // We need to expose the host port of the server to the Autobahn Client in docker container.
+ final int port = 9001;
+ org.testcontainers.Testcontainers.exposeHostPorts(port);
+ server.startAutobahnServer(port);
+
+ AutobahnUtils.FileSignalWaitStrategy strategy = new AutobahnUtils.FileSignalWaitStrategy(reportDir, Paths.get("/target/reports/servers"));
+ try (GenericContainer> container = new GenericContainer<>(DockerImageName.parse("jettyproject/autobahn-testsuite:latest"))
+ .withCommand("/bin/bash", "-c", "wstest -m fuzzingclient -s /config/fuzzingclient.json" + AutobahnUtils.FileSignalWaitStrategy.END_COMMAND)
+ .withLogConsumer(new Slf4jLogConsumer(LOG))
+ .withCopyFileToContainer(MountableFile.forHostPath(fuzzingClient), "/config/fuzzingclient.json")
+ .withStartupCheckStrategy(strategy)
+ .withStartupTimeout(Duration.ofHours(2)))
+ {
+ container.start();
+ }
+ finally
+ {
+ server.stopAutobahnServer();
+ }
+
+ LOG.info("Test Result Overview {}", reportDir.resolve("servers/index.html").toUri());
+ List results = parseResults(reportDir.resolve("servers/index.json"));
+ String className = getClass().getName();
+ writeJUnitXmlReport(results, version + "-autobahn-server", className + ".server");
+ throwIfFailed(results);
+ }
+}
diff --git a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnTests.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/AutobahnUtils.java
similarity index 68%
rename from jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnTests.java
rename to tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/AutobahnUtils.java
index fe768ce4397..7b0f356369e 100644
--- a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnTests.java
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/AutobahnUtils.java
@@ -11,7 +11,7 @@
// ========================================================================
//
-package org.eclipse.jetty.websocket.core.autobahn;
+package org.eclipse.jetty.websocket.tests;
import java.io.File;
import java.io.FileNotFoundException;
@@ -31,110 +31,19 @@ import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomWriter;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.util.IO;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Disabled;
-import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.testcontainers.containers.GenericContainer;
-import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.startupcheck.StartupCheckStrategy;
-import org.testcontainers.junit.jupiter.Testcontainers;
-import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.DockerStatus;
-import org.testcontainers.utility.MountableFile;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-@Disabled("Disable this test so it doesn't run locally as it takes 1h+ to run.")
-@Testcontainers
-public class AutobahnTests
+public class AutobahnUtils
{
- private static final Logger LOG = LoggerFactory.getLogger(AutobahnTests.class);
- private static final Path USER_DIR = Paths.get(System.getProperty("user.dir"));
+ private static final Logger LOG = LoggerFactory.getLogger(AutobahnUtils.class);
- private static Path reportDir;
- private static Path fuzzingServer;
- private static Path fuzzingClient;
-
- @BeforeAll
- public static void before() throws Exception
- {
- fuzzingServer = USER_DIR.resolve("fuzzingserver.json");
- assertTrue(Files.exists(fuzzingServer), fuzzingServer + " not exists");
-
- fuzzingClient = USER_DIR.resolve("fuzzingclient.json");
- assertTrue(Files.exists(fuzzingClient), fuzzingClient + " not exists");
-
- reportDir = USER_DIR.resolve("target/reports");
- IO.delete(reportDir.toFile());
- Files.createDirectory(reportDir);
- }
-
- @Test
- public void testClient() throws Exception
- {
- try (GenericContainer> container = new GenericContainer<>(DockerImageName.parse("jettyproject/autobahn-testsuite:latest"))
- .withCommand("/bin/bash", "-c", "wstest -m fuzzingserver -s /config/fuzzingserver.json")
- .withExposedPorts(9001)
- .withCopyFileToContainer(MountableFile.forHostPath(fuzzingServer), "/config/fuzzingserver.json")
- .withLogConsumer(new Slf4jLogConsumer(LOG))
- .withStartupTimeout(Duration.ofHours(2)))
- {
- container.start();
- Integer mappedPort = container.getMappedPort(9001);
- CoreAutobahnClient.main(new String[]{container.getContainerIpAddress(), mappedPort.toString()});
-
- DockerClient dockerClient = container.getDockerClient();
- String containerId = container.getContainerId();
- copyFromContainer(dockerClient, containerId, reportDir, Paths.get("/target/reports/clients"));
- }
-
- LOG.info("Test Result Overview {}", reportDir.resolve("clients/index.html").toUri());
-
- List results = parseResults(Paths.get("target/reports/clients/index.json"));
- String className = getClass().getName();
- writeJUnitXmlReport(results, "autobahn-client", className + ".client");
- throwIfFailed(results);
- }
-
- @Test
- public void testServer() throws Exception
- {
- // We need to expose the host port of the server to the Autobahn Client in docker container.
- final int port = 9001;
- org.testcontainers.Testcontainers.exposeHostPorts(port);
- Server server = CoreAutobahnServer.startAutobahnServer(port);
-
- FileSignalWaitStrategy strategy = new FileSignalWaitStrategy(reportDir, Paths.get("/target/reports/servers"));
- try (GenericContainer> container = new GenericContainer<>(DockerImageName.parse("jettyproject/autobahn-testsuite:latest"))
- .withCommand("/bin/bash", "-c", "wstest -m fuzzingclient -s /config/fuzzingclient.json" + FileSignalWaitStrategy.END_COMMAND)
- .withLogConsumer(new Slf4jLogConsumer(LOG))
- .withCopyFileToContainer(MountableFile.forHostPath(fuzzingClient), "/config/fuzzingclient.json")
- .withStartupCheckStrategy(strategy)
- .withStartupTimeout(Duration.ofHours(2)))
- {
- container.start();
- }
- finally
- {
- server.stop();
- }
-
- LOG.info("Test Result Overview {}", reportDir.resolve("servers/index.html").toUri());
-
- List results = parseResults(Paths.get("target/reports/servers/index.json"));
- String className = getClass().getName();
- writeJUnitXmlReport(results, "autobahn-server", className + ".server");
- throwIfFailed(results);
- }
-
- private void throwIfFailed(List results) throws Exception
+ public static void throwIfFailed(List results) throws Exception
{
StringBuilder message = new StringBuilder();
for (AutobahnCaseResult result : results)
@@ -147,7 +56,7 @@ public class AutobahnTests
throw new Exception("Failed Test Cases: " + message);
}
- private static class FileSignalWaitStrategy extends StartupCheckStrategy
+ public static class FileSignalWaitStrategy extends StartupCheckStrategy
{
public static final String SIGNAL_FILE = "/signalComplete";
public static final String END_COMMAND = " && touch " + SIGNAL_FILE + " && sleep infinity";
@@ -163,7 +72,7 @@ public class AutobahnTests
}
@Override
- public StartupCheckStrategy.StartupStatus checkStartupState(DockerClient dockerClient, String containerId)
+ public StartupStatus checkStartupState(DockerClient dockerClient, String containerId)
{
// If the container was stopped then we have failed to copy out the file.
if (DockerStatus.isContainerStopped(getCurrentState(dockerClient, containerId)))
@@ -196,7 +105,7 @@ public class AutobahnTests
}
}
- private static void copyFromContainer(DockerClient dockerClient, String containerId, Path target, Path source) throws Exception
+ public static void copyFromContainer(DockerClient dockerClient, String containerId, Path target, Path source) throws Exception
{
try (TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(dockerClient
.copyArchiveFromContainerCmd(containerId, source.toString())
@@ -217,8 +126,7 @@ public class AutobahnTests
}
}
- private void writeJUnitXmlReport(List results, String surefireFileName, String testName)
- throws Exception
+ public static void writeJUnitXmlReport(List results, String surefireFileName, String testName) throws Exception
{
int failures = 0;
long suiteDuration = 0;
@@ -259,8 +167,7 @@ public class AutobahnTests
}
}
- private void addFailure(Xpp3Dom testCase, AutobahnCaseResult result) throws IOException,
- ParseException
+ public static void addFailure(Xpp3Dom testCase, AutobahnCaseResult result) throws IOException, ParseException
{
JSONParser parser = new JSONParser();
@@ -292,7 +199,7 @@ public class AutobahnTests
}
}
- private static List parseResults(Path jsonPath) throws Exception
+ public static List parseResults(Path jsonPath) throws Exception
{
List results = new ArrayList<>();
JSONParser parser = new JSONParser();
diff --git a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnFrameHandler.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/core/AutobahnFrameHandler.java
similarity index 94%
rename from jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnFrameHandler.java
rename to tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/core/AutobahnFrameHandler.java
index faa10a797d1..b0251b53e19 100644
--- a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnFrameHandler.java
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/core/AutobahnFrameHandler.java
@@ -11,14 +11,13 @@
// ========================================================================
//
-package org.eclipse.jetty.websocket.core.autobahn;
+package org.eclipse.jetty.websocket.tests.core;
import java.nio.ByteBuffer;
import java.time.Duration;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.CoreSession;
-import org.eclipse.jetty.websocket.core.TestMessageHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/CoreAutobahnClient.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/core/CoreAutobahnClient.java
similarity index 83%
rename from jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/CoreAutobahnClient.java
rename to tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/core/CoreAutobahnClient.java
index a48ed1882f4..a15999a86fb 100644
--- a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/CoreAutobahnClient.java
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/core/CoreAutobahnClient.java
@@ -11,7 +11,7 @@
// ========================================================================
//
-package org.eclipse.jetty.websocket.core.autobahn;
+package org.eclipse.jetty.websocket.tests.core;
import java.net.URI;
import java.util.concurrent.Future;
@@ -23,15 +23,15 @@ import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Jetty;
import org.eclipse.jetty.util.UrlEncoded;
import org.eclipse.jetty.websocket.core.CoreSession;
-import org.eclipse.jetty.websocket.core.TestMessageHandler;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.eclipse.jetty.websocket.core.internal.MessageHandler;
+import org.eclipse.jetty.websocket.tests.AutobahnClient;
+import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* WebSocket Client for use with autobahn websocket testsuite (wstest).
@@ -67,9 +67,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* $ ls target/reports/clients/
*
*/
-public class CoreAutobahnClient
+public class CoreAutobahnClient implements AutobahnClient
{
- public static void main(String[] args) throws Exception
+ public static void main(String[] args)
{
String hostname = "localhost";
int port = 9001;
@@ -92,11 +92,25 @@ public class CoreAutobahnClient
}
}
- CoreAutobahnClient client = null;
+ CoreAutobahnClient client = new CoreAutobahnClient();
+ client.runAutobahnClient(hostname, port, caseNumbers);
+ }
+
+ private static final Logger LOG = LoggerFactory.getLogger(CoreAutobahnClient.class);
+ private URI baseWebsocketUri;
+ private WebSocketCoreClient client;
+ private String userAgent;
+
+ @Override
+ public void runAutobahnClient(String hostname, int port, int[] caseNumbers)
+ {
try
{
- String userAgent = "JettyWebsocketClient/" + Jetty.VERSION;
- client = new CoreAutobahnClient(hostname, port, userAgent);
+ String userAgent = "CoreWebsocketClient/" + Jetty.VERSION;
+ this.userAgent = userAgent;
+ this.baseWebsocketUri = new URI("ws://" + hostname + ":" + port);
+ this.client = new WebSocketCoreClient();
+ this.client.start();
LOG.info("Running test suite...");
LOG.info("Using Fuzzing Server: {}:{}", hostname, port);
@@ -104,12 +118,12 @@ public class CoreAutobahnClient
if (caseNumbers == null)
{
- int caseCount = client.getCaseCount();
+ int caseCount = getCaseCount();
LOG.info("Will run all {} cases ...", caseCount);
for (int caseNum = 1; caseNum <= caseCount; caseNum++)
{
LOG.info("Running case {} (of {}) ...", caseNum, caseCount);
- client.runCaseByNumber(caseNum);
+ runCaseByNumber(caseNum);
}
}
else
@@ -117,48 +131,34 @@ public class CoreAutobahnClient
LOG.info("Will run {} cases ...", caseNumbers.length);
for (int caseNum : caseNumbers)
{
- client.runCaseByNumber(caseNum);
+ runCaseByNumber(caseNum);
}
}
LOG.info("All test cases executed.");
- client.updateReports();
+ updateReports();
}
catch (Throwable t)
{
LOG.warn("Test Failed", t);
- throw t;
}
finally
{
if (client != null)
- client.shutdown();
+ shutdown();
}
}
- private static final Logger LOG = LoggerFactory.getLogger(CoreAutobahnClient.class);
- private final URI baseWebsocketUri;
- private final WebSocketCoreClient client;
- private final String userAgent;
-
- public CoreAutobahnClient(String hostname, int port, String userAgent) throws Exception
- {
- this.userAgent = userAgent;
- this.baseWebsocketUri = new URI("ws://" + hostname + ":" + port);
- this.client = new WebSocketCoreClient();
- this.client.start();
- }
-
public int getCaseCount() throws Exception
{
URI wsUri = baseWebsocketUri.resolve("/getCaseCount");
TestMessageHandler onCaseCount = new TestMessageHandler();
CoreSession session = upgrade(onCaseCount, wsUri).get(5, TimeUnit.SECONDS);
- assertTrue(onCaseCount.openLatch.await(5, TimeUnit.SECONDS));
+ Assertions.assertTrue(onCaseCount.openLatch.await(5, TimeUnit.SECONDS));
String msg = onCaseCount.textMessages.poll(5, TimeUnit.SECONDS);
// Close the connection.
session.close(Callback.NOOP);
- assertTrue(onCaseCount.closeLatch.await(5, TimeUnit.SECONDS));
+ Assertions.assertTrue(onCaseCount.closeLatch.await(5, TimeUnit.SECONDS));
assertNotNull(msg);
return Integer.decode(msg);
@@ -208,7 +208,7 @@ public class CoreAutobahnClient
TestMessageHandler onUpdateReports = new TestMessageHandler();
Future response = upgrade(onUpdateReports, wsUri);
response.get(5, TimeUnit.SECONDS);
- assertTrue(onUpdateReports.closeLatch.await(15, TimeUnit.SECONDS));
+ Assertions.assertTrue(onUpdateReports.closeLatch.await(15, TimeUnit.SECONDS));
LOG.info("Reports updated.");
LOG.info("Test suite finished!");
}
diff --git a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/CoreAutobahnServer.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/core/CoreAutobahnServer.java
similarity index 75%
rename from jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/CoreAutobahnServer.java
rename to tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/core/CoreAutobahnServer.java
index 4753d13adc2..38765224529 100644
--- a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/CoreAutobahnServer.java
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/core/CoreAutobahnServer.java
@@ -11,14 +11,13 @@
// ========================================================================
//
-package org.eclipse.jetty.websocket.core.autobahn;
+package org.eclipse.jetty.websocket.tests.core;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
-import org.eclipse.jetty.server.handler.ContextHandler;
-import org.eclipse.jetty.websocket.core.TestWebSocketNegotiator;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.server.WebSocketUpgradeHandler;
+import org.eclipse.jetty.websocket.tests.AutobahnServer;
/**
* WebSocket Server for use with autobahn websocket testsuite (wstest).
@@ -54,7 +53,7 @@ import org.eclipse.jetty.websocket.core.server.WebSocketUpgradeHandler;
* $ ls target/reports/servers/
*
*/
-public class CoreAutobahnServer
+public class CoreAutobahnServer implements AutobahnServer
{
public static void main(String[] args) throws Exception
{
@@ -62,25 +61,36 @@ public class CoreAutobahnServer
if (args != null && args.length > 0)
port = Integer.parseInt(args[0]);
- Server server = startAutobahnServer(port);
+ CoreAutobahnServer server = new CoreAutobahnServer();
+ server.startAutobahnServer(port);
server.join();
}
- public static Server startAutobahnServer(int port) throws Exception
+ private Server _server;
+
+ public void startAutobahnServer(int port) throws Exception
{
- Server server = new Server(port);
- ServerConnector connector = new ServerConnector(server);
- connector.setIdleTimeout(10000);
- server.addConnector(connector);
- ContextHandler context = new ContextHandler("/");
- server.setHandler(context);
+ _server = new Server();
+ ServerConnector connector = new ServerConnector(_server);
+ connector.setPort(port);
+ _server.addConnector(connector);
WebSocketComponents components = new WebSocketComponents();
WebSocketUpgradeHandler handler = new WebSocketUpgradeHandler(components);
handler.addMapping("/*", new TestWebSocketNegotiator(new AutobahnFrameHandler()));
+ _server.setHandler(handler);
- context.setHandler(handler);
- server.start();
- return server;
+ _server.start();
+ }
+
+ @Override
+ public void stopAutobahnServer() throws Exception
+ {
+ _server.stop();
+ }
+
+ public void join() throws InterruptedException
+ {
+ _server.join();
}
}
diff --git a/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/core/TestMessageHandler.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/core/TestMessageHandler.java
new file mode 100644
index 00000000000..1e4ba011062
--- /dev/null
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/core/TestMessageHandler.java
@@ -0,0 +1,82 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2022 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.eclipse.jetty.websocket.tests.core;
+
+import java.nio.ByteBuffer;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CountDownLatch;
+
+import org.eclipse.jetty.util.BlockingArrayQueue;
+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.internal.MessageHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestMessageHandler extends MessageHandler
+{
+ protected static final Logger LOG = LoggerFactory.getLogger(TestMessageHandler.class);
+
+ public CoreSession coreSession;
+ public BlockingQueue textMessages = new BlockingArrayQueue<>();
+ public BlockingQueue binaryMessages = new BlockingArrayQueue<>();
+ public CloseStatus closeStatus;
+ public volatile Throwable error;
+ public CountDownLatch openLatch = new CountDownLatch(1);
+ public CountDownLatch errorLatch = new CountDownLatch(1);
+ public CountDownLatch closeLatch = new CountDownLatch(1);
+
+ @Override
+ public void onOpen(CoreSession coreSession, Callback callback)
+ {
+ super.onOpen(coreSession, callback);
+ this.coreSession = coreSession;
+ openLatch.countDown();
+ }
+
+ @Override
+ public void onError(Throwable cause, Callback callback)
+ {
+ super.onError(cause, callback);
+ error = cause;
+ errorLatch.countDown();
+ }
+
+ @Override
+ public void onClosed(CloseStatus closeStatus, Callback callback)
+ {
+ super.onClosed(closeStatus, callback);
+ this.closeStatus = closeStatus;
+ closeLatch.countDown();
+ }
+
+ @Override
+ protected void onText(String message, Callback callback)
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("onText {}", message);
+ textMessages.offer(message);
+ callback.succeeded();
+ }
+
+ @Override
+ protected void onBinary(ByteBuffer message, Callback callback)
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("onBinary {}", message);
+ binaryMessages.offer(message);
+ callback.succeeded();
+ }
+}
diff --git a/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/core/TestWebSocketNegotiator.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/core/TestWebSocketNegotiator.java
new file mode 100644
index 00000000000..5a7d126ada8
--- /dev/null
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/core/TestWebSocketNegotiator.java
@@ -0,0 +1,47 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2022 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.eclipse.jetty.websocket.tests.core;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.jetty.websocket.core.FrameHandler;
+import org.eclipse.jetty.websocket.core.server.WebSocketNegotiation;
+import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
+
+public class TestWebSocketNegotiator extends WebSocketNegotiator.AbstractNegotiator
+{
+ private final FrameHandler frameHandler;
+
+ public TestWebSocketNegotiator(FrameHandler frameHandler)
+ {
+ this(frameHandler, null);
+ }
+
+ public TestWebSocketNegotiator(FrameHandler frameHandler, Customizer customizer)
+ {
+ super(customizer);
+ this.frameHandler = frameHandler;
+ }
+
+ @Override
+ public FrameHandler negotiate(WebSocketNegotiation negotiation) throws IOException
+ {
+ List offeredSubprotocols = negotiation.getOfferedSubprotocols();
+ if (!offeredSubprotocols.isEmpty())
+ negotiation.setSubprotocol(offeredSubprotocols.get(0));
+
+ return frameHandler;
+ }
+}
diff --git a/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/EchoSocket.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/EchoSocket.java
new file mode 100644
index 00000000000..d27247e67f1
--- /dev/null
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/EchoSocket.java
@@ -0,0 +1,39 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2022 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.eclipse.jetty.websocket.tests.jakarta;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import jakarta.websocket.ClientEndpoint;
+import jakarta.websocket.server.ServerEndpoint;
+
+@ServerEndpoint("/")
+@ClientEndpoint(configurator = HostConfigurator.class)
+public class EchoSocket extends EventSocket
+{
+ @Override
+ public void onMessage(String message) throws IOException
+ {
+ super.onMessage(message);
+ session.getBasicRemote().sendText(message);
+ }
+
+ @Override
+ public void onMessage(ByteBuffer message) throws IOException
+ {
+ super.onMessage(message);
+ session.getBasicRemote().sendBinary(message);
+ }
+}
diff --git a/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/EventSocket.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/EventSocket.java
new file mode 100644
index 00000000000..d3c8352ec37
--- /dev/null
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/EventSocket.java
@@ -0,0 +1,96 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2022 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.eclipse.jetty.websocket.tests.jakarta;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CountDownLatch;
+
+import jakarta.websocket.ClientEndpoint;
+import jakarta.websocket.CloseReason;
+import jakarta.websocket.EndpointConfig;
+import jakarta.websocket.OnClose;
+import jakarta.websocket.OnError;
+import jakarta.websocket.OnMessage;
+import jakarta.websocket.OnOpen;
+import jakarta.websocket.Session;
+import jakarta.websocket.server.ServerEndpoint;
+import org.eclipse.jetty.util.BlockingArrayQueue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@ServerEndpoint("/")
+@ClientEndpoint(configurator = HostConfigurator.class)
+public class EventSocket
+{
+ private static final Logger LOG = LoggerFactory.getLogger(EventSocket.class);
+
+ public Session session;
+ public EndpointConfig endpointConfig;
+
+ public BlockingQueue textMessages = new BlockingArrayQueue<>();
+ public BlockingQueue binaryMessages = new BlockingArrayQueue<>();
+ public volatile Throwable error = null;
+ public volatile CloseReason closeReason = null;
+
+ public CountDownLatch openLatch = new CountDownLatch(1);
+ public CountDownLatch closeLatch = new CountDownLatch(1);
+ public CountDownLatch errorLatch = new CountDownLatch(1);
+
+ @OnOpen
+ public void onOpen(Session session, EndpointConfig endpointConfig)
+ {
+ this.session = session;
+ this.endpointConfig = endpointConfig;
+ if (LOG.isDebugEnabled())
+ LOG.debug("{} onOpen(): {}", toString(), session);
+ openLatch.countDown();
+ }
+
+ @OnMessage
+ public void onMessage(String message) throws IOException
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("{} onMessage(): {}", toString(), message);
+ textMessages.offer(message);
+ }
+
+ @OnMessage
+ public void onMessage(ByteBuffer message) throws IOException
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("{} onMessage(): {}", toString(), message);
+ binaryMessages.offer(message);
+ }
+
+ @OnClose
+ public void onClose(CloseReason reason)
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("{} onClose(): {}", toString(), reason);
+
+ closeReason = reason;
+ closeLatch.countDown();
+ }
+
+ @OnError
+ public void onError(Throwable cause)
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("{} onError(): {}", toString(), cause);
+ error = cause;
+ errorLatch.countDown();
+ }
+}
diff --git a/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/HostConfigurator.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/HostConfigurator.java
new file mode 100644
index 00000000000..3380b25c9be
--- /dev/null
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/HostConfigurator.java
@@ -0,0 +1,30 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2022 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.eclipse.jetty.websocket.tests.jakarta;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import jakarta.websocket.ClientEndpointConfig;
+import org.eclipse.jetty.http.HttpHeader;
+
+public class HostConfigurator extends ClientEndpointConfig.Configurator
+{
+ @Override
+ public void beforeRequest(Map> headers)
+ {
+ headers.put(HttpHeader.HOST.asString(), Collections.singletonList("localhost:9001"));
+ }
+}
diff --git a/jetty-websocket/websocket-jakarta-tests/src/test/java/org/eclipse/jetty/websocket/jakarta/tests/autobahn/JakartaAutobahnClient.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/JakartaAutobahnClient.java
similarity index 85%
rename from jetty-websocket/websocket-jakarta-tests/src/test/java/org/eclipse/jetty/websocket/jakarta/tests/autobahn/JakartaAutobahnClient.java
rename to tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/JakartaAutobahnClient.java
index ecf6df3bb0d..47c8e05eebb 100644
--- a/jetty-websocket/websocket-jakarta-tests/src/test/java/org/eclipse/jetty/websocket/jakarta/tests/autobahn/JakartaAutobahnClient.java
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/JakartaAutobahnClient.java
@@ -11,7 +11,7 @@
// ========================================================================
//
-package org.eclipse.jetty.websocket.jakarta.tests.autobahn;
+package org.eclipse.jetty.websocket.tests.jakarta;
import java.net.URI;
import java.util.concurrent.TimeUnit;
@@ -21,7 +21,8 @@ import org.eclipse.jetty.util.Jetty;
import org.eclipse.jetty.util.UrlEncoded;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.websocket.jakarta.client.internal.JakartaWebSocketClientContainer;
-import org.eclipse.jetty.websocket.jakarta.tests.EventSocket;
+import org.eclipse.jetty.websocket.tests.AutobahnClient;
+import org.eclipse.jetty.websocket.tests.jetty.JettyAutobahnClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -62,7 +63,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* $ ls target/reports/clients/
*
*/
-public class JakartaAutobahnClient
+public class JakartaAutobahnClient implements AutobahnClient
{
public static void main(String[] args)
{
@@ -87,11 +88,25 @@ public class JakartaAutobahnClient
}
}
- JakartaAutobahnClient client = null;
+ JettyAutobahnClient client = new JettyAutobahnClient();
+ client.runAutobahnClient(hostname, port, caseNumbers);
+ }
+
+ private static final Logger LOG = LoggerFactory.getLogger(JakartaAutobahnClient.class);
+ private URI baseWebsocketUri;
+ private JakartaWebSocketClientContainer clientContainer;
+ private String userAgent;
+
+ @Override
+ public void runAutobahnClient(String hostname, int port, int[] caseNumbers)
+ {
try
{
- String userAgent = "JettyWebsocketClient/" + Jetty.VERSION;
- client = new JakartaAutobahnClient(hostname, port, userAgent);
+ String userAgent = "JakartaWebsocketClient/" + Jetty.VERSION;
+ this.userAgent = userAgent;
+ this.baseWebsocketUri = new URI("ws://" + hostname + ":" + port);
+ this.clientContainer = new JakartaWebSocketClientContainer();
+ clientContainer.start();
LOG.info("Running test suite...");
LOG.info("Using Fuzzing Server: {}:{}", hostname, port);
@@ -99,12 +114,12 @@ public class JakartaAutobahnClient
if (caseNumbers == null)
{
- int caseCount = client.getCaseCount();
+ int caseCount = getCaseCount();
LOG.info("Will run all {} cases ...", caseCount);
for (int caseNum = 1; caseNum <= caseCount; caseNum++)
{
LOG.info("Running case {} (of {}) ...", caseNum, caseCount);
- client.runCaseByNumber(caseNum);
+ runCaseByNumber(caseNum);
}
}
else
@@ -112,11 +127,11 @@ public class JakartaAutobahnClient
LOG.info("Will run {} cases ...", caseNumbers.length);
for (int caseNum : caseNumbers)
{
- client.runCaseByNumber(caseNum);
+ runCaseByNumber(caseNum);
}
}
LOG.info("All test cases executed.");
- client.updateReports();
+ updateReports();
}
catch (Throwable t)
{
@@ -124,26 +139,11 @@ public class JakartaAutobahnClient
}
finally
{
- if (client != null)
- client.stop();
+ shutdown();
}
}
- private static final Logger LOG = LoggerFactory.getLogger(JakartaAutobahnClient.class);
-
- private URI baseWebsocketUri;
- private JakartaWebSocketClientContainer clientContainer;
- private String userAgent;
-
- public JakartaAutobahnClient(String hostname, int port, String userAgent) throws Exception
- {
- this.userAgent = userAgent;
- this.baseWebsocketUri = new URI("ws://" + hostname + ":" + port);
- this.clientContainer = new JakartaWebSocketClientContainer();
- clientContainer.start();
- }
-
- public void stop()
+ public void shutdown()
{
LifeCycle.stop(clientContainer);
}
diff --git a/jetty-websocket/websocket-jakarta-tests/src/test/java/org/eclipse/jetty/websocket/jakarta/tests/autobahn/JakartaAutobahnServer.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/JakartaAutobahnServer.java
similarity index 75%
rename from jetty-websocket/websocket-jakarta-tests/src/test/java/org/eclipse/jetty/websocket/jakarta/tests/autobahn/JakartaAutobahnServer.java
rename to tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/JakartaAutobahnServer.java
index f0242661e8a..f0043a4a601 100644
--- a/jetty-websocket/websocket-jakarta-tests/src/test/java/org/eclipse/jetty/websocket/jakarta/tests/autobahn/JakartaAutobahnServer.java
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/JakartaAutobahnServer.java
@@ -11,12 +11,13 @@
// ========================================================================
//
-package org.eclipse.jetty.websocket.jakarta.tests.autobahn;
+package org.eclipse.jetty.websocket.tests.jakarta;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.websocket.jakarta.server.config.JakartaWebSocketServletContainerInitializer;
+import org.eclipse.jetty.websocket.tests.AutobahnServer;
/**
* WebSocket Server for use with autobahn websocket testsuite (wstest).
@@ -52,7 +53,7 @@ import org.eclipse.jetty.websocket.jakarta.server.config.JakartaWebSocketServlet
* $ ls target/reports/servers/
*
*/
-public class JakartaAutobahnServer
+public class JakartaAutobahnServer implements AutobahnServer
{
public static void main(String[] args) throws Exception
{
@@ -60,18 +61,38 @@ public class JakartaAutobahnServer
if (args != null && args.length > 0)
port = Integer.parseInt(args[0]);
- Server server = new Server(port);
- ServerConnector connector = new ServerConnector(server);
- connector.setIdleTimeout(10000);
- server.addConnector(connector);
+ JakartaAutobahnServer server = new JakartaAutobahnServer();
+ server.startAutobahnServer(port);
+ server.join();
+ }
+
+ private Server _server;
+
+ public void startAutobahnServer(int port) throws Exception
+ {
+ _server = new Server();
+ ServerConnector connector = new ServerConnector(_server);
+ connector.setPort(port);
+ _server.addConnector(connector);
+
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
- server.setHandler(context);
+ _server.setHandler(context);
JakartaWebSocketServletContainerInitializer.configure(context, (servletContext, container) ->
container.addEndpoint(JakartaAutobahnSocket.class));
- server.start();
- server.join();
+ _server.start();
+ }
+
+ @Override
+ public void stopAutobahnServer() throws Exception
+ {
+ _server.stop();
+ }
+
+ public void join() throws InterruptedException
+ {
+ _server.join();
}
}
diff --git a/jetty-websocket/websocket-jakarta-tests/src/test/java/org/eclipse/jetty/websocket/jakarta/tests/autobahn/JakartaAutobahnSocket.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/JakartaAutobahnSocket.java
similarity index 94%
rename from jetty-websocket/websocket-jakarta-tests/src/test/java/org/eclipse/jetty/websocket/jakarta/tests/autobahn/JakartaAutobahnSocket.java
rename to tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/JakartaAutobahnSocket.java
index 17ec30678f9..703fd7be2ad 100644
--- a/jetty-websocket/websocket-jakarta-tests/src/test/java/org/eclipse/jetty/websocket/jakarta/tests/autobahn/JakartaAutobahnSocket.java
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jakarta/JakartaAutobahnSocket.java
@@ -11,7 +11,7 @@
// ========================================================================
//
-package org.eclipse.jetty.websocket.jakarta.tests.autobahn;
+package org.eclipse.jetty.websocket.tests.jakarta;
import java.io.IOException;
import java.nio.ByteBuffer;
@@ -27,7 +27,7 @@ import jakarta.websocket.server.ServerEndpoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@ClientEndpoint
+@ClientEndpoint(configurator = HostConfigurator.class)
@ServerEndpoint("/")
public class JakartaAutobahnSocket
{
diff --git a/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jetty/EchoSocket.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jetty/EchoSocket.java
new file mode 100644
index 00000000000..e0fe21bebe9
--- /dev/null
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jetty/EchoSocket.java
@@ -0,0 +1,37 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2022 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.eclipse.jetty.websocket.tests.jetty;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.eclipse.jetty.websocket.api.annotations.WebSocket;
+
+@WebSocket
+public class EchoSocket extends EventSocket
+{
+ @Override
+ public void onMessage(String message) throws IOException
+ {
+ super.onMessage(message);
+ session.getRemote().sendString(message);
+ }
+
+ @Override
+ public void onMessage(byte[] buf, int offset, int len) throws IOException
+ {
+ super.onMessage(buf, offset, len);
+ session.getRemote().sendBytes(ByteBuffer.wrap(buf, offset, len));
+ }
+}
diff --git a/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jetty/EventSocket.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jetty/EventSocket.java
new file mode 100644
index 00000000000..efeb6d757a7
--- /dev/null
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jetty/EventSocket.java
@@ -0,0 +1,101 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2022 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.eclipse.jetty.websocket.tests.jetty;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CountDownLatch;
+
+import org.eclipse.jetty.util.BlockingArrayQueue;
+import org.eclipse.jetty.websocket.api.Session;
+import org.eclipse.jetty.websocket.api.StatusCode;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
+import org.eclipse.jetty.websocket.api.annotations.WebSocket;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@WebSocket
+public class EventSocket
+{
+ private static final Logger LOG = LoggerFactory.getLogger(EventSocket.class);
+
+ public Session session;
+ private String behavior;
+
+ public BlockingQueue textMessages = new BlockingArrayQueue<>();
+ public BlockingQueue binaryMessages = new BlockingArrayQueue<>();
+ public volatile int closeCode = StatusCode.UNDEFINED;
+ public volatile String closeReason;
+ public volatile Throwable error = null;
+
+ public CountDownLatch openLatch = new CountDownLatch(1);
+ public CountDownLatch errorLatch = new CountDownLatch(1);
+ public CountDownLatch closeLatch = new CountDownLatch(1);
+
+ @OnWebSocketConnect
+ public void onOpen(Session session)
+ {
+ this.session = session;
+ behavior = session.getPolicy().getBehavior().name();
+ if (LOG.isDebugEnabled())
+ LOG.debug("{} onOpen(): {}", toString(), session);
+ openLatch.countDown();
+ }
+
+ @OnWebSocketMessage
+ public void onMessage(String message) throws IOException
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("{} onMessage(): {}", toString(), message);
+ textMessages.offer(message);
+ }
+
+ @OnWebSocketMessage
+ public void onMessage(byte[] buf, int offset, int len) throws IOException
+ {
+ ByteBuffer message = ByteBuffer.wrap(buf, offset, len);
+ if (LOG.isDebugEnabled())
+ LOG.debug("{} onMessage(): {}", toString(), message);
+ binaryMessages.offer(message);
+ }
+
+ @OnWebSocketClose
+ public void onClose(int statusCode, String reason)
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("{} onClose(): {}:{}", toString(), statusCode, reason);
+ this.closeCode = statusCode;
+ this.closeReason = reason;
+ closeLatch.countDown();
+ }
+
+ @OnWebSocketError
+ public void onError(Throwable cause)
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("{} onError(): {}", toString(), cause);
+ error = cause;
+ errorLatch.countDown();
+ }
+
+ @Override
+ public String toString()
+ {
+ return String.format("[%s@%s]", behavior, Integer.toHexString(hashCode()));
+ }
+}
diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/autobahn/JettyAutobahnClient.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jetty/JettyAutobahnClient.java
similarity index 76%
rename from jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/autobahn/JettyAutobahnClient.java
rename to tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jetty/JettyAutobahnClient.java
index bf5ccd9cc10..d9fbd525a9e 100644
--- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/autobahn/JettyAutobahnClient.java
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jetty/JettyAutobahnClient.java
@@ -11,28 +11,25 @@
// ========================================================================
//
-package org.eclipse.jetty.websocket.tests.autobahn;
+package org.eclipse.jetty.websocket.tests.jetty;
-import java.io.IOException;
import java.net.URI;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
+import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.util.Jetty;
import org.eclipse.jetty.util.UrlEncoded;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode;
+import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.client.WebSocketClient;
-import org.eclipse.jetty.websocket.tests.EchoSocket;
-import org.eclipse.jetty.websocket.tests.EventSocket;
+import org.eclipse.jetty.websocket.tests.AutobahnClient;
+import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* WebSocket Client for use with autobahn websocket testsuite (wstest).
@@ -68,7 +65,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* $ ls target/reports/clients/
*
*/
-public class JettyAutobahnClient
+public class JettyAutobahnClient implements AutobahnClient
{
public static void main(String[] args)
{
@@ -93,46 +90,8 @@ public class JettyAutobahnClient
}
}
- JettyAutobahnClient client = null;
- try
- {
- String userAgent = "JettyWebsocketClient/" + Jetty.VERSION;
- client = new JettyAutobahnClient(hostname, port, userAgent);
-
- LOG.info("Running test suite...");
- LOG.info("Using Fuzzing Server: {}:{}", hostname, port);
- LOG.info("User Agent: {}", userAgent);
-
- if (caseNumbers == null)
- {
- int caseCount = client.getCaseCount();
- LOG.info("Will run all {} cases ...", caseCount);
- for (int caseNum = 1; caseNum <= caseCount; caseNum++)
- {
- LOG.info("Running case {} (of {}) ...", caseNum, caseCount);
- client.runCaseByNumber(caseNum);
- }
- }
- else
- {
- LOG.info("Will run {} cases ...", caseNumbers.length);
- for (int caseNum : caseNumbers)
- {
- client.runCaseByNumber(caseNum);
- }
- }
- LOG.info("All test cases executed.");
- client.updateReports();
- }
- catch (Throwable t)
- {
- LOG.warn("Test Failed", t);
- }
- finally
- {
- if (client != null)
- client.shutdown();
- }
+ JettyAutobahnClient client = new JettyAutobahnClient();
+ client.runAutobahnClient(hostname, port, caseNumbers);
}
private static final Logger LOG = LoggerFactory.getLogger(JettyAutobahnClient.class);
@@ -140,38 +99,76 @@ public class JettyAutobahnClient
private WebSocketClient client;
private String userAgent;
- public JettyAutobahnClient(String hostname, int port, String userAgent) throws Exception
+ @Override
+ public void runAutobahnClient(String hostname, int port, int[] caseNumbers)
{
- this.userAgent = userAgent;
- this.baseWebsocketUri = new URI("ws://" + hostname + ":" + port);
- this.client = new WebSocketClient();
- this.client.start();
+ try
+ {
+ String userAgent = "JettyWebsocketClient/" + Jetty.VERSION;
+ this.userAgent = userAgent;
+ this.baseWebsocketUri = new URI("ws://" + hostname + ":" + port);
+ this.client = new WebSocketClient();
+ this.client.start();
+
+ LOG.info("Running test suite...");
+ LOG.info("Using Fuzzing Server: {}:{}", hostname, port);
+ LOG.info("User Agent: {}", userAgent);
+
+ if (caseNumbers == null)
+ {
+ int caseCount = getCaseCount();
+ LOG.info("Will run all {} cases ...", caseCount);
+ for (int caseNum = 1; caseNum <= caseCount; caseNum++)
+ {
+ LOG.info("Running case {} (of {}) ...", caseNum, caseCount);
+ runCaseByNumber(caseNum);
+ }
+ }
+ else
+ {
+ LOG.info("Will run {} cases ...", caseNumbers.length);
+ for (int caseNum : caseNumbers)
+ {
+ runCaseByNumber(caseNum);
+ }
+ }
+ LOG.info("All test cases executed.");
+ updateReports();
+ }
+ catch (Throwable t)
+ {
+ LOG.warn("Test Failed", t);
+ }
+ finally
+ {
+ shutdown();
+ }
}
- public int getCaseCount() throws IOException, InterruptedException
+ public int getCaseCount() throws Exception
{
URI wsUri = baseWebsocketUri.resolve("/getCaseCount");
EventSocket onCaseCount = new EventSocket();
- CompletableFuture response = client.connect(onCaseCount, wsUri);
+ Future response = upgrade(onCaseCount, wsUri);
if (waitForUpgrade(wsUri, response))
{
String msg = onCaseCount.textMessages.poll(10, TimeUnit.SECONDS);
onCaseCount.session.close(StatusCode.SHUTDOWN, null);
- assertTrue(onCaseCount.closeLatch.await(2, TimeUnit.SECONDS));
+ Assertions.assertTrue(onCaseCount.closeLatch.await(2, TimeUnit.SECONDS));
assertNotNull(msg);
return Integer.decode(msg);
}
throw new IllegalStateException("Unable to get Case Count");
}
- public void runCaseByNumber(int caseNumber) throws IOException, InterruptedException
+ public void runCaseByNumber(int caseNumber) throws Exception
{
URI wsUri = baseWebsocketUri.resolve("/runCase?case=" + caseNumber + "&agent=" + UrlEncoded.encodeString(userAgent));
LOG.info("test uri: {}", wsUri);
EchoSocket echoHandler = new JettyAutobahnSocket();
- Future response = client.connect(echoHandler, wsUri);
+ Future response = upgrade(echoHandler, wsUri);
if (waitForUpgrade(wsUri, response))
{
// Wait up to 5 min as some of the tests can take a while
@@ -195,13 +192,21 @@ public class JettyAutobahnClient
}
}
- public void updateReports() throws IOException, InterruptedException, ExecutionException, TimeoutException
+ public Future upgrade(Object handler, URI uri) throws Exception
+ {
+ // We manually set the port as we run the server in docker container.
+ ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
+ upgradeRequest.setHeader(HttpHeader.HOST.asString(), "localhost:9001");
+ return client.connect(handler, uri, upgradeRequest);
+ }
+
+ public void updateReports() throws Exception
{
URI wsUri = baseWebsocketUri.resolve("/updateReports?agent=" + UrlEncoded.encodeString(userAgent));
EventSocket onUpdateReports = new EventSocket();
- Future response = client.connect(onUpdateReports, wsUri);
+ Future response = upgrade(onUpdateReports, wsUri);
response.get(5, TimeUnit.SECONDS);
- assertTrue(onUpdateReports.closeLatch.await(15, TimeUnit.SECONDS));
+ Assertions.assertTrue(onUpdateReports.closeLatch.await(15, TimeUnit.SECONDS));
LOG.info("Reports updated.");
LOG.info("Test suite finished!");
}
diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/autobahn/JettyAutobahnServer.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jetty/JettyAutobahnServer.java
similarity index 74%
rename from jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/autobahn/JettyAutobahnServer.java
rename to tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jetty/JettyAutobahnServer.java
index b316fe301d0..c31ca04fc0a 100644
--- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/autobahn/JettyAutobahnServer.java
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jetty/JettyAutobahnServer.java
@@ -11,12 +11,13 @@
// ========================================================================
//
-package org.eclipse.jetty.websocket.tests.autobahn;
+package org.eclipse.jetty.websocket.tests.jetty;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
+import org.eclipse.jetty.websocket.tests.AutobahnServer;
/**
* WebSocket Server for use with autobahn websocket testsuite (wstest).
@@ -52,7 +53,7 @@ import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerI
* $ ls target/reports/servers/
*
*/
-public class JettyAutobahnServer
+public class JettyAutobahnServer implements AutobahnServer
{
public static void main(String[] args) throws Exception
{
@@ -60,18 +61,39 @@ public class JettyAutobahnServer
if (args != null && args.length > 0)
port = Integer.parseInt(args[0]);
- Server server = new Server(port);
- ServerConnector connector = new ServerConnector(server);
- connector.setIdleTimeout(10000);
- server.addConnector(connector);
+ JettyAutobahnServer server = new JettyAutobahnServer();
+ server.startAutobahnServer(port);
+ server.join();
+ }
+
+ private Server _server;
+
+ @Override
+ public void startAutobahnServer(int port) throws Exception
+ {
+ _server = new Server();
+ ServerConnector connector = new ServerConnector(_server);
+ connector.setPort(port);
+ _server.addConnector(connector);
+
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
- server.setHandler(context);
+ _server.setHandler(context);
JettyWebSocketServletContainerInitializer.configure(context, (servletContext, container) ->
container.addMapping("/", (req, resp) -> new JettyAutobahnSocket()));
- server.start();
- server.join();
+ _server.start();
+ }
+
+ @Override
+ public void stopAutobahnServer() throws Exception
+ {
+ _server.stop();
+ }
+
+ public void join() throws InterruptedException
+ {
+ _server.join();
}
}
diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/autobahn/JettyAutobahnSocket.java b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jetty/JettyAutobahnSocket.java
similarity index 91%
rename from jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/autobahn/JettyAutobahnSocket.java
rename to tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jetty/JettyAutobahnSocket.java
index 3fbe269ddb4..3e92e4f403d 100644
--- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/autobahn/JettyAutobahnSocket.java
+++ b/tests/test-websocket-autobahn/src/test/java/org/eclipse/jetty/websocket/tests/jetty/JettyAutobahnSocket.java
@@ -11,12 +11,11 @@
// ========================================================================
//
-package org.eclipse.jetty.websocket.tests.autobahn;
+package org.eclipse.jetty.websocket.tests.jetty;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.core.WebSocketConstants;
-import org.eclipse.jetty.websocket.tests.EchoSocket;
@WebSocket
public class JettyAutobahnSocket extends EchoSocket
diff --git a/tests/test-websocket-autobahn/src/test/resources/simplelogger.properties b/tests/test-websocket-autobahn/src/test/resources/simplelogger.properties
new file mode 100644
index 00000000000..4386cf53ec8
--- /dev/null
+++ b/tests/test-websocket-autobahn/src/test/resources/simplelogger.properties
@@ -0,0 +1,4 @@
+org.slf4j.simpleLogger.defaultLogLevel=info
+org.slf4j.simpleLogger.showDateTime=true
+org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss
+org.slf4j.simpleLogger.log.org.eclipse.jetty.websocket.tests=info