Skip to content

Commit

Permalink
Fixes #4004 - Set longer timeouts in Arquillian connector and Maven p…
Browse files Browse the repository at this point in the history
…lugin (#4005)
  • Loading branch information
mnriem authored Sep 22, 2024
1 parent f28b1f8 commit b03c575
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <table>
* <caption>System properties</caption>
* <tr>
* <th>name</th>
* <th>value</th>
* <th>notes</th>
* </tr>
* <tr>
* <td>piranha.debug</td>
* <td>The boolean to start the Piranha process in debugging mode</td>
* <td>not enabled by default</td>
* </tr>
* <tr>
* <td>piranha.httpPort</td>
* <td>The integer to select the HTTP port to use for the Piranha process</td>
* <td>if not set an unused port will be automatically chosen</td>
* </tr>
* <tr>
* <td>piranha.jvmArguments</td>
* <td>The string with JVM arguments to pass to the Piranha process</td>
* <td>no additional JVM arguments are passed by default</td>
* </tr>
* <tr>
* <td>piranha.protocol</td>
* <td>The string with the Arquillian protocol to use when talking to the
* Piranha process</td>
* <td>set to 'Servlet 6.0' by default</td>
* </tr>
* <tr>
* <td>piranha.suspend</td>
* <td>the boolean to start the Piranha process in suspend mode</td>
* <td>not enabled by default</td>
* </tr>
* </table>
*
* @author Manfred Riem ([email protected])
*/
Expand All @@ -46,30 +83,30 @@ 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.
*/
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.
Expand Down Expand Up @@ -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;
Expand All @@ -167,11 +212,10 @@ public void validate() throws ConfigurationException {
Using suspend: {4}
""",

getHttpPort() + "",
getJvmArguments(),
getProtocol(),
isDebug(),
isSuspend());
getHttpPort() + "",
getJvmArguments(),
getProtocol(),
isDebug(),
isSuspend());
}
}
1 change: 1 addition & 0 deletions arquillian/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</description>

<modules>
<module>jarcontainer</module>
<module>managed</module>
<module>server</module>
</modules>
Expand Down
6 changes: 6 additions & 0 deletions maven/plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-tools-annotations</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions maven/plugin/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
*
* @author Manfred Riem ([email protected])
*/
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
34 changes: 31 additions & 3 deletions test/micro/helloworld/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
-->
<parent>
Expand All @@ -35,6 +38,7 @@
<piranha.version>${project.version}</piranha.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- plugins -->
<build-helper-maven-plugin.version>3.6.0</build-helper-maven-plugin.version>
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
<maven-failsafe-plugin.version>3.0.0-M7</maven-failsafe-plugin.version>
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
Expand Down Expand Up @@ -64,7 +68,7 @@
</executions>
<configuration>
<distribution>${piranha.distribution}</distribution>
<httpPort>6001</httpPort>
<httpPort>${httpPort}</httpPort>
</configuration>
</plugin>
<plugin>
Expand All @@ -87,6 +91,11 @@
</goals>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<httpPort>${httpPort}</httpPort>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -96,6 +105,25 @@
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>validate</phase>
<configuration>
<portNames>
<portName>httpPort</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> response = client.send(request, BodyHandlers.ofString());
assertTrue(response.body().contains("Hello World!"));
Expand Down

0 comments on commit b03c575

Please sign in to comment.