From b03c5759a87451dc29f6dc3259c9aaaa43903cfe Mon Sep 17 00:00:00 2001 From: Manfred Riem Date: Sun, 22 Sep 2024 10:31:18 -0500 Subject: [PATCH] Fixes #4004 - Set longer timeouts in Arquillian connector and Maven plugin (#4005) --- .../ManagedPiranhaContainerConfiguration.java | 84 ++++++++++++++----- arquillian/pom.xml | 1 + maven/plugin/pom.xml | 6 ++ .../{plugins/piranha => plugin}/BaseMojo.java | 8 +- .../{plugins/piranha => plugin}/RunMojo.java | 8 +- .../piranha => plugin}/StartMojo.java | 12 ++- .../{plugins/piranha => plugin}/StopMojo.java | 8 +- maven/plugin/src/main/java/module-info.java | 6 +- .../piranha/test/common/PiranhaStartup.java | 4 +- test/micro/helloworld/pom.xml | 34 +++++++- .../java/helloworld/HelloWorldServletIT.java | 3 +- 11 files changed, 139 insertions(+), 35 deletions(-) rename maven/plugin/src/main/java/cloud/piranha/maven/{plugins/piranha => plugin}/BaseMojo.java (98%) rename maven/plugin/src/main/java/cloud/piranha/maven/{plugins/piranha => plugin}/RunMojo.java (98%) rename maven/plugin/src/main/java/cloud/piranha/maven/{plugins/piranha => plugin}/StartMojo.java (97%) rename maven/plugin/src/main/java/cloud/piranha/maven/{plugins/piranha => plugin}/StopMojo.java (96%) diff --git a/arquillian/managed/src/main/java/cloud/piranha/arquillian/managed/ManagedPiranhaContainerConfiguration.java b/arquillian/managed/src/main/java/cloud/piranha/arquillian/managed/ManagedPiranhaContainerConfiguration.java index 03d7243e8b..8e6151a305 100644 --- a/arquillian/managed/src/main/java/cloud/piranha/arquillian/managed/ManagedPiranhaContainerConfiguration.java +++ b/arquillian/managed/src/main/java/cloud/piranha/arquillian/managed/ManagedPiranhaContainerConfiguration.java @@ -35,7 +35,44 @@ import static java.lang.System.Logger.Level.INFO; /** - * The Managed Piranha container configuration. + * The managed Piranha container configuration. + * + * The following system properties can be used to configure the Piranha + * container from the command-line. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
System properties
namevaluenotes
piranha.debugThe boolean to start the Piranha process in debugging modenot enabled by default
piranha.httpPortThe integer to select the HTTP port to use for the Piranha processif not set an unused port will be automatically chosen
piranha.jvmArgumentsThe string with JVM arguments to pass to the Piranha processno additional JVM arguments are passed by default
piranha.protocolThe string with the Arquillian protocol to use when talking to the + * Piranha processset to 'Servlet 6.0' by default
piranha.suspendthe boolean to start the Piranha process in suspend modenot enabled by default
* * @author Manfred Riem (mriem@manorrock.com) */ @@ -46,10 +83,15 @@ public class ManagedPiranhaContainerConfiguration implements ContainerConfigurat */ private static final System.Logger LOGGER = System.getLogger(ManagedPiranhaContainerConfiguration.class.getName()); + /** + * Stores the debug flag. + */ + private boolean debug = Boolean.parseBoolean(System.getProperty("piranha.debug", "false")); + /** * Stores the HTTP port. */ - private Integer httpPort = System.getProperty("piranha.httpPort") != null? Integer.valueOf(System.getProperty("piranha.httpPort")) : null; + private Integer httpPort = System.getProperty("piranha.httpPort") != null ? Integer.valueOf(System.getProperty("piranha.httpPort")) : null; /** * Stores the JVM arguments. @@ -57,19 +99,14 @@ public class ManagedPiranhaContainerConfiguration implements ContainerConfigurat private String jvmArguments = System.getProperty("piranha.jvmArguments", ""); /** - * Stores the protocol. + * Stores the Arquillian protocol. */ private String protocol = System.getProperty("piranha.protocol", "Servlet 6.0"); /** - * Stores the debug. - */ - private boolean debug = Boolean.valueOf(System.getProperty("piranha.debug", "false")); - - /** - * Stores the [guess what?]. + * Stores the suspend flag. */ - private boolean suspend = Boolean.valueOf(System.getProperty("piranha.suspend", "false")); + private boolean suspend = Boolean.parseBoolean(System.getProperty("piranha.suspend", "false")); /** * Get the HTTP port. @@ -129,28 +166,36 @@ public void setProtocol(String protocol) { } /** - * @return the debug + * Is the debug flag set? + * + * @return true if the debug flag is set, false otherwise. */ public boolean isDebug() { return debug; } /** - * @param debug the debug to set + * Set the debug flag. + * + * @param debug the debug flag. */ public void setDebug(boolean debug) { this.debug = debug; } /** - * @return the suspend + * Is the suspend flag set? + * + * @return true if the suspend flag is set, false otherwise. */ public boolean isSuspend() { return suspend; } /** - * @param suspend the suspend to set [yes we know, this comment does not make much sense] + * Set the suspend flag. + * + * @param suspend the suspend flag. */ public void setSuspend(boolean suspend) { this.suspend = suspend; @@ -167,11 +212,10 @@ public void validate() throws ConfigurationException { Using suspend: {4} """, - - getHttpPort() + "", - getJvmArguments(), - getProtocol(), - isDebug(), - isSuspend()); + getHttpPort() + "", + getJvmArguments(), + getProtocol(), + isDebug(), + isSuspend()); } } diff --git a/arquillian/pom.xml b/arquillian/pom.xml index b69db6412d..5220a19377 100644 --- a/arquillian/pom.xml +++ b/arquillian/pom.xml @@ -19,6 +19,7 @@ + jarcontainer managed server diff --git a/maven/plugin/pom.xml b/maven/plugin/pom.xml index 29e142f776..bcff923fd4 100644 --- a/maven/plugin/pom.xml +++ b/maven/plugin/pom.xml @@ -23,6 +23,12 @@ org.apache.maven.plugin-tools maven-plugin-tools-annotations provided + + + org.apache.maven + maven-artifact + + diff --git a/maven/plugin/src/main/java/cloud/piranha/maven/plugins/piranha/BaseMojo.java b/maven/plugin/src/main/java/cloud/piranha/maven/plugin/BaseMojo.java similarity index 98% rename from maven/plugin/src/main/java/cloud/piranha/maven/plugins/piranha/BaseMojo.java rename to maven/plugin/src/main/java/cloud/piranha/maven/plugin/BaseMojo.java index b12b5a357c..742f036589 100644 --- a/maven/plugin/src/main/java/cloud/piranha/maven/plugins/piranha/BaseMojo.java +++ b/maven/plugin/src/main/java/cloud/piranha/maven/plugin/BaseMojo.java @@ -25,7 +25,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package cloud.piranha.maven.plugins.piranha; +package cloud.piranha.maven.plugin; import java.io.File; import java.io.FileNotFoundException; @@ -138,6 +138,12 @@ public abstract class BaseMojo extends AbstractMojo { @Parameter(defaultValue = "${project.build.finalName}", property="piranha.warName", required = true, readonly = true) protected String warName; + /** + * Default constructor. + */ + public BaseMojo() { + } + /** * Convert a Maven groupId to a path snippet. * diff --git a/maven/plugin/src/main/java/cloud/piranha/maven/plugins/piranha/RunMojo.java b/maven/plugin/src/main/java/cloud/piranha/maven/plugin/RunMojo.java similarity index 98% rename from maven/plugin/src/main/java/cloud/piranha/maven/plugins/piranha/RunMojo.java rename to maven/plugin/src/main/java/cloud/piranha/maven/plugin/RunMojo.java index 3acaf66642..5eb8703dc4 100644 --- a/maven/plugin/src/main/java/cloud/piranha/maven/plugins/piranha/RunMojo.java +++ b/maven/plugin/src/main/java/cloud/piranha/maven/plugin/RunMojo.java @@ -25,7 +25,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package cloud.piranha.maven.plugins.piranha; +package cloud.piranha.maven.plugin; import java.io.File; import java.io.IOException; @@ -44,6 +44,12 @@ @Mojo(name = "run", defaultPhase = NONE) public class RunMojo extends BaseMojo { + /** + * Default constructor. + */ + public RunMojo() { + } + @Override public void execute() throws MojoExecutionException { if (!skip) { diff --git a/maven/plugin/src/main/java/cloud/piranha/maven/plugins/piranha/StartMojo.java b/maven/plugin/src/main/java/cloud/piranha/maven/plugin/StartMojo.java similarity index 97% rename from maven/plugin/src/main/java/cloud/piranha/maven/plugins/piranha/StartMojo.java rename to maven/plugin/src/main/java/cloud/piranha/maven/plugin/StartMojo.java index 7acfce8e52..0cbb100bac 100644 --- a/maven/plugin/src/main/java/cloud/piranha/maven/plugins/piranha/StartMojo.java +++ b/maven/plugin/src/main/java/cloud/piranha/maven/plugin/StartMojo.java @@ -25,7 +25,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package cloud.piranha.maven.plugins.piranha; +package cloud.piranha.maven.plugin; import java.io.File; import java.io.IOException; @@ -44,6 +44,12 @@ @Mojo(name = "start", defaultPhase = NONE) public class StartMojo extends BaseMojo { + /** + * Default constructor. + */ + public StartMojo() { + } + @Override public void execute() throws MojoExecutionException { if (!skip) { @@ -150,12 +156,12 @@ private void startPiranha() throws IOException { System.out.print("Waiting for Piranha to be ready "); while (!pidFile.exists()) { try { - Thread.sleep(500); + Thread.sleep(1000); count++; System.out.print("."); } catch (InterruptedException ie) { } - if (count == 100) { + if (count == 600) { System.out.println(); System.out.println("Warning, PID file not seen!"); break; diff --git a/maven/plugin/src/main/java/cloud/piranha/maven/plugins/piranha/StopMojo.java b/maven/plugin/src/main/java/cloud/piranha/maven/plugin/StopMojo.java similarity index 96% rename from maven/plugin/src/main/java/cloud/piranha/maven/plugins/piranha/StopMojo.java rename to maven/plugin/src/main/java/cloud/piranha/maven/plugin/StopMojo.java index 631c8032ea..b659f1524f 100644 --- a/maven/plugin/src/main/java/cloud/piranha/maven/plugins/piranha/StopMojo.java +++ b/maven/plugin/src/main/java/cloud/piranha/maven/plugin/StopMojo.java @@ -25,7 +25,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package cloud.piranha.maven.plugins.piranha; +package cloud.piranha.maven.plugin; import java.io.File; import java.io.IOException; @@ -58,6 +58,12 @@ public class StopMojo extends AbstractMojo { @Parameter(defaultValue= "false", property="piranha.skip") private boolean skip; + /** + * Default constructor. + */ + public StopMojo() { + } + @Override public void execute() throws MojoExecutionException { if (!skip) { diff --git a/maven/plugin/src/main/java/module-info.java b/maven/plugin/src/main/java/module-info.java index 8148f1c6c2..6d8e608c72 100644 --- a/maven/plugin/src/main/java/module-info.java +++ b/maven/plugin/src/main/java/module-info.java @@ -31,10 +31,10 @@ * * @author Manfred Riem (mriem@manorrock.com) */ -module cloud.piranha.maven.plugins.piranha { +module cloud.piranha.maven.plugin { - exports cloud.piranha.maven.plugins.piranha; - opens cloud.piranha.maven.plugins.piranha; + exports cloud.piranha.maven.plugin; + opens cloud.piranha.maven.plugin; requires maven.plugin.annotations; requires maven.plugin.api; requires java.xml; diff --git a/test/common/src/main/java/cloud/piranha/test/common/PiranhaStartup.java b/test/common/src/main/java/cloud/piranha/test/common/PiranhaStartup.java index 56b467bafe..ef692eda3e 100644 --- a/test/common/src/main/java/cloud/piranha/test/common/PiranhaStartup.java +++ b/test/common/src/main/java/cloud/piranha/test/common/PiranhaStartup.java @@ -59,8 +59,8 @@ public static void waitUntilPiranhaReady(int port) { } private static void waitUntilPiranhaReady(int port, BooleanSupplier customCheck) { - final int timeoutMillis = 120 * 1000; - final int sleepTimeMillis = 100; + final int timeoutMillis = 600 * 1000; + final int sleepTimeMillis = 1000; long initialTimeMillis = System.currentTimeMillis(); boolean started = false; diff --git a/test/micro/helloworld/pom.xml b/test/micro/helloworld/pom.xml index 9ccbdfb6e6..9cbac30030 100644 --- a/test/micro/helloworld/pom.xml +++ b/test/micro/helloworld/pom.xml @@ -11,8 +11,11 @@ particular project is used as a basis for the guide content at docs/src/site/markdown/micro/create_a_hello_world_web_application.md. - When updating the guide drop the parent part below and change the name to - read 'Create a Hello World application'. + When updating the guide do the following: + + 1. Drop the parent part below + 2. Change the name of the project to read 'Create a Hello World application' + 3. Change the version to the latest released version of Piranha --> @@ -35,6 +38,7 @@ ${project.version} UTF-8 + 3.6.0 3.10.1 3.0.0-M7 3.3.2 @@ -64,7 +68,7 @@ ${piranha.distribution} - 6001 + ${httpPort} @@ -87,6 +91,11 @@ + + + ${httpPort} + + org.apache.maven.plugins @@ -96,6 +105,25 @@ false + + org.codehaus.mojo + build-helper-maven-plugin + ${build-helper-maven-plugin.version} + + + reserve-network-port + + reserve-network-port + + validate + + + httpPort + + + + + diff --git a/test/micro/helloworld/src/test/java/helloworld/HelloWorldServletIT.java b/test/micro/helloworld/src/test/java/helloworld/HelloWorldServletIT.java index 6805d328f4..73202c7544 100644 --- a/test/micro/helloworld/src/test/java/helloworld/HelloWorldServletIT.java +++ b/test/micro/helloworld/src/test/java/helloworld/HelloWorldServletIT.java @@ -41,7 +41,8 @@ class HelloWorldServletIT { void testHelloWorld() throws Exception { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest - .newBuilder(new URI("http://localhost:6001/index.html")) + .newBuilder(new URI("http://localhost:" + + Integer.valueOf(System.getProperty("httpPort")) + "/index.html")) .build(); HttpResponse response = client.send(request, BodyHandlers.ofString()); assertTrue(response.body().contains("Hello World!"));