This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat-tck.git


The following commit(s) were added to refs/heads/main by this push:
     new e065a89  Enable running Servlet TCK tests in parallel
e065a89 is described below

commit e065a8919e1ea187485a1e6d2105bc40a54f421a
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Mar 18 12:14:55 2024 +0000

    Enable running Servlet TCK tests in parallel
    
    This is achieved as follows:
    - configure Tomcat to listen on port 0 in arquillian.xml
    - on deployment, extract the actual port being used from Tomcat
    - then inject the correct port into the arquillian configuration
    
    This ensures that arquillian generates the correct URLs for the clients
    to use during the tests.
---
 servlet-tck/pom.xml                                |  4 +-
 .../tck/servlet/TomcatServletTckConfiguration.java | 57 ++++++++++++++++++++++
 ...org.jboss.arquillian.core.spi.LoadableExtension |  1 +
 servlet-tck/src/test/resources/arquillian.xml      |  7 +++
 4 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/servlet-tck/pom.xml b/servlet-tck/pom.xml
index 8b24483..0157c03 100644
--- a/servlet-tck/pom.xml
+++ b/servlet-tck/pom.xml
@@ -104,11 +104,9 @@
                               <include>**/*Test.java</include>                 
               
                               <include>**/*Tests.java</include>                
                
                             </includes>
+                            <forkCount>5</forkCount>
                             <reuseForks>false</reuseForks>
                             <systemPropertyVariables>
-                                <webServerHost>localhost</webServerHost>
-                                <webServerPort>8080</webServerPort>
-                                
<securedWebServicePort>8443</securedWebServicePort>
                                 <ws_wait>5</ws_wait>
                                 <junit.log.traceflag>true</junit.log.traceflag>
                             </systemPropertyVariables>
diff --git 
a/servlet-tck/src/test/java/org/apache/tomcat/tck/servlet/TomcatServletTckConfiguration.java
 
b/servlet-tck/src/test/java/org/apache/tomcat/tck/servlet/TomcatServletTckConfiguration.java
new file mode 100644
index 0000000..4cbe69a
--- /dev/null
+++ 
b/servlet-tck/src/test/java/org/apache/tomcat/tck/servlet/TomcatServletTckConfiguration.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomcat.tck.servlet;
+
+import java.lang.reflect.Field;
+
+import org.apache.catalina.startup.Tomcat;
+import org.jboss.arquillian.container.spi.event.container.BeforeDeploy;
+import org.jboss.arquillian.core.api.annotation.Observes;
+import org.jboss.arquillian.core.spi.LoadableExtension;
+import 
org.jboss.arquillian.container.tomcat.embedded.Tomcat10EmbeddedContainer;
+
+public class TomcatServletTckConfiguration implements LoadableExtension {
+
+    @Override
+    public void register(ExtensionBuilder builder) {
+        builder.observer(ServletObserver.class);
+    }
+
+    public static class ServletObserver {
+
+        public void configurePorts(@Observes final BeforeDeploy beforeDeploy) {
+            Tomcat10EmbeddedContainer container = (Tomcat10EmbeddedContainer) 
beforeDeploy.getDeployableContainer();
+            try {
+                Field tomcatField = 
Tomcat10EmbeddedContainer.class.getDeclaredField("tomcat");
+                tomcatField.setAccessible(true);
+                Tomcat tomcat = (Tomcat) tomcatField.get(container);
+                int localPort = tomcat.getConnector().getLocalPort();
+
+                Field configurationField = 
Tomcat10EmbeddedContainer.class.getDeclaredField("configuration");
+                configurationField.setAccessible(true);
+                Object configuration = configurationField.get(container);
+
+                Field portField = 
container.getConfigurationClass().getDeclaredField("bindHttpPort");
+                portField.setAccessible(true);
+                portField.set(configuration, Integer.valueOf(localPort));
+
+            } catch (ReflectiveOperationException e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+}
diff --git 
a/servlet-tck/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension
 
b/servlet-tck/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension
new file mode 100644
index 0000000..3a5794f
--- /dev/null
+++ 
b/servlet-tck/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension
@@ -0,0 +1 @@
+org.apache.tomcat.tck.servlet.TomcatServletTckConfiguration
\ No newline at end of file
diff --git a/servlet-tck/src/test/resources/arquillian.xml 
b/servlet-tck/src/test/resources/arquillian.xml
new file mode 100644
index 0000000..a0554f4
--- /dev/null
+++ b/servlet-tck/src/test/resources/arquillian.xml
@@ -0,0 +1,7 @@
+<arquillian>
+  <container qualifier="tomcat" default="true">
+    <configuration>
+      <property name="bindHttpPort">0</property>
+    </configuration>
+  </container>
+</arquillian>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to