From dd023c5417cb6f03ba8ad54603aea6d0ffe95ba2 Mon Sep 17 00:00:00 2001 From: Garima Monga Date: Thu, 2 Jul 2020 15:07:27 +0530 Subject: [PATCH] Updated Uber-Jar,Fast-jar test and LaunchUtils --- .../gradle/FastJarFormatWorksTest.java | 32 ++------- .../java/io/quarkus/gradle/LaunchUtils.java | 18 +++++ .../gradle/UberJarFormatWorksTest.java | 66 +++++++++++++++++++ .../test-uber-jar-format-works/build.gradle | 29 ++++++++ .../gradle.properties | 2 + .../settings.gradle | 11 ++++ .../main/java/org/acme/ExampleResource.java | 19 ++++++ .../src/main/resources/application.properties | 4 ++ 8 files changed, 155 insertions(+), 26 deletions(-) create mode 100644 integration-tests/gradle/src/test/java/io/quarkus/gradle/UberJarFormatWorksTest.java create mode 100644 integration-tests/gradle/src/test/resources/test-uber-jar-format-works/build.gradle create mode 100644 integration-tests/gradle/src/test/resources/test-uber-jar-format-works/gradle.properties create mode 100644 integration-tests/gradle/src/test/resources/test-uber-jar-format-works/settings.gradle create mode 100644 integration-tests/gradle/src/test/resources/test-uber-jar-format-works/src/main/java/org/acme/ExampleResource.java create mode 100644 integration-tests/gradle/src/test/resources/test-uber-jar-format-works/src/main/resources/application.properties diff --git a/integration-tests/gradle/src/test/java/io/quarkus/gradle/FastJarFormatWorksTest.java b/integration-tests/gradle/src/test/java/io/quarkus/gradle/FastJarFormatWorksTest.java index 67c78306910c4..7b2df6c0e47f3 100644 --- a/integration-tests/gradle/src/test/java/io/quarkus/gradle/FastJarFormatWorksTest.java +++ b/integration-tests/gradle/src/test/java/io/quarkus/gradle/FastJarFormatWorksTest.java @@ -1,18 +1,16 @@ package io.quarkus.gradle; +import static io.quarkus.gradle.LaunchUtils.dumpFileContentOnFailure; import static io.quarkus.gradle.LaunchUtils.launch; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import java.io.File; import java.nio.file.Path; -import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.function.Supplier; import org.apache.commons.io.FileUtils; -import org.apache.log4j.Logger; import org.awaitility.core.ConditionTimeoutException; import org.junit.jupiter.api.Test; @@ -37,7 +35,7 @@ public void testFastJarFormatWorks() throws Exception { output.createNewFile(); Process process = launch(jar, output); try { - // Wait until server up + //Wait until server up dumpFileContentOnFailure(() -> { await() .pollDelay(1, TimeUnit.SECONDS) @@ -50,37 +48,19 @@ public void testFastJarFormatWorks() throws Exception { assertThatOutputWorksCorrectly(logs); // test that the application name and version are properly set - assertThat(DevModeTestUtils.getHttpResponse("/hello", getQuarkusDevBrokenReason()).equals("hello")); + assertThat(DevModeTestUtils.getHttpResponse("/hello", () -> { + return jarRun == null ? null : jarRun.isDone() ? "jar run mode has terminated" : null; + }).equals("hello")); } finally { process.destroy(); } } - static void assertThatOutputWorksCorrectly(String logs) { + private void assertThatOutputWorksCorrectly(String logs) { assertThat(logs.isEmpty()).isFalse(); String infoLogLevel = "INFO"; assertThat(logs.contains(infoLogLevel)).isTrue(); assertThat(logs.contains("cdi, resteasy")).isTrue(); } - private void dumpFileContentOnFailure(final Callable operation, final File logFile, - final Class failureType) throws Exception { - - final Logger log = Logger.getLogger(FastJarFormatWorksTest.class); - try { - operation.call(); - } catch (Throwable t) { - log.error("Dumping logs that were generated in " + logFile + " for an operation that resulted in " - + t.getClass().getName() + ":", t); - - throw t; - } - } - - private static Supplier getQuarkusDevBrokenReason() { - return () -> { - return jarRun == null ? null : jarRun.isDone() ? "jar run mode has terminated" : null; - }; - } - } diff --git a/integration-tests/gradle/src/test/java/io/quarkus/gradle/LaunchUtils.java b/integration-tests/gradle/src/test/java/io/quarkus/gradle/LaunchUtils.java index 3f75f85b87d3b..1fc5ccad38c63 100644 --- a/integration-tests/gradle/src/test/java/io/quarkus/gradle/LaunchUtils.java +++ b/integration-tests/gradle/src/test/java/io/quarkus/gradle/LaunchUtils.java @@ -5,10 +5,15 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Callable; + +// import org.apache.log4j.Logger; +import org.jboss.logging.Logger; import io.quarkus.utilities.JavaBinFinder; public class LaunchUtils { + private static final Logger log = Logger.getLogger(LaunchUtils.class); protected static Process launch(Path jar, File output) throws IOException { List commands = new ArrayList<>(); @@ -21,4 +26,17 @@ protected static Process launch(Path jar, File output) throws IOException { return processBuilder.start(); } + public static void dumpFileContentOnFailure(final Callable operation, final File logFile, + final Class failureType) throws Exception { + + try { + operation.call(); + } catch (Throwable t) { + log.error("Dumping logs that were generated in " + logFile + " for an operation that resulted in " + + t.getClass().getName() + ":", t); + + throw t; + } + } + } diff --git a/integration-tests/gradle/src/test/java/io/quarkus/gradle/UberJarFormatWorksTest.java b/integration-tests/gradle/src/test/java/io/quarkus/gradle/UberJarFormatWorksTest.java new file mode 100644 index 0000000000000..2374164828675 --- /dev/null +++ b/integration-tests/gradle/src/test/java/io/quarkus/gradle/UberJarFormatWorksTest.java @@ -0,0 +1,66 @@ +package io.quarkus.gradle; + +import static io.quarkus.gradle.LaunchUtils.dumpFileContentOnFailure; +import static io.quarkus.gradle.LaunchUtils.launch; +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +import java.io.File; +import java.nio.file.Path; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.io.FileUtils; +import org.awaitility.core.ConditionTimeoutException; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.devmode.util.DevModeTestUtils; + +public class UberJarFormatWorksTest extends QuarkusGradleWrapperTestBase { + + private static Future jarRun; + + @Test + public void testUberJarFormatWorks() throws Exception { + + final File projectDir = getProjectDir("test-uber-jar-format-works"); + runGradleWrapper(projectDir, "clean", "build"); + final Path quarkusApp = projectDir.toPath().resolve("build"); + assertThat(quarkusApp).exists(); + Path jar = quarkusApp.resolve("uber-jar-test-1.0.0-SNAPSHOT-runner.jar"); + assertThat(jar).exists(); + + File output = new File(projectDir, "build/output.log"); + output.createNewFile(); + Process process = launch(jar, output); + try { + // Wait until server up + dumpFileContentOnFailure(() -> { + await() + .pollDelay(1, TimeUnit.SECONDS) + .atMost(1, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/hello", 200)); + return null; + }, output, ConditionTimeoutException.class); + + String logs = FileUtils.readFileToString(output, "UTF-8"); + + assertThatOutputWorksCorrectly(logs); + + // test that the application name and version are properly set + assertThat(DevModeTestUtils.getHttpResponse("/hello", () -> { + return jarRun == null ? null : jarRun.isDone() ? "jar run mode has terminated" : null; + }).equals("hello")); + } finally { + process.destroy(); + } + + } + + private void assertThatOutputWorksCorrectly(String logs) { + assertThat(logs.isEmpty()).isFalse(); + String infoLogLevel = "INFO"; + assertThat(logs.contains(infoLogLevel)).isTrue(); + assertThat(logs.contains("cdi, resteasy")).isTrue(); + } + +} diff --git a/integration-tests/gradle/src/test/resources/test-uber-jar-format-works/build.gradle b/integration-tests/gradle/src/test/resources/test-uber-jar-format-works/build.gradle new file mode 100644 index 0000000000000..6484513f4f4aa --- /dev/null +++ b/integration-tests/gradle/src/test/resources/test-uber-jar-format-works/build.gradle @@ -0,0 +1,29 @@ +plugins { + id 'java' + id 'io.quarkus' +} + +repositories { + mavenLocal() + mavenCentral() +} + +dependencies { + implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}") + implementation 'io.quarkus:quarkus-resteasy' + + testImplementation 'io.quarkus:quarkus-junit5' + testImplementation 'io.rest-assured:rest-assured' +} + +group 'org.acme' +version '1.0.0-SNAPSHOT' + +compileJava { + options.encoding = 'UTF-8' + options.compilerArgs << '-parameters' +} + +compileTestJava { + options.encoding = 'UTF-8' +} diff --git a/integration-tests/gradle/src/test/resources/test-uber-jar-format-works/gradle.properties b/integration-tests/gradle/src/test/resources/test-uber-jar-format-works/gradle.properties new file mode 100644 index 0000000000000..ec2b6ef199c2c --- /dev/null +++ b/integration-tests/gradle/src/test/resources/test-uber-jar-format-works/gradle.properties @@ -0,0 +1,2 @@ +quarkusPlatformArtifactId=quarkus-bom +quarkusPlatformGroupId=io.quarkus diff --git a/integration-tests/gradle/src/test/resources/test-uber-jar-format-works/settings.gradle b/integration-tests/gradle/src/test/resources/test-uber-jar-format-works/settings.gradle new file mode 100644 index 0000000000000..176f0396673af --- /dev/null +++ b/integration-tests/gradle/src/test/resources/test-uber-jar-format-works/settings.gradle @@ -0,0 +1,11 @@ +pluginManagement { + repositories { + mavenLocal() + mavenCentral() + gradlePluginPortal() + } + plugins { + id 'io.quarkus' version "${quarkusPluginVersion}" + } +} +rootProject.name='uber-jar-test' \ No newline at end of file diff --git a/integration-tests/gradle/src/test/resources/test-uber-jar-format-works/src/main/java/org/acme/ExampleResource.java b/integration-tests/gradle/src/test/resources/test-uber-jar-format-works/src/main/java/org/acme/ExampleResource.java new file mode 100644 index 0000000000000..2cd1720641843 --- /dev/null +++ b/integration-tests/gradle/src/test/resources/test-uber-jar-format-works/src/main/java/org/acme/ExampleResource.java @@ -0,0 +1,19 @@ +package org.acme; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.eclipse.microprofile.config.inject.ConfigProperty; + +@Path("/hello") +public class ExampleResource { + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return "hello"; + } + +} \ No newline at end of file diff --git a/integration-tests/gradle/src/test/resources/test-uber-jar-format-works/src/main/resources/application.properties b/integration-tests/gradle/src/test/resources/test-uber-jar-format-works/src/main/resources/application.properties new file mode 100644 index 0000000000000..109410b9b21db --- /dev/null +++ b/integration-tests/gradle/src/test/resources/test-uber-jar-format-works/src/main/resources/application.properties @@ -0,0 +1,4 @@ +# Configuration file +# key = value +my-app-name=${quarkus.application.name} +quarkus.package.type=uber-jar