Skip to content

Commit

Permalink
Remove unnecessary use of QuarkusProcessExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed Sep 11, 2024
1 parent d4e988c commit 77a55a6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 228 deletions.
36 changes: 6 additions & 30 deletions kamelet-chucknorris/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
<quarkus.platform.version>3.14.2</quarkus.platform.version>
<camel-quarkus.platform.version>3.15.0-SNAPSHOT</camel-quarkus.platform.version>

<!-- TODO: https://github.com/apache/camel-quarkus/issues/3156 -->
<camel-quarkus.version>${camel-quarkus.platform.version}</camel-quarkus.version>

<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<camel-quarkus.platform.group-id>org.apache.camel.quarkus</camel-quarkus.platform.group-id>
Expand All @@ -53,8 +50,6 @@
<maven-jar-plugin.version>3.4.2</maven-jar-plugin.version>
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
<maven-surefire-plugin.version>3.5.0</maven-surefire-plugin.version>

<quarkus.runner>${project.build.directory}/quarkus-app/quarkus-run.jar</quarkus.runner>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -119,12 +114,6 @@
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-tests-process-executor-support</artifactId>
<version>${camel-quarkus.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -166,27 +155,16 @@
</configuration>
</plugin>

<!-- Move surefire:test to integration-test phase to be able to execute the runner JAR from a test -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<executions>
<execution>
<id>default-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<failIfNoTests>false</failIfNoTests>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<quarkus.runner>${quarkus.runner}</quarkus.runner>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
<configuration>
<failIfNoTests>false</failIfNoTests>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemPropertyVariables>
</configuration>
</plugin>

<plugin>
Expand Down Expand Up @@ -291,7 +269,6 @@
</activation>
<properties>
<quarkus.native.enabled>true</quarkus.native.enabled>
<quarkus.runner>${project.build.directory}/${project.artifactId}-${project.version}-runner</quarkus.runner>
</properties>
<build>
<plugins>
Expand All @@ -307,7 +284,6 @@
<configuration>
<systemPropertyVariables>
<quarkus.native.enabled>${quarkus.native.enabled}</quarkus.native.enabled>
<quarkus.runner>${quarkus.runner}</quarkus.runner>
</systemPropertyVariables>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,89 +16,23 @@
*/
package org.acme.kamelet;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.apache.camel.quarkus.test.support.process.QuarkusProcessExecutor;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Test;
import org.zeroturnaround.exec.StartedProcess;

import static org.awaitility.Awaitility.await;

@QuarkusTest
public class ChuckNorrisTest {

private static final String NATIVE_ENABLED = System.getProperty("quarkus.native.enabled");

@Test
public void testTimerLogMain() throws IOException {
QuarkusRunnerExecutor quarkusProcessExecutor = new QuarkusRunnerExecutor();
StartedProcess process = quarkusProcessExecutor.start();

awaitStartup(quarkusProcessExecutor);

try {
File quarkusLogFile = getQuarkusLogFile();
await().atMost(10L, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> {
String log = FileUtils.readFileToString(quarkusLogFile, StandardCharsets.UTF_8);
return log.contains("Chuck Norris");
});
} finally {
if (process != null && process.getProcess().isAlive()) {
process.getProcess().destroy();
}
}
}

private File getQuarkusLogFile() {
String pathPrefix = "target/quarkus";
if (isNative()) {
pathPrefix += "-native";
}
return new File(pathPrefix + ".log");
}

private void awaitStartup(QuarkusProcessExecutor quarkusProcessExecutor) {
await().atMost(10, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> {
return isApplicationHealthy(quarkusProcessExecutor.getHttpPort());
public void testTimerLogMain() {
await().atMost(10L, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> {
List<String> log = Files.readAllLines(Paths.get("target/quarkus.log"));
return log.stream().anyMatch(line -> line.matches(".*timer.*Chuck.*"));
});
}

private boolean isApplicationHealthy(int port) {
try {
int status = RestAssured.given()
.port(port)
.get("/q/health")
.then()
.extract()
.statusCode();
return status == 200;
} catch (Exception e) {
return false;
}
}

private static boolean isNative() {
return NATIVE_ENABLED != null && NATIVE_ENABLED.equals("true");
}

static final class QuarkusRunnerExecutor extends QuarkusProcessExecutor {
@Override
protected List<String> command(String... args) {
List<String> command = super.command(args);
if (isNative()) {
command.add("-Dquarkus.log.file.path=target/quarkus-native.log");
} else {
command.add(1, "-Dquarkus.log.file.path=target/quarkus.log");
}
return command;
}

}
}
48 changes: 6 additions & 42 deletions timer-log-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
<quarkus.platform.version>3.14.2</quarkus.platform.version>
<camel-quarkus.platform.version>3.15.0-SNAPSHOT</camel-quarkus.platform.version>

<!-- TODO: https://github.com/apache/camel-quarkus/issues/3156 -->
<camel-quarkus.version>${camel-quarkus.platform.version}</camel-quarkus.version>

<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<camel-quarkus.platform.group-id>org.apache.camel.quarkus</camel-quarkus.platform.group-id>
Expand All @@ -53,8 +50,6 @@
<maven-jar-plugin.version>3.4.2</maven-jar-plugin.version>
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
<maven-surefire-plugin.version>3.5.0</maven-surefire-plugin.version>

<quarkus.runner>${project.build.directory}/quarkus-app/quarkus-run.jar</quarkus.runner>
</properties>

<dependencyManagement>
Expand All @@ -74,13 +69,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-bom-test</artifactId>
<version>${camel-quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -109,17 +97,6 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-tests-process-executor-support</artifactId>
<version>${camel-quarkus.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -161,27 +138,16 @@
</configuration>
</plugin>

<!-- Move surefire:test to integration-test phase to be able to execute the runner JAR from a test -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<executions>
<execution>
<id>default-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<failIfNoTests>false</failIfNoTests>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<quarkus.runner>${quarkus.runner}</quarkus.runner>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
<configuration>
<failIfNoTests>false</failIfNoTests>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemPropertyVariables>
</configuration>
</plugin>

<plugin>
Expand Down Expand Up @@ -286,7 +252,6 @@
</activation>
<properties>
<quarkus.native.enabled>true</quarkus.native.enabled>
<quarkus.runner>${project.build.directory}/${project.artifactId}-${project.version}-runner</quarkus.runner>
</properties>
<build>
<plugins>
Expand All @@ -302,7 +267,6 @@
<configuration>
<systemPropertyVariables>
<quarkus.native.enabled>${quarkus.native.enabled}</quarkus.native.enabled>
<quarkus.runner>${quarkus.runner}</quarkus.runner>
</systemPropertyVariables>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
package org.acme.main;

import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.quarkus.test.junit.main.QuarkusMainIntegrationTest;

@QuarkusIntegrationTest
@QuarkusMainIntegrationTest
class TimerLogMainIT extends TimerLogMainTest {

}
90 changes: 8 additions & 82 deletions timer-log-main/src/test/java/org/acme/main/TimerLogMainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,91 +16,17 @@
*/
package org.acme.main;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.apache.camel.quarkus.test.support.process.QuarkusProcessExecutor;
import org.apache.commons.io.FileUtils;
import io.quarkus.test.junit.main.Launch;
import io.quarkus.test.junit.main.LaunchResult;
import io.quarkus.test.junit.main.QuarkusMainTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.zeroturnaround.exec.StartedProcess;

import static org.awaitility.Awaitility.await;

@QuarkusTest
@QuarkusMainTest
public class TimerLogMainTest {

private static final String NATIVE_ENABLED = System.getProperty("quarkus.native.enabled");

@Test
public void testTimerLogMain() throws IOException {
QuarkusRunnerExecutor quarkusProcessExecutor = new QuarkusRunnerExecutor();
StartedProcess process = quarkusProcessExecutor.start();

awaitStartup(quarkusProcessExecutor);

try {
File quarkusLogFile = getQuarkusLogFile();
await().atMost(10L, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> {
String log = FileUtils.readFileToString(quarkusLogFile, StandardCharsets.UTF_8);
return log.contains("Greetings");
});
} finally {
if (process != null && process.getProcess().isAlive()) {
process.getProcess().destroy();
}
}
}

private File getQuarkusLogFile() {
String pathPrefix = "target/quarkus";
if (isNative()) {
pathPrefix += "-native";
}
return new File(pathPrefix + ".log");
}

private void awaitStartup(QuarkusProcessExecutor quarkusProcessExecutor) {
await().atMost(10, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> {
return isApplicationHealthy(quarkusProcessExecutor.getHttpPort());
});
}

private boolean isApplicationHealthy(int port) {
try {
int status = RestAssured.given()
.port(port)
.get("/q/health")
.then()
.extract()
.statusCode();
return status == 200;
} catch (Exception e) {
return false;
}
}

private static boolean isNative() {
return NATIVE_ENABLED != null && NATIVE_ENABLED.equals("true");
}

static final class QuarkusRunnerExecutor extends QuarkusProcessExecutor {
@Override
protected List<String> command(String... args) {
List<String> command = super.command(args);
if (isNative()) {
command.add("-Dquarkus.log.file.path=target/quarkus-native.log");
} else {
command.add(1, "-Dquarkus.log.file.path=target/quarkus.log");
}
command.add("Greetings");
command.add("2");
return command;
}

@Launch(value = { "Greetings", "2" }, exitCode = 15)
public void testTimerLogMain(LaunchResult result) {
Assertions.assertTrue(result.getOutput().contains("Body: Greetings"));
}
}

0 comments on commit 77a55a6

Please sign in to comment.