Skip to content

Commit

Permalink
Updated Uber-Jar,Fast-jar test and LaunchUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
Garima Monga committed Jul 2, 2020
1 parent a2918c8 commit dd023c5
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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)
Expand All @@ -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<Void> operation, final File logFile,
final Class<? extends Throwable> 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<String> getQuarkusDevBrokenReason() {
return () -> {
return jarRun == null ? null : jarRun.isDone() ? "jar run mode has terminated" : null;
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> commands = new ArrayList<>();
Expand All @@ -21,4 +26,17 @@ protected static Process launch(Path jar, File output) throws IOException {
return processBuilder.start();
}

public static void dumpFileContentOnFailure(final Callable<Void> operation, final File logFile,
final Class<? extends Throwable> 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;
}
}

}
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
quarkusPlatformArtifactId=quarkus-bom
quarkusPlatformGroupId=io.quarkus
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pluginManagement {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
}
plugins {
id 'io.quarkus' version "${quarkusPluginVersion}"
}
}
rootProject.name='uber-jar-test'
Original file line number Diff line number Diff line change
@@ -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";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Configuration file
# key = value
my-app-name=${quarkus.application.name}
quarkus.package.type=uber-jar

0 comments on commit dd023c5

Please sign in to comment.