-
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 #35399 from mkouba/issue-35381
Dev mode: fix several problems when the initial build fails
- Loading branch information
Showing
8 changed files
with
148 additions
and
17 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
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
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
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
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
63 changes: 63 additions & 0 deletions
63
integration-tests/devmode/src/test/java/io/quarkus/test/reload/CrashAfterReloadTest.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,63 @@ | ||
package io.quarkus.test.reload; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
|
||
// https://github.com/quarkusio/quarkus/issues/35381 | ||
public class CrashAfterReloadTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusDevModeTest config = new QuarkusDevModeTest() | ||
.setAllowFailedStart(true) | ||
.withApplicationRoot(root -> root.addClasses(SomeBean.class, SomeBeanClient.class)); | ||
|
||
@Test | ||
public void testRestarts() { | ||
// The build should fail initially | ||
RestAssured.with() | ||
.get("/test") | ||
.then() | ||
.statusCode(500); | ||
|
||
String someBeanWithoutScope = "public class SomeBean {"; | ||
String someBeanWithScope = "@ApplicationScoped public class SomeBean {"; | ||
String originalImport = "import jakarta.annotation.PostConstruct;"; | ||
String newImport = "import jakarta.annotation.PostConstruct;\nimport jakarta.enterprise.context.ApplicationScoped;"; | ||
|
||
// Add the scope annotation | ||
config.modifySourceFile(SomeBean.class, | ||
s -> s.replace(someBeanWithoutScope, someBeanWithScope).replace(originalImport, newImport)); | ||
|
||
RestAssured.with() | ||
.get("/test") | ||
.then() | ||
.statusCode(200) | ||
.body(containsString("pong")); | ||
|
||
// Remove the scope annotation - the build should fail but the dev mode should not exit | ||
config.modifySourceFile(SomeBean.class, | ||
s -> s.replace(someBeanWithScope, someBeanWithoutScope)); | ||
|
||
RestAssured.with() | ||
.get("/test") | ||
.then() | ||
.statusCode(500); | ||
|
||
// Add the scope annotation | ||
config.modifySourceFile(SomeBean.class, | ||
s -> s.replace(someBeanWithoutScope, someBeanWithScope)); | ||
|
||
RestAssured.with() | ||
.get("/test") | ||
.then() | ||
.statusCode(200) | ||
.body(containsString("pong")); | ||
|
||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
integration-tests/devmode/src/test/java/io/quarkus/test/reload/SomeBean.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,19 @@ | ||
package io.quarkus.test.reload; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
|
||
//missing scope - the build fails during the first dev mode start | ||
public class SomeBean { | ||
|
||
private String msg; | ||
|
||
public String ping() { | ||
return msg; | ||
} | ||
|
||
@PostConstruct | ||
void init() { | ||
msg = "pong"; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
integration-tests/devmode/src/test/java/io/quarkus/test/reload/SomeBeanClient.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,27 @@ | ||
package io.quarkus.test.reload; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.event.Observes; | ||
import jakarta.inject.Inject; | ||
|
||
import io.vertx.core.Handler; | ||
import io.vertx.ext.web.Router; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
@ApplicationScoped | ||
public class SomeBeanClient { | ||
|
||
@Inject | ||
SomeBean someBean; | ||
|
||
void route(@Observes Router router) { | ||
router.route("/test").handler(new Handler<RoutingContext>() { | ||
@Override | ||
public void handle(RoutingContext event) { | ||
event.response().end(someBean.ping()); | ||
} | ||
}); | ||
|
||
} | ||
|
||
} |