This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit b1e5d89d32606427759c5b4103c98d099cebacb1 Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Mon Aug 3 16:36:15 2020 +0100 Add test support module for executing quarkus runners --- integration-tests-support/pom.xml | 1 + .../{ => process-executor-support}/pom.xml | 50 ++++++------ .../support/process/QuarkusProcessExecutor.java | 92 ++++++++++++++++++++++ integration-tests/main-command-mode/pom.xml | 12 +-- .../camel/quarkus/main/cmd/it/CommandModeIT.java | 12 --- .../camel/quarkus/main/cmd/it/CommandModeTest.java | 19 +---- poms/bom-test/pom.xml | 5 ++ 7 files changed, 134 insertions(+), 57 deletions(-) diff --git a/integration-tests-support/pom.xml b/integration-tests-support/pom.xml index 0259955..430475c 100644 --- a/integration-tests-support/pom.xml +++ b/integration-tests-support/pom.xml @@ -41,6 +41,7 @@ <module>custom-routes-collector</module> <module>custom-type-converter</module> <module>custom-main-listener</module> + <module>process-executor-support</module> <module>test-support</module> <module>testcontainers-support</module> </modules> diff --git a/integration-tests-support/pom.xml b/integration-tests-support/process-executor-support/pom.xml similarity index 54% copy from integration-tests-support/pom.xml copy to integration-tests-support/process-executor-support/pom.xml index 0259955..15d7ef5 100644 --- a/integration-tests-support/pom.xml +++ b/integration-tests-support/process-executor-support/pom.xml @@ -18,31 +18,37 @@ --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - - <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-build-parent</artifactId> + <artifactId>camel-quarkus-integration-tests-support</artifactId> <version>1.1.0-SNAPSHOT</version> - <relativePath>../poms/build-parent/pom.xml</relativePath> + <relativePath>../pom.xml</relativePath> </parent> + <modelVersion>4.0.0</modelVersion> - <artifactId>camel-quarkus-integration-tests-support</artifactId> - <packaging>pom</packaging> - - <name>Camel Quarkus :: Integration Tests :: Support :: Parent</name> - <description>Ancillary modules required by some integration tests. Hosted outside the integration-tests directory - so that we can keep a flat hierarchy in the integration-tests directory. - </description> - - <modules> - <module>custom-dataformat</module> - <module>custom-log-component</module> - <module>custom-routes-collector</module> - <module>custom-type-converter</module> - <module>custom-main-listener</module> - <module>test-support</module> - <module>testcontainers-support</module> - </modules> - + <artifactId>camel-quarkus-integration-tests-process-executor-support</artifactId> + <name>Camel Quarkus :: Integration Tests :: Process :: Executor :: Support</name> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bom-test</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-test-support</artifactId> + </dependency> + <dependency> + <groupId>org.zeroturnaround</groupId> + <artifactId>zt-exec</artifactId> + </dependency> + </dependencies> </project> diff --git a/integration-tests-support/process-executor-support/src/main/java/org/apache/camel/quarkus/test/support/process/QuarkusProcessExecutor.java b/integration-tests-support/process-executor-support/src/main/java/org/apache/camel/quarkus/test/support/process/QuarkusProcessExecutor.java new file mode 100644 index 0000000..4aa9249 --- /dev/null +++ b/integration-tests-support/process-executor-support/src/main/java/org/apache/camel/quarkus/test/support/process/QuarkusProcessExecutor.java @@ -0,0 +1,92 @@ +/* + * 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.camel.quarkus.test.support.process; + +import java.io.IOException; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.TimeoutException; + +import org.apache.camel.quarkus.test.AvailablePortFinder; +import org.jboss.logging.Logger; +import org.zeroturnaround.exec.ProcessExecutor; +import org.zeroturnaround.exec.ProcessResult; +import org.zeroturnaround.exec.StartedProcess; + +/** + * Support class for executing a Quarkus executable JAR or native executable with arbitrary arguments + */ +public class QuarkusProcessExecutor { + + private static final Logger LOGGER = Logger.getLogger(QuarkusProcessExecutor.class); + private final ProcessExecutor executor; + private final int httpPort = AvailablePortFinder.getNextAvailable(); + private final int httpsPort = AvailablePortFinder.getNextAvailable(); + + public QuarkusProcessExecutor(String... args) { + LOGGER.infof("Executing process: %s", String.join(" ", command(args))); + executor = new ProcessExecutor() + .command(command(args)) + .redirectOutput(System.out) + .readOutput(true); + } + + public ProcessResult execute() throws InterruptedException, TimeoutException, IOException { + return executor.execute(); + } + + public StartedProcess start() throws IOException { + return executor.start(); + } + + public int getHttpPort() { + return httpPort; + } + + public int getHttpsPort() { + return httpsPort; + } + + protected List<String> command(String... args) { + final boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows"); + final String javaExecutable = System.getProperty("java.home") + (isWindows ? "/bin/java.exe" : "/bin/java"); + String runner = System.getProperty("quarkus.runner"); + if (runner != null && !Paths.get(runner).toFile().exists()) { + throw new IllegalStateException("Quarkus application runner does not exist: " + runner); + } + + List<String> runnerArgs = new ArrayList<>(); + if (runner.endsWith(".jar")) { + runnerArgs.add(javaExecutable); + runnerArgs.addAll(Arrays.asList(args)); + runnerArgs.add("-Dquarkus.http.port=" + httpPort); + runnerArgs.add("-Dquarkus.http.ssl-port=" + httpsPort); + runnerArgs.add("-jar"); + runnerArgs.add(runner); + } else { + runner += (isWindows ? ".exe" : ""); + runnerArgs.add(runner); + runnerArgs.addAll(Arrays.asList(args)); + runnerArgs.add("-Dquarkus.http.port=" + httpPort); + runnerArgs.add("-Dquarkus.http.ssl-port=" + httpsPort); + } + + return runnerArgs; + } +} diff --git a/integration-tests/main-command-mode/pom.xml b/integration-tests/main-command-mode/pom.xml index be9dc9a..6e672e1 100644 --- a/integration-tests/main-command-mode/pom.xml +++ b/integration-tests/main-command-mode/pom.xml @@ -37,7 +37,7 @@ <!-- mvn process-resources -Pformat from the root directory --> <mvnd.builder.rule>camel-quarkus-log-deployment,camel-quarkus-main-deployment,camel-quarkus-support-policy-deployment,camel-quarkus-timer-deployment</mvnd.builder.rule> - <quarkus.runner.jar>${basedir}/target/${project.artifactId}-${project.version}-runner.jar</quarkus.runner.jar> + <quarkus.runner.jar>${project.build.directory}/${project.artifactId}-${project.version}-runner.jar</quarkus.runner.jar> </properties> <dependencies> @@ -66,8 +66,8 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.zeroturnaround</groupId> - <artifactId>zt-exec</artifactId> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-tests-process-executor-support</artifactId> <scope>test</scope> </dependency> </dependencies> @@ -99,7 +99,7 @@ <phase>integration-test</phase> <configuration> <systemProperties> - <quarkus.runner.jar>${quarkus.runner.jar}</quarkus.runner.jar> + <quarkus.runner>${quarkus.runner.jar}</quarkus.runner> </systemProperties> </configuration> </execution> @@ -118,7 +118,7 @@ </activation> <properties> <quarkus.package.type>native</quarkus.package.type> - <quarkus.runner.jar>${basedir}/target/${project.artifactId}-${project.version}-native-image-source-jar/${project.artifactId}-${project.version}-runner.jar</quarkus.runner.jar> + <quarkus.runner.jar>${project.build.directory}/${project.artifactId}-${project.version}-native-image-source-jar/${project.artifactId}-${project.version}-runner.jar</quarkus.runner.jar> </properties> <build> <plugins> @@ -133,7 +133,7 @@ </goals> <configuration> <systemProperties> - <quarkus.runner>${basedir}/target/${project.artifactId}-${project.version}-runner</quarkus.runner> + <quarkus.runner>${project.build.directory}/${project.artifactId}-${project.version}-runner</quarkus.runner> </systemProperties> </configuration> </execution> diff --git a/integration-tests/main-command-mode/src/test/java/org/apache/camel/quarkus/main/cmd/it/CommandModeIT.java b/integration-tests/main-command-mode/src/test/java/org/apache/camel/quarkus/main/cmd/it/CommandModeIT.java index 16cec19..1337b7d 100644 --- a/integration-tests/main-command-mode/src/test/java/org/apache/camel/quarkus/main/cmd/it/CommandModeIT.java +++ b/integration-tests/main-command-mode/src/test/java/org/apache/camel/quarkus/main/cmd/it/CommandModeIT.java @@ -16,17 +16,5 @@ */ package org.apache.camel.quarkus.main.cmd.it; -import java.nio.file.Paths; - -import org.assertj.core.api.Assertions; - public class CommandModeIT extends CommandModeTest { - - protected String[] command(String greetingSubject) { - final boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows"); - final String runner = System.getProperty("quarkus.runner") + (isWindows ? ".exe" : ""); - Assertions.assertThat(Paths.get(runner)).exists(); - return new String[] { runner, "-Dgreeted.subject=" + greetingSubject }; - } - } diff --git a/integration-tests/main-command-mode/src/test/java/org/apache/camel/quarkus/main/cmd/it/CommandModeTest.java b/integration-tests/main-command-mode/src/test/java/org/apache/camel/quarkus/main/cmd/it/CommandModeTest.java index 2de094b..c907f24 100644 --- a/integration-tests/main-command-mode/src/test/java/org/apache/camel/quarkus/main/cmd/it/CommandModeTest.java +++ b/integration-tests/main-command-mode/src/test/java/org/apache/camel/quarkus/main/cmd/it/CommandModeTest.java @@ -17,36 +17,21 @@ package org.apache.camel.quarkus.main.cmd.it; import java.io.IOException; -import java.nio.file.Paths; import java.util.concurrent.TimeoutException; +import org.apache.camel.quarkus.test.support.process.QuarkusProcessExecutor; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.zeroturnaround.exec.InvalidExitValueException; -import org.zeroturnaround.exec.ProcessExecutor; import org.zeroturnaround.exec.ProcessResult; public class CommandModeTest { @Test void hello() throws InvalidExitValueException, IOException, InterruptedException, TimeoutException { - - final ProcessResult result = new ProcessExecutor() - .command(command("Joe")) - .readOutput(true) - .execute(); + final ProcessResult result = new QuarkusProcessExecutor("-Dgreeted.subject=Joe").execute(); Assertions.assertThat(result.getExitValue()).isEqualTo(0); Assertions.assertThat(result.outputUTF8()).contains("Hello Joe!"); - } - - protected String[] command(String greetingSubject) { - final boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows"); - final String javaExecutable = System.getProperty("java.home") + (isWindows ? "/bin/java.exe" : "/bin/java"); - final String runnerJar = System.getProperty("quarkus.runner.jar"); - Assertions.assertThat(Paths.get(runnerJar)).exists(); - return new String[] { javaExecutable, "-Dgreeted.subject=" + greetingSubject, "-jar", runnerJar }; - } - } diff --git a/poms/bom-test/pom.xml b/poms/bom-test/pom.xml index 672b042..936157c 100644 --- a/poms/bom-test/pom.xml +++ b/poms/bom-test/pom.xml @@ -80,6 +80,11 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-tests-process-executor-support</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-integration-test-support</artifactId> <version>${camel-quarkus.version}</version> </dependency>