Skip to content

Commit

Permalink
Merge pull request #10324 from Garima829/JarTestBranch2.0
Browse files Browse the repository at this point in the history
Updating FarJarTest for Gradle
  • Loading branch information
geoand authored Jul 1, 2020
2 parents 0413903 + 136f16a commit f7e0495
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
package io.quarkus.gradle;

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;

import io.quarkus.test.devmode.util.DevModeTestUtils;

public class FastJarFormatWorksTest extends QuarkusGradleWrapperTestBase {
private static Future<?> jarRun;

@Test
public void testFastJarFormatWorks() throws Exception {
Expand All @@ -20,6 +32,55 @@ public void testFastJarFormatWorks() throws Exception {
assertThat(quarkusApp).exists();
Path jar = quarkusApp.resolve("quarkus-run.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", getQuarkusDevBrokenReason()).equals("hello"));
} finally {
process.destroy();
}
}

static 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
@@ -0,0 +1,24 @@
package io.quarkus.gradle;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import io.quarkus.utilities.JavaBinFinder;

public class LaunchUtils {

protected static Process launch(Path jar, File output) throws IOException {
List<String> commands = new ArrayList<>();
commands.add(JavaBinFinder.findBin());
commands.add("-jar");
commands.add(jar.toString());
ProcessBuilder processBuilder = new ProcessBuilder(commands.toArray(new String[0]));
processBuilder.redirectOutput(output);
processBuilder.redirectError(output);
return processBuilder.start();
}

}

0 comments on commit f7e0495

Please sign in to comment.