From 7638d8f2d7189c4fbb2c575a8f448dc8ccd7c853 Mon Sep 17 00:00:00 2001 From: Radoslav Husar Date: Fri, 6 Dec 2024 16:42:53 +0100 Subject: [PATCH] Upgrade to org.apache.httpcomponents.client5:httpclient5 - Tomcat module #525 --- .../AbstractAverageSystemLoadServletIT.java | 42 +++++++++++++ .../it/shared/AbstractDebugServletIT.java | 1 - .../it/shared/AbstractGranularServletIT.java | 1 - .../shared/AbstractHttpResponseServletIT.java | 1 - .../shared/AbstractHttpSessionServletIT.java | 58 ++++++++++++++++++ .../it/shared/AbstractLoggerServletIT.java | 6 +- .../it/shared/AbstractNodeNameServletIT.java | 1 - integration-tests/tomcat-10.1/pom.xml | 53 +++++++--------- .../it/tomcat/AbstractTomcatIT.java | 24 -------- .../it/tomcat/AverageSystemLoadServletIT.java | 14 +++++ .../AverageSystemLoadServletTomcatIT.java | 47 --------------- .../it/tomcat/HttpSessionServletTomcatIT.java | 60 ------------------- .../it/tomcat/SystemLoadServletTomcatIT.java | 14 +++++ .../wildfly/AverageSystemLoadServletIT.java | 14 +++++ .../it/wildfly/HttpSessionServletIT.java | 14 +++++ 15 files changed, 180 insertions(+), 170 deletions(-) create mode 100644 integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractAverageSystemLoadServletIT.java create mode 100644 integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractHttpSessionServletIT.java delete mode 100644 integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/AbstractTomcatIT.java create mode 100644 integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/AverageSystemLoadServletIT.java delete mode 100644 integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/AverageSystemLoadServletTomcatIT.java delete mode 100644 integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/HttpSessionServletTomcatIT.java create mode 100644 integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/SystemLoadServletTomcatIT.java create mode 100644 integration-tests/wildfly/src/test/java/org/jboss/test/clusterbench/it/wildfly/AverageSystemLoadServletIT.java create mode 100644 integration-tests/wildfly/src/test/java/org/jboss/test/clusterbench/it/wildfly/HttpSessionServletIT.java diff --git a/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractAverageSystemLoadServletIT.java b/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractAverageSystemLoadServletIT.java new file mode 100644 index 00000000..5550957b --- /dev/null +++ b/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractAverageSystemLoadServletIT.java @@ -0,0 +1,42 @@ +/* + * Copyright The ClusterBench Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.test.clusterbench.it.shared; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * Smoke test for {@link org.jboss.test.clusterbench.web.load.AverageSystemLoadServlet}. + * + * @author Radoslav Husar + */ +@ExtendWith(ArquillianExtension.class) +@RunAsClient +public abstract class AbstractAverageSystemLoadServletIT { + + @Test + public void test() throws Exception { + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + HttpGet httpGet = new HttpGet("http://localhost:8080/clusterbench/averagesystemload?milliseconds=1000&threads=4"); + + httpClient.execute(httpGet, response -> { + assertEquals(200, response.getCode()); + + String responseBody = EntityUtils.toString(response.getEntity()); + assertEquals("DONE", responseBody); + + return null; + }); + } + } +} diff --git a/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractDebugServletIT.java b/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractDebugServletIT.java index 926ce8ab..46f022c6 100644 --- a/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractDebugServletIT.java +++ b/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractDebugServletIT.java @@ -2,7 +2,6 @@ * Copyright The ClusterBench Authors * SPDX-License-Identifier: Apache-2.0 */ - package org.jboss.test.clusterbench.it.shared; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractGranularServletIT.java b/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractGranularServletIT.java index f3fa1f66..f808e432 100644 --- a/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractGranularServletIT.java +++ b/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractGranularServletIT.java @@ -2,7 +2,6 @@ * Copyright The ClusterBench Authors * SPDX-License-Identifier: Apache-2.0 */ - package org.jboss.test.clusterbench.it.shared; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractHttpResponseServletIT.java b/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractHttpResponseServletIT.java index e2d8145c..5b38bfc6 100644 --- a/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractHttpResponseServletIT.java +++ b/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractHttpResponseServletIT.java @@ -2,7 +2,6 @@ * Copyright The ClusterBench Authors * SPDX-License-Identifier: Apache-2.0 */ - package org.jboss.test.clusterbench.it.shared; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractHttpSessionServletIT.java b/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractHttpSessionServletIT.java new file mode 100644 index 00000000..f7488a59 --- /dev/null +++ b/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractHttpSessionServletIT.java @@ -0,0 +1,58 @@ +/* + * Copyright The ClusterBench Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.test.clusterbench.it.shared; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Arrays; +import java.util.Optional; + +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.core5.http.Header; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * @author Radoslav Husar + */ +@ExtendWith(ArquillianExtension.class) +@RunAsClient +public abstract class AbstractHttpSessionServletIT { + + @Test + public void test() throws Exception { + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + HttpGet httpGet = new HttpGet("http://localhost:8080/clusterbench/session"); + + httpClient.execute(httpGet, response -> { + assertEquals(200, response.getCode()); + + String responseBody = EntityUtils.toString(response.getEntity()); + assertEquals("0", responseBody); + + // Also ensure session is created + Optional jsessionIdCookie = Arrays.stream(response.getHeaders("Set-Cookie")).map(Header::getValue).filter(cookie -> cookie.startsWith("JSESSIONID=")).findFirst(); + assertTrue(jsessionIdCookie.isPresent()); + + return null; + }); + + httpClient.execute(httpGet, response -> { + assertEquals(200, response.getCode()); + + String responseBody = EntityUtils.toString(response.getEntity()); + assertEquals("1", responseBody); + + return null; + }); + } + } +} diff --git a/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractLoggerServletIT.java b/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractLoggerServletIT.java index cffa5876..745a31cc 100644 --- a/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractLoggerServletIT.java +++ b/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractLoggerServletIT.java @@ -1,6 +1,6 @@ -/** - * @author Tommaso Borgato - * @author Radoslav Husar +/* + * Copyright The ClusterBench Authors + * SPDX-License-Identifier: Apache-2.0 */ package org.jboss.test.clusterbench.it.shared; diff --git a/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractNodeNameServletIT.java b/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractNodeNameServletIT.java index 14d30f0e..51a395ff 100644 --- a/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractNodeNameServletIT.java +++ b/integration-tests/shared/src/main/java/org/jboss/test/clusterbench/it/shared/AbstractNodeNameServletIT.java @@ -2,7 +2,6 @@ * Copyright The ClusterBench Authors * SPDX-License-Identifier: Apache-2.0 */ - package org.jboss.test.clusterbench.it.shared; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/integration-tests/tomcat-10.1/pom.xml b/integration-tests/tomcat-10.1/pom.xml index 6e981a5f..f525ec51 100644 --- a/integration-tests/tomcat-10.1/pom.xml +++ b/integration-tests/tomcat-10.1/pom.xml @@ -13,8 +13,6 @@ clusterbench-it-tomcat-10.1 - jar - ClusterBench ITs: Tomcat 10.1 @@ -22,17 +20,6 @@ - - - jakarta.servlet - jakarta.servlet-api - test - - - junit - junit - test - org.jboss.arquillian.container arquillian-tomcat-managed-10 @@ -40,14 +27,14 @@ test - org.jboss.arquillian.junit - arquillian-junit-container + org.junit.platform + junit-platform-suite test org.jboss.test - clusterbench-ee10-web - classes + clusterbench-it-shares + ${project.version} test @@ -79,48 +66,50 @@ + org.apache.maven.plugins maven-dependency-plugin - copy-war + unpack-tomcat generate-test-resources - copy + unpack - org.jboss.test - clusterbench-ee10-web - war + org.apache.tomcat + tomcat + ${version.org.apache.tomcat} + zip true - tomcat ${project.build.directory} + ** - true - unpack-tomcat + copy-war generate-test-resources - unpack + copy - org.apache.tomcat - tomcat - ${version.org.apache.tomcat} - zip + org.jboss.test + clusterbench-ee10-web + war true - ${project.build.directory} - ** + tomcat + ${catalina.home}/webapps + clusterbench.war + true diff --git a/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/AbstractTomcatIT.java b/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/AbstractTomcatIT.java deleted file mode 100644 index a64cc481..00000000 --- a/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/AbstractTomcatIT.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.jboss.test.clusterbench.it.tomcat; - -import java.io.File; - -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.shrinkwrap.api.Archive; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.importer.ZipImporter; -import org.jboss.shrinkwrap.api.spec.WebArchive; - -/** - * @author Radoslav Husar - */ -public abstract class AbstractTomcatIT { - - @Deployment(testable = false) - public static Archive deployment() { - return ShrinkWrap - .create(ZipImporter.class, "clusterbench.war") - .importFrom(new File("target/clusterbench-ee10-web-tomcat.war")) - .as(WebArchive.class); - } - -} diff --git a/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/AverageSystemLoadServletIT.java b/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/AverageSystemLoadServletIT.java new file mode 100644 index 00000000..03262997 --- /dev/null +++ b/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/AverageSystemLoadServletIT.java @@ -0,0 +1,14 @@ +/* + * Copyright The ClusterBench Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.test.clusterbench.it.tomcat; + +import org.jboss.test.clusterbench.it.shared.AbstractAverageSystemLoadServletIT; + +/** + * @author Radoslav Husar + */ +public class AverageSystemLoadServletIT extends AbstractAverageSystemLoadServletIT { + // Inherit. +} \ No newline at end of file diff --git a/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/AverageSystemLoadServletTomcatIT.java b/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/AverageSystemLoadServletTomcatIT.java deleted file mode 100644 index 8eb2a9ad..00000000 --- a/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/AverageSystemLoadServletTomcatIT.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright The ClusterBench Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.jboss.test.clusterbench.it.tomcat; - -import static org.junit.Assert.assertEquals; - -import java.net.URL; - -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; -import org.jboss.arquillian.container.test.api.RunAsClient; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.jboss.test.clusterbench.web.session.HttpSessionServlet; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * Tomcat version of the smoke test for {@link org.jboss.test.clusterbench.web.load.AverageSystemLoadServlet}. - * - * @author Radoslav Husar - */ -@RunWith(Arquillian.class) -@RunAsClient -public class AverageSystemLoadServletTomcatIT extends AbstractTomcatIT { - - @Test - public void test(@ArquillianResource(HttpSessionServlet.class) URL baseURL) throws Exception { - try (CloseableHttpClient httpClient = HttpClients.createDefault()) { - HttpGet httpGet = new HttpGet(baseURL.toURI() + "/averagesystemload?milliseconds=1000&threads=4"); - System.out.println(httpGet); - - try (CloseableHttpResponse response = httpClient.execute(httpGet)) { - assertEquals(200, response.getStatusLine().getStatusCode()); - - String responseBody = EntityUtils.toString(response.getEntity()); - assertEquals("DONE", responseBody); - } - } - } -} diff --git a/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/HttpSessionServletTomcatIT.java b/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/HttpSessionServletTomcatIT.java deleted file mode 100644 index 9f4b2582..00000000 --- a/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/HttpSessionServletTomcatIT.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright The ClusterBench Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.jboss.test.clusterbench.it.tomcat; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.net.URL; -import java.util.Arrays; -import java.util.Optional; - -import org.apache.http.Header; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; -import org.jboss.arquillian.container.test.api.RunAsClient; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.jboss.test.clusterbench.web.session.HttpSessionServlet; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * @author Radoslav Husar - */ -@RunWith(Arquillian.class) -@RunAsClient -public class HttpSessionServletTomcatIT extends AbstractTomcatIT { - - @Test - public void test(@ArquillianResource(HttpSessionServlet.class) URL baseURL) throws Exception { - try (CloseableHttpClient httpClient = HttpClients.createDefault()) { - HttpGet httpGet = new HttpGet(baseURL.toURI() + "/session"); - System.out.println(httpGet); - - try (CloseableHttpResponse response = httpClient.execute(httpGet)) { - assertEquals(200, response.getStatusLine().getStatusCode()); - - String responseBody = EntityUtils.toString(response.getEntity()); - assertEquals("0", responseBody); - - // Also ensure session is created - Optional
header = Arrays.stream(response.getAllHeaders()).filter(h -> Arrays.stream(h.getElements()).anyMatch(e -> e.getName().equals("JSESSIONID"))).findAny(); - assertTrue(header.isPresent()); - } - - try (CloseableHttpResponse response = httpClient.execute(httpGet)) { - assertEquals(200, response.getStatusLine().getStatusCode()); - - String responseBody = EntityUtils.toString(response.getEntity()); - assertEquals("1", responseBody); - } - } - } -} diff --git a/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/SystemLoadServletTomcatIT.java b/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/SystemLoadServletTomcatIT.java new file mode 100644 index 00000000..8fc268e7 --- /dev/null +++ b/integration-tests/tomcat-10.1/src/test/java/org/jboss/test/clusterbench/it/tomcat/SystemLoadServletTomcatIT.java @@ -0,0 +1,14 @@ +/* + * Copyright The ClusterBench Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.test.clusterbench.it.tomcat; + +import org.jboss.test.clusterbench.it.shared.AbstractAverageSystemLoadServletIT; + +/** + * @author Radoslav Husar + */ +public class SystemLoadServletTomcatIT extends AbstractAverageSystemLoadServletIT { + // Inherit. +} diff --git a/integration-tests/wildfly/src/test/java/org/jboss/test/clusterbench/it/wildfly/AverageSystemLoadServletIT.java b/integration-tests/wildfly/src/test/java/org/jboss/test/clusterbench/it/wildfly/AverageSystemLoadServletIT.java new file mode 100644 index 00000000..4bad1733 --- /dev/null +++ b/integration-tests/wildfly/src/test/java/org/jboss/test/clusterbench/it/wildfly/AverageSystemLoadServletIT.java @@ -0,0 +1,14 @@ +/* + * Copyright The ClusterBench Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.test.clusterbench.it.wildfly; + +import org.jboss.test.clusterbench.it.shared.AbstractAverageSystemLoadServletIT; + +/** + * @author Radoslav Husar + */ +public class AverageSystemLoadServletIT extends AbstractAverageSystemLoadServletIT { + // Inherit. +} \ No newline at end of file diff --git a/integration-tests/wildfly/src/test/java/org/jboss/test/clusterbench/it/wildfly/HttpSessionServletIT.java b/integration-tests/wildfly/src/test/java/org/jboss/test/clusterbench/it/wildfly/HttpSessionServletIT.java new file mode 100644 index 00000000..660eba9f --- /dev/null +++ b/integration-tests/wildfly/src/test/java/org/jboss/test/clusterbench/it/wildfly/HttpSessionServletIT.java @@ -0,0 +1,14 @@ +/* + * Copyright The ClusterBench Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.test.clusterbench.it.wildfly; + +import org.jboss.test.clusterbench.it.shared.AbstractHttpSessionServletIT; + +/** + * @author Radoslav Husar + */ +public class HttpSessionServletIT extends AbstractHttpSessionServletIT { + // Inherit. +} \ No newline at end of file