diff --git a/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcBuildTimeConfig.java b/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcBuildTimeConfig.java index a20e62e0c534c..a443056b4236a 100644 --- a/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcBuildTimeConfig.java +++ b/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcBuildTimeConfig.java @@ -12,4 +12,10 @@ public class GrpcBuildTimeConfig { @ConfigItem(name = "metrics.enabled") public boolean metricsEnabled; + /** + * Configuration gRPC dev mode. + */ + @ConfigItem + public GrpcDevModeConfig devMode; + } diff --git a/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcDevModeConfig.java b/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcDevModeConfig.java new file mode 100644 index 0000000000000..a2b0931824011 --- /dev/null +++ b/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcDevModeConfig.java @@ -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; +} diff --git a/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcServerProcessor.java b/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcServerProcessor.java index ec726faa57c9f..a6d3fcc5770df 100644 --- a/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcServerProcessor.java +++ b/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcServerProcessor.java @@ -466,8 +466,11 @@ private GrpcInterceptors gatherInterceptors(IndexView index) { @BuildStep @Record(value = ExecutionTime.RUNTIME_INIT) @Consume(SyntheticBeansRuntimeInitBuildItem.class) - ServiceStartBuildItem initializeServer(GrpcServerRecorder recorder, GrpcConfiguration config, - ShutdownContextBuildItem shutdown, List bindables, + ServiceStartBuildItem initializeServer(GrpcServerRecorder recorder, + GrpcConfiguration config, + GrpcBuildTimeConfig buildTimeConfig, + ShutdownContextBuildItem shutdown, + List bindables, LaunchModeBuildItem launchModeBuildItem, VertxBuildItem vertx) { @@ -479,7 +482,8 @@ ServiceStartBuildItem initializeServer(GrpcServerRecorder recorder, GrpcConfigur } } - if (!bindables.isEmpty() || LaunchMode.current() == LaunchMode.DEVELOPMENT) { + if (!bindables.isEmpty() + || (LaunchMode.current() == LaunchMode.DEVELOPMENT && buildTimeConfig.devMode.forceServerStart)) { recorder.initializeGrpcServer(vertx.getVertx(), config, shutdown, blocking, launchModeBuildItem.getLaunchMode()); return new ServiceStartBuildItem(GRPC_SERVER); } @@ -550,7 +554,7 @@ void configureMetrics(GrpcBuildTimeConfig configuration, Optional() { + return new BeanArchivePredicateBuildItem(new Predicate<>() { @Override public boolean test(ApplicationArchive archive) { diff --git a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/devmode/DevModeServerStartDisabledTest.java b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/devmode/DevModeServerStartDisabledTest.java new file mode 100644 index 0000000000000..f140ce652b917 --- /dev/null +++ b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/devmode/DevModeServerStartDisabledTest.java @@ -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 + } +} diff --git a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/devmode/DevModeServerStartTest.java b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/devmode/DevModeServerStartTest.java new file mode 100644 index 0000000000000..f5ef8974b7b23 --- /dev/null +++ b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/devmode/DevModeServerStartTest.java @@ -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 + } +} diff --git a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/devmode/IsUpEndpoint.java b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/devmode/IsUpEndpoint.java new file mode 100644 index 0000000000000..5dcb55086e1c3 --- /dev/null +++ b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/devmode/IsUpEndpoint.java @@ -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(); + } + +}