Skip to content

Commit

Permalink
Merge pull request #87 from jsmrcka/live-reload-add-class-td-1.11
Browse files Browse the repository at this point in the history
[1.11] Extend Quarkus live reload test
  • Loading branch information
kshpak authored May 21, 2021
2 parents 57fe67f + 41fe939 commit 16589a7
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 36 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ The goal of this test is to test Quarkus maven artifact generator, i.e. to to us
empty (Hello World) skeleton and build it in Quarkus dev mode. The objective is to make sure all required
extensions are correctly found.

Next, the project is run in dev mode, time to the first O.K. request is measured, a ```.java``` file is changed and the time
it took to get the expected results after hot reload is measured.
Next, the project is run in dev mode, time to the first O.K. request is measured. Then, an existing ```.java``` file
is changed and a new one is added, which causes hot reload. After that, a request to the modified file is issued,
and the time it took to get the expected results is measured. Also, separate request to the added file is issued
to verify that the new resource has been loaded. Response time is not measured in this case.

The whole run is executed as a warm-up to download the Internet and then again to measure the times.
The properties for thresholds are stored in [app-generated-skeleton/threshold.properties](./app-generated-skeleton/threshold.properties).
Expand Down
14 changes: 14 additions & 0 deletions app-generated-skeleton/AddedController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.my.group;

import javax.inject.Singleton;
import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("/hello-added")
@Singleton
public class AddedController {
@GET
public String sayHello() {
return "Hello added";
}
}
7 changes: 6 additions & 1 deletion app-generated-skeleton/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ This is a placeholder directory to keep

It also keeps dummy [application.properties](./application.properties) used for the
generated skeleton purely to satisfy some extensions' expected non-empty directives.
No functional code is actually run for the skeleton though. It merely checks the generator and Hello World in dev mode.

Another resource that kept here is an [AddedController](./AddedController.java) class,
which is used to test live reload of added classes.

Apart from that, no functional code is actually run for the skeleton though.
It merely checks the generator and Hello World in dev mode.

When executed, the test actually uses ```ARTIFACT_GENERATOR_WORKSPACE``` directory
to generate the ```app-generated-skeleton``` project into. If neither sys prop nor env prop ```ARTIFACT_GENERATOR_WORKSPACE```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,10 @@
*/
package io.quarkus.ts.startstop;

import io.quarkus.ts.startstop.utils.Apps;
import io.quarkus.ts.startstop.utils.Commands;
import io.quarkus.ts.startstop.utils.FakeOIDCServer;
import io.quarkus.ts.startstop.utils.LogBuilder;
import io.quarkus.ts.startstop.utils.Logs;
import io.quarkus.ts.startstop.utils.MvnCmds;
import io.quarkus.ts.startstop.utils.TestFlags;
import io.quarkus.ts.startstop.utils.URLContent;
import io.quarkus.ts.startstop.utils.WebpageTester;
import org.jboss.logging.Logger;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Date;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static io.quarkus.ts.startstop.utils.Commands.adjustPrettyPrintForJsonLogging;
import static io.quarkus.ts.startstop.utils.Commands.cleanDirOrFile;
import static io.quarkus.ts.startstop.utils.Commands.confAppPropsForSkeleton;
import static io.quarkus.ts.startstop.utils.Commands.copyFileForSkeleton;
import static io.quarkus.ts.startstop.utils.Commands.getArtifactGeneBaseDir;
import static io.quarkus.ts.startstop.utils.Commands.getGeneratorCommand;
import static io.quarkus.ts.startstop.utils.Commands.getOpenedFDs;
Expand All @@ -70,6 +43,35 @@
import static io.quarkus.ts.startstop.utils.Logs.writeReport;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Date;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.jboss.logging.Logger;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;

import io.quarkus.ts.startstop.utils.Apps;
import io.quarkus.ts.startstop.utils.Commands;
import io.quarkus.ts.startstop.utils.FakeOIDCServer;
import io.quarkus.ts.startstop.utils.LogBuilder;
import io.quarkus.ts.startstop.utils.Logs;
import io.quarkus.ts.startstop.utils.MvnCmds;
import io.quarkus.ts.startstop.utils.TestFlags;
import io.quarkus.ts.startstop.utils.URLContent;
import io.quarkus.ts.startstop.utils.WebpageTester;

/**
* Tests for quarkus-maven-plugin generator
*
Expand Down Expand Up @@ -233,16 +235,28 @@ public void testRuntime(TestInfo testInfo, String[] extensions, Set<TestFlags> f
}

LOGGER.info("Testing reload...");
// modify existing class
Path srcFile = Paths.get(appDir + File.separator + "src" + File.separator + "main" + File.separator + "java" + File.separator +
"org" + File.separator + "my" + File.separator + "group" + File.separator + "SpringGreetingController.java");
appendlnSection(whatIDidReport, "Reloading class: " + srcFile.toAbsolutePath());
try (Stream<String> src = Files.lines(srcFile)) {
Files.write(srcFile, src.map(l -> l.replaceAll("Hello", "Bye")).collect(Collectors.toList()));
}

// add new class
Path addedFile = Paths
.get(appDir + File.separator + "src" + File.separator + "main" + File.separator + "java" + File.separator +
"org" + File.separator + "my" + File.separator + "group" + File.separator + "AddedController.java");
appendlnSection(whatIDidReport, "Adding class: " + addedFile.toAbsolutePath());
copyFileForSkeleton("AddedController.java", addedFile);

// test modified class and measure time
long timeToReloadedOKRequest = WebpageTester.testWeb(skeletonApp.urlContent[1][0], 60,
skeletonApp.urlContent[1][1], true);

// test added class
WebpageTester.testWeb(skeletonApp.urlContent[2][0], 60, skeletonApp.urlContent[2][1], false);

LOGGER.info("Terminate and scan logs...");
pA.getInputStream().available();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,15 @@ public static boolean waitForTcpClosed(String host, int port, long loopTimeoutS)
// TODO we should get rid of it once Quarkus progresses with walid config per extension in generated examples
public static void confAppPropsForSkeleton(String appDir) throws IOException {
// Config, see app-generated-skeleton/README.md
String appPropsSrc = BASE_DIR + File.separator + Apps.GENERATED_SKELETON.dir + File.separator + "application.properties";
String appPropsDst = appDir + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "application.properties";
Files.copy(Paths.get(appPropsSrc),
Paths.get(appPropsDst), StandardCopyOption.REPLACE_EXISTING);
final String appRelativePath =
"src" + File.separator + "main" + File.separator + "resources" + File.separator + "application.properties";
copyFileForSkeleton("application.properties", Paths.get(appDir + File.separator + appRelativePath));
}

public static void copyFileForSkeleton(String skeletonFileRelativePath, Path destPath)
throws IOException {
final String srcPath = BASE_DIR + File.separator + Apps.GENERATED_SKELETON.dir + File.separator + skeletonFileRelativePath;
Files.copy(Paths.get(srcPath), destPath, StandardCopyOption.REPLACE_EXISTING);
}

public static void adjustPrettyPrintForJsonLogging(String appDir) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public enum URLContent {
}),
GENERATED_SKELETON(new String[][]{
new String[]{"http://localhost:8080", "Congratulations"},
new String[]{"http://localhost:8080/hello-spring", "Bye Spring"}
new String[]{"http://localhost:8080/hello-spring", "Bye Spring"},
new String[]{"http://localhost:8080/hello-added", "Hello added"}
});

public final String[][] urlContent;
Expand Down

0 comments on commit 16589a7

Please sign in to comment.