-
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 #20354 from michalszynkiewicz/optional-grpc-server…
…-start gRPC: add an option to not start server in dev mode
- Loading branch information
Showing
6 changed files
with
98 additions
and
4 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
15 changes: 15 additions & 0 deletions
15
extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcDevModeConfig.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,15 @@ | ||
package io.quarkus.grpc.deployment; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
|
||
@ConfigGroup | ||
public class GrpcDevModeConfig { | ||
|
||
/** | ||
* Start gRPC server in dev mode even if no gRPC services are implemented. | ||
* By default set to `true` to ease incremental development of new services using dev mode. | ||
*/ | ||
@ConfigItem(defaultValue = "true") | ||
public boolean forceServerStart; | ||
} |
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
26 changes: 26 additions & 0 deletions
26
...ployment/src/test/java/io/quarkus/grpc/server/devmode/DevModeServerStartDisabledTest.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,26 @@ | ||
package io.quarkus.grpc.server.devmode; | ||
|
||
import static io.restassured.RestAssured.when; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.restassured.response.Response; | ||
|
||
public class DevModeServerStartDisabledTest { | ||
@RegisterExtension | ||
public static final QuarkusDevModeTest config = new QuarkusDevModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(IsUpEndpoint.class) | ||
.add(new StringAsset("quarkus.grpc.dev-mode.force-server-start=false\n"), "application.properties")); | ||
|
||
@Test | ||
public void test() { | ||
Response response = when().get("/grpc-status"); | ||
response.then().statusCode(204); // 200 is returned when server started, 204 otherwise | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
.../grpc/deployment/src/test/java/io/quarkus/grpc/server/devmode/DevModeServerStartTest.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,25 @@ | ||
package io.quarkus.grpc.server.devmode; | ||
|
||
import static io.restassured.RestAssured.when; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.restassured.response.Response; | ||
|
||
public class DevModeServerStartTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusDevModeTest config = new QuarkusDevModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(IsUpEndpoint.class)); | ||
|
||
@Test | ||
public void test() { | ||
Response response = when().get("/grpc-status"); | ||
response.then().statusCode(200); // 200 is returned when server started, 204 otherwise | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/devmode/IsUpEndpoint.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,18 @@ | ||
package io.quarkus.grpc.server.devmode; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.Response; | ||
|
||
import io.quarkus.grpc.runtime.GrpcServerRecorder; | ||
|
||
@Path("/grpc-status") | ||
@ApplicationScoped | ||
public class IsUpEndpoint { | ||
@GET | ||
public Response isGrpcUp() { | ||
return GrpcServerRecorder.getVerticleCount() > 0 ? Response.ok().build() : Response.noContent().build(); | ||
} | ||
|
||
} |