Skip to content

Commit

Permalink
Merge pull request #19018 from geoand/#19011
Browse files Browse the repository at this point in the history
Add force restart and toggle live reload options to DevUI
  • Loading branch information
geoand authored Jul 27, 2021
2 parents 768ac03 + 90f06a3 commit 76d1dc7
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,14 @@ void installBuiltins(DevModeType devModeType) {
}
}));
commands.add(new ConsoleCommand('l', "Toggle live reload",
new ConsoleCommand.HelpState(() -> RuntimeUpdatesProcessor.INSTANCE.isLiveReloadEnabled()),
() -> RuntimeUpdatesProcessor.INSTANCE.toggleLiveReloadEnabled()));
new ConsoleCommand.HelpState(() -> RuntimeUpdatesProcessor.INSTANCE.isLiveReloadEnabled()), () -> {
// TODO: same hack as above
if (TestSupport.instance().isPresent()) {
TestSupport.instance().get().toggleLiveReloadEnabled();
} else {
RuntimeUpdatesProcessor.INSTANCE.toggleLiveReloadEnabled();
}
}));
}

ConsoleContext context = createContext("System");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,13 @@ public boolean doScan(boolean userInitiated, boolean forceRestart) {
|| (IsolatedDevModeMain.deploymentProblem != null && userInitiated) || configFileRestartNeeded);
if (restartNeeded) {
String changeString = changedFilesForRestart.stream().map(Path::getFileName).map(Object::toString)
.collect(Collectors.joining(", ")) + ".";
log.infof("Restarting quarkus due to changes in " + changeString);
.collect(Collectors.joining(", "));
if (!changeString.isEmpty()) {
log.infof("Restarting quarkus due to changes in %s.", changeString);
} else if (forceRestart && userInitiated) {
log.info("Restarting as requested by the user.");
}

restartCallback.accept(filesChanged, changedClassResults);
long timeNanoSeconds = System.nanoTime() - startNanoseconds;
log.infof("Live reload total time: %ss ", Timing.convertToBigDecimalSeconds(timeNanoSeconds));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public interface TestController {
*/
boolean toggleInstrumentation();

/**
* Toggles instrumentation based reload.
*
* @return <code>true</code> if this change to do instrumentation based reload
*/
boolean toggleLiveReloadEnabled();

/**
* Print the current results and failures
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ default void setInstrumentationBasedReload(boolean ibr) {

}

default void setLiveReloadEnabled(boolean lre) {

}

default void testCompileFailed(String message) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,18 @@ public boolean toggleInstrumentation() {
return ibr;
}

@Override
public boolean toggleLiveReloadEnabled() {

boolean lr = RuntimeUpdatesProcessor.INSTANCE.toggleLiveReloadEnabled();

for (TestListener i : testListeners) {
i.setLiveReloadEnabled(lr);
}

return lr;
}

@Override
public void printFullResults() {
if (currentState().getFailingClasses().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class ContinuousTestingWebsocketListener {

private static Consumer<State> stateListener;
private static volatile State lastState = new State(false, false, 0, 0, 0, 0, false, false, false);
private static volatile State lastState = new State(false, false, 0, 0, 0, 0, false, false, false, true);

public static Consumer<State> getStateListener() {
return stateListener;
Expand Down Expand Up @@ -35,39 +35,47 @@ public static void setInProgress(boolean inProgress) {
State state = lastState;
if (state != null) {
setLastState(new State(state.running, inProgress, state.run, state.passed, state.failed, state.skipped,
state.isBrokenOnly, state.isTestOutput, state.isInstrumentationBasedReload));
state.isBrokenOnly, state.isTestOutput, state.isInstrumentationBasedReload, state.isLiveReload));
}
}

public static void setRunning(boolean running) {
State state = lastState;
if (state != null) {
setLastState(new State(running, running && state.inProgress, state.run, state.passed, state.failed, state.skipped,
state.isBrokenOnly, state.isTestOutput, state.isInstrumentationBasedReload));
state.isBrokenOnly, state.isTestOutput, state.isInstrumentationBasedReload, state.isLiveReload));
}
}

public static void setBrokenOnly(boolean brokenOnly) {
State state = lastState;
if (state != null) {
setLastState(new State(state.running, state.inProgress, state.run, state.passed, state.failed, state.skipped,
brokenOnly, state.isTestOutput, state.isInstrumentationBasedReload));
brokenOnly, state.isTestOutput, state.isInstrumentationBasedReload, state.isLiveReload));
}
}

public static void setTestOutput(boolean testOutput) {
State state = lastState;
if (state != null) {
setLastState(new State(state.running, state.inProgress, state.run, state.passed, state.failed, state.skipped,
state.isBrokenOnly, testOutput, state.isInstrumentationBasedReload));
state.isBrokenOnly, testOutput, state.isInstrumentationBasedReload, state.isLiveReload));
}
}

public static void setInstrumentationBasedReload(boolean instrumentationBasedReload) {
State state = lastState;
if (state != null) {
setLastState(new State(state.running, state.inProgress, state.run, state.passed, state.failed, state.skipped,
state.isBrokenOnly, state.isTestOutput, instrumentationBasedReload));
state.isBrokenOnly, state.isTestOutput, instrumentationBasedReload, state.isLiveReload));
}
}

public static void setLiveReloadEnabled(boolean liveReload) {
State state = lastState;
if (state != null) {
setLastState(new State(state.running, state.inProgress, state.run, state.passed, state.failed, state.skipped,
state.isBrokenOnly, state.isTestOutput, state.isInstrumentationBasedReload, liveReload));
}
}

Expand All @@ -81,9 +89,10 @@ public static class State {
public final boolean isBrokenOnly;
public final boolean isTestOutput;
public final boolean isInstrumentationBasedReload;
public final boolean isLiveReload;

public State(boolean running, boolean inProgress, long run, long passed, long failed, long skipped,
boolean isBrokenOnly, boolean isTestOutput, boolean isInstrumentationBasedReload) {
boolean isBrokenOnly, boolean isTestOutput, boolean isInstrumentationBasedReload, boolean isLiveReload) {
this.running = running;
this.inProgress = inProgress;
this.run = run;
Expand All @@ -93,6 +102,7 @@ public State(boolean running, boolean inProgress, long run, long passed, long fa
this.isBrokenOnly = isBrokenOnly;
this.isTestOutput = isTestOutput;
this.isInstrumentationBasedReload = isInstrumentationBasedReload;
this.isLiveReload = isLiveReload;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void listenerRegistered(TestController testController) {
public void testsEnabled() {
ContinuousTestingWebsocketListener
.setLastState(
new ContinuousTestingWebsocketListener.State(true, true, 0L, 0L, 0L, 0L, false, false, false));
new ContinuousTestingWebsocketListener.State(true, true, 0L, 0L, 0L, 0L, false, false, false, true));
}

@Override
Expand Down Expand Up @@ -55,7 +55,8 @@ public void runComplete(TestRunResults testRunResults) {
testRunResults.getFailedCount(), testRunResults.getSkippedCount(),
ContinuousTestingWebsocketListener.getLastState().isBrokenOnly,
ContinuousTestingWebsocketListener.getLastState().isTestOutput,
ContinuousTestingWebsocketListener.getLastState().isInstrumentationBasedReload));
ContinuousTestingWebsocketListener.getLastState().isInstrumentationBasedReload,
ContinuousTestingWebsocketListener.getLastState().isLiveReload));
}

@Override
Expand Down Expand Up @@ -86,4 +87,9 @@ public void setInstrumentationBasedReload(boolean ibr) {
ContinuousTestingWebsocketListener.setInstrumentationBasedReload(ibr);
}

@Override
public void setLiveReloadEnabled(boolean lre) {
ContinuousTestingWebsocketListener.setLiveReloadEnabled(lre);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.deployment.dev.RuntimeUpdatesProcessor;
import io.quarkus.deployment.dev.testing.TestClassResult;
import io.quarkus.deployment.dev.testing.TestListenerBuildItem;
import io.quarkus.deployment.dev.testing.TestRunResults;
Expand Down Expand Up @@ -75,7 +76,7 @@ DevConsoleRouteBuildItem handleTestStatus(LaunchModeBuildItem launchModeBuildIte
//DISABLED, RUNNING (run id), RUN (run id, start time, nextRunQueued)
//GET tests/results

return new DevConsoleRouteBuildItem("tests/status", "GET", new Handler<RoutingContext>() {
return new DevConsoleRouteBuildItem("tests/status", "GET", new Handler<>() {
@Override
public void handle(RoutingContext event) {
jsonResponse(event);
Expand Down Expand Up @@ -108,7 +109,7 @@ void toggleTestRunner(LaunchModeBuildItem launchModeBuildItem, BuildProducer<Dev
if (testsDisabled(launchModeBuildItem, ts)) {
return;
}
routeProducer.produce(new DevConsoleRouteBuildItem("tests/toggle", "POST", new Handler<RoutingContext>() {
routeProducer.produce(new DevConsoleRouteBuildItem("tests/toggle", "POST", new Handler<>() {
@Override
public void handle(RoutingContext event) {
if (ts.get().isStarted()) {
Expand All @@ -122,7 +123,7 @@ public void handle(RoutingContext event) {
event.response().putHeader("Content-Type", "application/json; charset=utf-8").end(object.build());
}
}));
routeProducer.produce(new DevConsoleRouteBuildItem("tests/toggle-broken-only", "POST", new Handler<RoutingContext>() {
routeProducer.produce(new DevConsoleRouteBuildItem("tests/toggle-broken-only", "POST", new Handler<>() {
@Override
public void handle(RoutingContext event) {
boolean brokenOnlyMode = ts.get().toggleBrokenOnlyMode();
Expand All @@ -134,7 +135,7 @@ public void handle(RoutingContext event) {
}

private boolean testsDisabled(LaunchModeBuildItem launchModeBuildItem, Optional<TestSupport> ts) {
return !ts.isPresent() || launchModeBuildItem.getDevModeType().orElse(null) != DevModeType.LOCAL;
return ts.isEmpty() || launchModeBuildItem.getDevModeType().orElse(null) != DevModeType.LOCAL;
}

@BuildStep(onlyIf = IsDevelopment.class)
Expand All @@ -143,7 +144,7 @@ DevConsoleRouteBuildItem runAllTests(LaunchModeBuildItem launchModeBuildItem) {
if (testsDisabled(launchModeBuildItem, ts)) {
return null;
}
return new DevConsoleRouteBuildItem("tests/runall", "POST", new Handler<RoutingContext>() {
return new DevConsoleRouteBuildItem("tests/runall", "POST", new Handler<>() {
@Override
public void handle(RoutingContext event) {
ts.get().runAllTests();
Expand All @@ -152,12 +153,12 @@ public void handle(RoutingContext event) {
}

@BuildStep(onlyIf = IsDevelopment.class)
DevConsoleRouteBuildItem runFailedTests(LaunchModeBuildItem launchModeBuildItem) {
DevConsoleRouteBuildItem toggleTestOutput(LaunchModeBuildItem launchModeBuildItem) {
Optional<TestSupport> ts = TestSupport.instance();
if (testsDisabled(launchModeBuildItem, ts)) {
return null;
}
return new DevConsoleRouteBuildItem("tests/toggle-test-output", "POST", new Handler<RoutingContext>() {
return new DevConsoleRouteBuildItem("tests/toggle-test-output", "POST", new Handler<>() {
@Override
public void handle(RoutingContext event) {

Expand All @@ -170,12 +171,12 @@ public void handle(RoutingContext event) {
}

@BuildStep(onlyIf = IsDevelopment.class)
DevConsoleRouteBuildItem toggleTestOutput(LaunchModeBuildItem launchModeBuildItem) {
DevConsoleRouteBuildItem runFailedTests(LaunchModeBuildItem launchModeBuildItem) {
Optional<TestSupport> ts = TestSupport.instance();
if (testsDisabled(launchModeBuildItem, ts)) {
return null;
}
return new DevConsoleRouteBuildItem("tests/runfailed", "POST", new Handler<RoutingContext>() {
return new DevConsoleRouteBuildItem("tests/runfailed", "POST", new Handler<>() {
@Override
public void handle(RoutingContext event) {
ts.get().runFailedTests();
Expand All @@ -189,7 +190,7 @@ DevConsoleRouteBuildItem printfailures(LaunchModeBuildItem launchModeBuildItem)
if (testsDisabled(launchModeBuildItem, ts)) {
return null;
}
return new DevConsoleRouteBuildItem("tests/printfailures", "POST", new Handler<RoutingContext>() {
return new DevConsoleRouteBuildItem("tests/printfailures", "POST", new Handler<>() {
@Override
public void handle(RoutingContext event) {
ts.get().printFullResults();
Expand All @@ -203,7 +204,7 @@ DevConsoleRouteBuildItem toggleInstrumentation(LaunchModeBuildItem launchModeBui
if (testsDisabled(launchModeBuildItem, ts)) {
return null;
}
return new DevConsoleRouteBuildItem("tests/toggle-instrumentation", "POST", new Handler<RoutingContext>() {
return new DevConsoleRouteBuildItem("tests/toggle-instrumentation", "POST", new Handler<>() {
@Override
public void handle(RoutingContext event) {
boolean instrumentationEnabled = ts.get().toggleInstrumentation();
Expand All @@ -214,14 +215,44 @@ public void handle(RoutingContext event) {
});
}

@BuildStep(onlyIf = IsDevelopment.class)
DevConsoleRouteBuildItem toggleLiveReloadEnabled(LaunchModeBuildItem launchModeBuildItem) {
Optional<TestSupport> ts = TestSupport.instance();
if (testsDisabled(launchModeBuildItem, ts)) {
return null;
}
return new DevConsoleRouteBuildItem("tests/toggle-live-reload", "POST", new Handler<>() {
@Override
public void handle(RoutingContext event) {
boolean liveReloadEnabled = ts.get().toggleLiveReloadEnabled();
Json.JsonObjectBuilder object = Json.object();
object.put("liveReloadEnabled", liveReloadEnabled);
event.response().putHeader("Content-Type", "application/json; charset=utf-8").end(object.build());
}
});
}

@BuildStep(onlyIf = IsDevelopment.class)
DevConsoleRouteBuildItem forceRestart(LaunchModeBuildItem launchModeBuildItem) {
if (testsDisabled(launchModeBuildItem, TestSupport.instance())) {
return null;
}
return new DevConsoleRouteBuildItem("tests/force-restart", "POST", new Handler<>() {
@Override
public void handle(RoutingContext event) {
RuntimeUpdatesProcessor.INSTANCE.doScan(true, true);
}
});
}

@BuildStep(onlyIf = IsDevelopment.class)
DevConsoleRouteBuildItem handleTestResult(LaunchModeBuildItem launchModeBuildItem) {
Optional<TestSupport> ts = TestSupport.instance();
if (testsDisabled(launchModeBuildItem, ts)) {
return null;
}

return new DevConsoleRouteBuildItem("tests/result", "GET", new Handler<RoutingContext>() {
return new DevConsoleRouteBuildItem("tests/result", "GET", new Handler<>() {
@Override
public void handle(RoutingContext event) {
TestRunResults testRunResults = ts.get().getResults();
Expand Down
Loading

0 comments on commit 76d1dc7

Please sign in to comment.