-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31645 from FroMage/31013
RuntimeUpdatesProcessor now supports hot replacement problems
- Loading branch information
Showing
7 changed files
with
142 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...ension/deployment/src/main/java/io/quarkus/extest/deployment/HotReplacementProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.quarkus.extest.deployment; | ||
|
||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem; | ||
import io.quarkus.extest.runtime.TestHotReplacementSetup; | ||
|
||
public class HotReplacementProcessor { | ||
@BuildStep | ||
public HotDeploymentWatchedFileBuildItem registerHotReplacementFile() { | ||
return new HotDeploymentWatchedFileBuildItem(TestHotReplacementSetup.HOT_REPLACEMENT_FILE, false); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...on/extension/runtime/src/main/java/io/quarkus/extest/runtime/HotReplacementException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.quarkus.extest.runtime; | ||
|
||
public class HotReplacementException extends Exception { | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...on/extension/runtime/src/main/java/io/quarkus/extest/runtime/TestHotReplacementSetup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.quarkus.extest.runtime; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Set; | ||
|
||
import io.quarkus.dev.ErrorPageGenerators; | ||
import io.quarkus.dev.spi.HotReplacementContext; | ||
import io.quarkus.dev.spi.HotReplacementSetup; | ||
|
||
public class TestHotReplacementSetup implements HotReplacementSetup { | ||
|
||
public final static String HOT_REPLACEMENT_FILE = "hot.replacement"; | ||
|
||
private static final String HOT_REPLACEMENT_EXCEPTION = HotReplacementException.class.getName(); | ||
|
||
private HotReplacementContext context; | ||
|
||
@Override | ||
public void setupHotDeployment(HotReplacementContext context) { | ||
context.consumeNoRestartChanges(this::noRestartChanges); | ||
this.context = context; | ||
ErrorPageGenerators.register(HOT_REPLACEMENT_EXCEPTION, this::generatePage); | ||
} | ||
|
||
public void noRestartChanges(Set<String> changedFiles) { | ||
if (changedFiles.contains(HOT_REPLACEMENT_FILE)) { | ||
for (Path resourcePath : context.getResourcesDir()) { | ||
Path myFile = resourcePath.resolve(HOT_REPLACEMENT_FILE); | ||
if (Files.exists(myFile)) { | ||
try { | ||
String contents = Files.readString(myFile); | ||
if ("throw".equals(contents)) | ||
throw new RuntimeException(new HotReplacementException()); | ||
return; | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private String generatePage(Throwable x) { | ||
return "Generated page for exception " + x; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...nsion/runtime/src/main/resources/META-INF/services/io.quarkus.dev.spi.HotReplacementSetup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.extest.runtime.TestHotReplacementSetup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...extension/tests/src/test/java/io/quarkus/it/extension/HotReplacementSetupDevModeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.quarkus.it.extension; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.extest.runtime.TestHotReplacementSetup; | ||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class HotReplacementSetupDevModeTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusDevModeTest TEST = new QuarkusDevModeTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(SystemPropertyTestEndpoint.class) | ||
.addAsResource(new StringAsset("nothing"), TestHotReplacementSetup.HOT_REPLACEMENT_FILE)); | ||
|
||
@Test | ||
public void watched() { | ||
RestAssured.get("/core/sysprop") | ||
.then() | ||
.statusCode(200); | ||
TEST.modifyResourceFile(TestHotReplacementSetup.HOT_REPLACEMENT_FILE, text -> "throw"); | ||
RestAssured.get("/core/sysprop") | ||
.then() | ||
.statusCode(500) | ||
.body(Matchers.containsString("Generated page for exception")); | ||
TEST.modifyResourceFile(TestHotReplacementSetup.HOT_REPLACEMENT_FILE, text -> "nothing"); | ||
RestAssured.get("/core/sysprop") | ||
.then() | ||
.statusCode(200); | ||
} | ||
} |