diff --git a/single/src/main/java/cloud/piranha/single/SinglePiranha.java b/single/src/main/java/cloud/piranha/single/SinglePiranha.java index ce6d9d5c5..a99b66cae 100644 --- a/single/src/main/java/cloud/piranha/single/SinglePiranha.java +++ b/single/src/main/java/cloud/piranha/single/SinglePiranha.java @@ -217,10 +217,6 @@ public void run() { featureManager.addFeature(exitOnStopFeature); } - long finishTime = System.currentTimeMillis(); - LOGGER.log(INFO, "Started Piranha"); - LOGGER.log(INFO, "It took {0} milliseconds", finishTime - startTime); - if (configuration.getLong("pid") != null) { File pidFile = new File("tmp", "piranha.pid"); if (!pidFile.getParentFile().exists() && !pidFile.getParentFile().mkdirs()) { @@ -234,6 +230,10 @@ public void run() { } } + long finishTime = System.currentTimeMillis(); + LOGGER.log(INFO, "Started Piranha"); + LOGGER.log(INFO, "It took {0} milliseconds", finishTime - startTime); + while (!stop) { if (configuration.getLong("pid") != null) { File pidFile = new File("tmp", "piranha.pid"); @@ -249,7 +249,7 @@ public void run() { } try { - Thread.sleep(100); + Thread.sleep(1000); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } diff --git a/test/servlet/integration/pom.xml b/test/servlet/integration/pom.xml new file mode 100644 index 000000000..54f81cdfa --- /dev/null +++ b/test/servlet/integration/pom.xml @@ -0,0 +1,116 @@ + + + + 4.0.0 + + cloud.piranha.test.servlet + project + 24.12.0-SNAPSHOT + + piranha-test-servlet-integration + war + Piranha - Test - Servlet - Distribution Integration Tests + + UTF-8 + + + + + jakarta.servlet + jakarta.servlet-api + provided + + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-params + test + + + + integration + + + org.codehaus.mojo + build-helper-maven-plugin + + + reserve-network-port + + reserve-network-port + + validate + + + httpPort + + + + + + + cloud.piranha.maven + piranha-maven-plugin + ${project.version} + + + pre-integration-test + pre-integration-test + + start + + + + post-integration-test + post-integration-test + + stop + + + + + servlet + ${httpPort} + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + 10 + + ${httpPort} + + + + + org.apache.maven.plugins + maven-war-plugin + + false + + + + + diff --git a/test/servlet/integration/src/main/java/cloud/piranha/test/servlet/integration/IntegrationServlet.java b/test/servlet/integration/src/main/java/cloud/piranha/test/servlet/integration/IntegrationServlet.java new file mode 100644 index 000000000..26a4efbdc --- /dev/null +++ b/test/servlet/integration/src/main/java/cloud/piranha/test/servlet/integration/IntegrationServlet.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package cloud.piranha.test.servlet.integration; + +import java.io.IOException; +import java.io.PrintWriter; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/** + * The Servlet testing Jakarta Servlet integration. + * + * @author Manfred Riem (mriem@manorrock.com) + */ +@WebServlet(name = "IntegrationServlet", urlPatterns = {"/servlet"}) +public class IntegrationServlet extends HttpServlet { + + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet works!"); + out.println(""); + out.println(""); + out.println("

Servlet works!

"); + out.println(""); + out.println(""); + } + } +} diff --git a/test/servlet/integration/src/test/java/cloud/piranha/test/servlet/integration/IntegrationtIT.java b/test/servlet/integration/src/test/java/cloud/piranha/test/servlet/integration/IntegrationtIT.java new file mode 100644 index 000000000..3c478957d --- /dev/null +++ b/test/servlet/integration/src/test/java/cloud/piranha/test/servlet/integration/IntegrationtIT.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package cloud.piranha.test.servlet.integration; + +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.net.http.HttpResponse.BodyHandlers; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; + +/** + * The integration tests validating the various integrations. + * + *
    + *
  1. testServletIntegration validates Servlets works
  2. + *
+ * + * @author Manfred Riem (mriem@manorrock.com) + */ +class IntegrationtIT { + + /** + * Stores the base URL. + */ + private final String baseUrl + = "http://localhost:" + System.getProperty("httpPort") + "/integration"; + + /** + * Test Servlet integration. + */ + @Test + void testServletIntegration() throws Exception { + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest + .newBuilder(new URI(baseUrl + "/servlet")) + .build(); + HttpResponse response = client.send(request, BodyHandlers.ofString()); + assertTrue(response.body().contains("Servlet works!")); + } +} diff --git a/test/servlet/pom.xml b/test/servlet/pom.xml index 5f3265ed2..81fcc9f45 100644 --- a/test/servlet/pom.xml +++ b/test/servlet/pom.xml @@ -33,6 +33,7 @@ crac hello helloworld + integration pages websocket