From 0a42b6c35c1e37a34e97f8b4f94407a5bef7e193 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Mon, 22 Mar 2021 14:55:19 +1100 Subject: [PATCH] GRPC port 9001 for tests GRPC does not bind to a different port for testing, which stops you running tests while the app is running. This will cause problems for continous testing. --- .../main/asciidoc/grpc-getting-started.adoc | 3 +- .../grpc/deployment/GrpcServerProcessor.java | 4 +- .../grpc/server/GrpcServiceTestBase.java | 2 +- .../server/MutinyGrpcServiceWithSSLTest.java | 2 +- ...arGrpcServiceWithSSLFromClasspathTest.java | 2 +- .../server/RegularGrpcServiceWithSSLTest.java | 2 +- .../server/blocking/BlockingServiceTest.java | 2 +- ...ServerInterceptorPriorityReversedTest.java | 2 +- .../ServerInterceptorPriorityTest.java | 2 +- .../ServerInterceptorRegistrationTest.java | 2 +- .../grpc/server/scaling/ScalingTestBase.java | 2 +- .../test/resources/blocking-config.properties | 3 ++ .../resources/blocking-test-config.properties | 1 + .../call-from-blocking-service.properties | 4 +- .../grpc-client-tls-configuration.properties | 1 + .../test/resources/health-config.properties | 1 + .../test/resources/hello-config.properties | 1 + .../multiple-instances-config.properties | 1 + .../resources/reflection-config.properties | 1 + .../single-instance-config.properties | 1 + .../grpc/runtime/GrpcServerRecorder.java | 42 ++++++++++--------- .../config/GrpcServerConfiguration.java | 6 +++ .../test/resources/health-config.properties | 3 +- .../resources/no-mp-health-config.properties | 1 + .../src/main/resources/application.properties | 3 +- .../src/main/resources/application.properties | 1 + .../hello/HelloWorldMutualTlsServiceTest.java | 2 +- .../src/main/resources/application.properties | 1 + .../examples/hello/HelloWorldServiceTest.java | 2 +- .../src/main/resources/application.properties | 3 +- .../examples/hello/HelloWorldServiceTest.java | 2 +- .../src/main/resources/application.properties | 3 +- .../examples/hello/HelloWorldServiceTest.java | 2 +- .../src/main/resources/application.properties | 3 +- .../streaming/StreamingServiceTest.java | 2 +- .../src/main/resources/application.properties | 1 + .../hello/HelloWorldTlsServiceTest.java | 2 +- 37 files changed, 76 insertions(+), 42 deletions(-) diff --git a/docs/src/main/asciidoc/grpc-getting-started.adoc b/docs/src/main/asciidoc/grpc-getting-started.adoc index e19de7e4cea90..8a082ab412500 100644 --- a/docs/src/main/asciidoc/grpc-getting-started.adoc +++ b/docs/src/main/asciidoc/grpc-getting-started.adoc @@ -224,7 +224,8 @@ annotated method on a worker thread instead of the I/O thread (event-loop). The services are _served_ by a _server_. Available services (_CDI beans_) are automatically registered and exposed. -By default, the server is exposed on `localhost:9000`, and uses _plain-text_ (so no TLS). +By default, the server is exposed on `localhost:9000`, and uses _plain-text_ (so no TLS) when +running normally, and `localhost:9001` for tests. Run the application using: `mvn quarkus:dev`. 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 447c88138c3b8..a8848d7e5b33d 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 @@ -28,6 +28,7 @@ import io.quarkus.deployment.builditem.CombinedIndexBuildItem; import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem; import io.quarkus.deployment.builditem.FeatureBuildItem; +import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.deployment.builditem.ShutdownContextBuildItem; import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; @@ -95,6 +96,7 @@ void buildContainerBean(BuildProducer beans, @Record(value = ExecutionTime.RUNTIME_INIT) ServiceStartBuildItem build(GrpcServerRecorder recorder, GrpcConfiguration config, ShutdownContextBuildItem shutdown, List bindables, + LaunchModeBuildItem launchModeBuildItem, VertxBuildItem vertx) { // Build the list of blocking methods per service implementation @@ -106,7 +108,7 @@ ServiceStartBuildItem build(GrpcServerRecorder recorder, GrpcConfiguration confi } if (!bindables.isEmpty()) { - recorder.initializeGrpcServer(vertx.getVertx(), config, shutdown, blocking); + recorder.initializeGrpcServer(vertx.getVertx(), config, shutdown, blocking, launchModeBuildItem.getLaunchMode()); return new ServiceStartBuildItem(GRPC_SERVER); } return null; diff --git a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/GrpcServiceTestBase.java b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/GrpcServiceTestBase.java index 99cbc34fbc6c6..4187a28871922 100644 --- a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/GrpcServiceTestBase.java +++ b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/GrpcServiceTestBase.java @@ -37,7 +37,7 @@ public class GrpcServiceTestBase { @BeforeEach public void init() throws Exception { - channel = ManagedChannelBuilder.forAddress("localhost", 9000) + channel = ManagedChannelBuilder.forAddress("localhost", 9001) .usePlaintext() .build(); } diff --git a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/MutinyGrpcServiceWithSSLTest.java b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/MutinyGrpcServiceWithSSLTest.java index e11c4adaa6cc6..e58596f060f7e 100644 --- a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/MutinyGrpcServiceWithSSLTest.java +++ b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/MutinyGrpcServiceWithSSLTest.java @@ -52,7 +52,7 @@ public void init() throws Exception { SslContext sslcontext = GrpcSslContexts.forClient() .trustManager(createTrustAllTrustManager()) .build(); - channel = NettyChannelBuilder.forAddress("localhost", 9000) + channel = NettyChannelBuilder.forAddress("localhost", 9001) .sslContext(sslcontext) .build(); } diff --git a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/RegularGrpcServiceWithSSLFromClasspathTest.java b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/RegularGrpcServiceWithSSLFromClasspathTest.java index d8d1c9937b662..20e1c1bba1e3c 100644 --- a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/RegularGrpcServiceWithSSLFromClasspathTest.java +++ b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/RegularGrpcServiceWithSSLFromClasspathTest.java @@ -54,7 +54,7 @@ public void init() throws Exception { SslContext sslcontext = GrpcSslContexts.forClient() .trustManager(createTrustAllTrustManager()) .build(); - channel = NettyChannelBuilder.forAddress("localhost", 9000) + channel = NettyChannelBuilder.forAddress("localhost", 9001) .sslContext(sslcontext) .build(); } diff --git a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/RegularGrpcServiceWithSSLTest.java b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/RegularGrpcServiceWithSSLTest.java index aeb0f28d596a0..ccc7cb2c5b655 100644 --- a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/RegularGrpcServiceWithSSLTest.java +++ b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/RegularGrpcServiceWithSSLTest.java @@ -52,7 +52,7 @@ public void init() throws Exception { SslContext sslcontext = GrpcSslContexts.forClient() .trustManager(createTrustAllTrustManager()) .build(); - channel = NettyChannelBuilder.forAddress("localhost", 9000) + channel = NettyChannelBuilder.forAddress("localhost", 9001) .sslContext(sslcontext) .build(); } diff --git a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/blocking/BlockingServiceTest.java b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/blocking/BlockingServiceTest.java index 4c1b1df3ab022..dda97d631461a 100644 --- a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/blocking/BlockingServiceTest.java +++ b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/blocking/BlockingServiceTest.java @@ -52,7 +52,7 @@ public class BlockingServiceTest { @BeforeEach public void init() { - channel = ManagedChannelBuilder.forAddress("localhost", 9000) + channel = ManagedChannelBuilder.forAddress("localhost", 9001) .usePlaintext() .build(); } diff --git a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/interceptors/ServerInterceptorPriorityReversedTest.java b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/interceptors/ServerInterceptorPriorityReversedTest.java index 140bbd7d1c0ba..f38aa2d51382c 100644 --- a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/interceptors/ServerInterceptorPriorityReversedTest.java +++ b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/interceptors/ServerInterceptorPriorityReversedTest.java @@ -40,7 +40,7 @@ public class ServerInterceptorPriorityReversedTest { @BeforeEach public void init() { - channel = ManagedChannelBuilder.forAddress("localhost", 9000) + channel = ManagedChannelBuilder.forAddress("localhost", 9001) .usePlaintext() .build(); } diff --git a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/interceptors/ServerInterceptorPriorityTest.java b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/interceptors/ServerInterceptorPriorityTest.java index a07f908a711fc..c336b274a4667 100644 --- a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/interceptors/ServerInterceptorPriorityTest.java +++ b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/interceptors/ServerInterceptorPriorityTest.java @@ -40,7 +40,7 @@ public class ServerInterceptorPriorityTest { @BeforeEach public void init() { - channel = ManagedChannelBuilder.forAddress("localhost", 9000) + channel = ManagedChannelBuilder.forAddress("localhost", 9001) .usePlaintext() .build(); } diff --git a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/interceptors/ServerInterceptorRegistrationTest.java b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/interceptors/ServerInterceptorRegistrationTest.java index 8b10b21a0840b..40fe92067cfe4 100644 --- a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/interceptors/ServerInterceptorRegistrationTest.java +++ b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/interceptors/ServerInterceptorRegistrationTest.java @@ -38,7 +38,7 @@ public class ServerInterceptorRegistrationTest { @BeforeEach public void init() throws Exception { - channel = ManagedChannelBuilder.forAddress("localhost", 9000) + channel = ManagedChannelBuilder.forAddress("localhost", 9001) .usePlaintext() .build(); } diff --git a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/scaling/ScalingTestBase.java b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/scaling/ScalingTestBase.java index 2fb1bd8be28ac..c4536e2c0606a 100644 --- a/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/scaling/ScalingTestBase.java +++ b/extensions/grpc/deployment/src/test/java/io/quarkus/grpc/server/scaling/ScalingTestBase.java @@ -24,7 +24,7 @@ Set getThreadsUsedFor100Requests() throws InterruptedException, Executio List> calls = new ArrayList<>(); for (int i = 0; i < requestNo; i++) { calls.add(() -> { - ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 9000) + ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 9001) .usePlaintext() .build(); HelloReply reply = GreeterGrpc.newBlockingStub(channel) diff --git a/extensions/grpc/deployment/src/test/resources/blocking-config.properties b/extensions/grpc/deployment/src/test/resources/blocking-config.properties index cef3311f67737..d02ee9c19cf1c 100644 --- a/extensions/grpc/deployment/src/test/resources/blocking-config.properties +++ b/extensions/grpc/deployment/src/test/resources/blocking-config.properties @@ -1,4 +1,7 @@ quarkus.grpc.clients.reflection-service.host=localhost +quarkus.grpc.clients.reflection-service.port=9001 quarkus.grpc.clients.test-service.host=localhost +quarkus.grpc.clients.test-service.port=9001 quarkus.grpc.clients.greeter-service.host=localhost +quarkus.grpc.clients.greeter-service.port=9001 quarkus.grpc.server.enable-reflection-service=true diff --git a/extensions/grpc/deployment/src/test/resources/blocking-test-config.properties b/extensions/grpc/deployment/src/test/resources/blocking-test-config.properties index 6077654bf8893..837c460c4c396 100644 --- a/extensions/grpc/deployment/src/test/resources/blocking-test-config.properties +++ b/extensions/grpc/deployment/src/test/resources/blocking-test-config.properties @@ -1,2 +1,3 @@ quarkus.grpc.clients.blocking-test.host=localhost +quarkus.grpc.clients.blocking-test.port=9001 quarkus.grpc.server.enable-reflection-service=true diff --git a/extensions/grpc/deployment/src/test/resources/call-from-blocking-service.properties b/extensions/grpc/deployment/src/test/resources/call-from-blocking-service.properties index a05a7c427c735..90598821b6ebc 100644 --- a/extensions/grpc/deployment/src/test/resources/call-from-blocking-service.properties +++ b/extensions/grpc/deployment/src/test/resources/call-from-blocking-service.properties @@ -1,2 +1,4 @@ quarkus.grpc.clients.greeter.host=localhost -quarkus.grpc.clients.service3.host=localhost \ No newline at end of file +quarkus.grpc.clients.greeter.port=9001 +quarkus.grpc.clients.service3.host=localhost +quarkus.grpc.clients.service3.port=9001 \ No newline at end of file diff --git a/extensions/grpc/deployment/src/test/resources/grpc-client-tls-configuration.properties b/extensions/grpc/deployment/src/test/resources/grpc-client-tls-configuration.properties index 2ffa41c43d264..c393ab7d3fd1e 100644 --- a/extensions/grpc/deployment/src/test/resources/grpc-client-tls-configuration.properties +++ b/extensions/grpc/deployment/src/test/resources/grpc-client-tls-configuration.properties @@ -1,4 +1,5 @@ quarkus.grpc.clients.hello.host=localhost +quarkus.grpc.clients.hello.port=9001 quarkus.grpc.clients.hello.ssl.trust-store=src/test/resources/tls-from-file/ca.pem quarkus.grpc.server.ssl.certificate=src/test/resources/tls-from-file/server.pem diff --git a/extensions/grpc/deployment/src/test/resources/health-config.properties b/extensions/grpc/deployment/src/test/resources/health-config.properties index 3b98375cca0a1..bc53c73d5adac 100644 --- a/extensions/grpc/deployment/src/test/resources/health-config.properties +++ b/extensions/grpc/deployment/src/test/resources/health-config.properties @@ -1,3 +1,4 @@ quarkus.grpc.clients.health-service.host=localhost +quarkus.grpc.clients.health-service.port=9001 quarkus.grpc.clients.foo.host=localhost quarkus.grpc.server.port=9000 \ No newline at end of file diff --git a/extensions/grpc/deployment/src/test/resources/hello-config.properties b/extensions/grpc/deployment/src/test/resources/hello-config.properties index a470728522c1d..a914a069aacd2 100644 --- a/extensions/grpc/deployment/src/test/resources/hello-config.properties +++ b/extensions/grpc/deployment/src/test/resources/hello-config.properties @@ -1,4 +1,5 @@ quarkus.grpc.clients.hello-service.host=localhost +quarkus.grpc.clients.hello-service.port=9001 quarkus.grpc.clients.hello-service.keep-alive-timeout=1s quarkus.grpc.clients.hello-service-2.host=localhost quarkus.grpc.clients.hello-service-2.retry=true \ No newline at end of file diff --git a/extensions/grpc/deployment/src/test/resources/multiple-instances-config.properties b/extensions/grpc/deployment/src/test/resources/multiple-instances-config.properties index a97643669296c..5b608591877f7 100644 --- a/extensions/grpc/deployment/src/test/resources/multiple-instances-config.properties +++ b/extensions/grpc/deployment/src/test/resources/multiple-instances-config.properties @@ -1,3 +1,4 @@ quarkus.grpc.server.instances=3 quarkus.grpc.clients.hello-service.host=localhost +quarkus.grpc.clients.hello-service.port=9001 quarkus.grpc.clients.hello-service.keep-alive-timeout=1s \ No newline at end of file diff --git a/extensions/grpc/deployment/src/test/resources/reflection-config.properties b/extensions/grpc/deployment/src/test/resources/reflection-config.properties index c15965d5e3744..fb8074812b64e 100644 --- a/extensions/grpc/deployment/src/test/resources/reflection-config.properties +++ b/extensions/grpc/deployment/src/test/resources/reflection-config.properties @@ -1,2 +1,3 @@ quarkus.grpc.clients.reflection-service.host=localhost +quarkus.grpc.clients.reflection-service.port=9001 quarkus.grpc.server.enable-reflection-service=true \ No newline at end of file diff --git a/extensions/grpc/deployment/src/test/resources/single-instance-config.properties b/extensions/grpc/deployment/src/test/resources/single-instance-config.properties index 675cedf145c83..8faad84d55503 100644 --- a/extensions/grpc/deployment/src/test/resources/single-instance-config.properties +++ b/extensions/grpc/deployment/src/test/resources/single-instance-config.properties @@ -1,3 +1,4 @@ quarkus.grpc.server.instances=1 quarkus.grpc.clients.hello-service.host=localhost +quarkus.grpc.clients.hello-service.port=9001 quarkus.grpc.clients.hello-service.keep-alive-timeout=1s \ No newline at end of file diff --git a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/GrpcServerRecorder.java b/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/GrpcServerRecorder.java index 0ddaee2cc7b61..0cbbdca5d85c2 100644 --- a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/GrpcServerRecorder.java +++ b/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/GrpcServerRecorder.java @@ -69,7 +69,7 @@ public class GrpcServerRecorder { public void initializeGrpcServer(RuntimeValue vertxSupplier, GrpcConfiguration cfg, ShutdownContext shutdown, - Map> blockingMethodsPerServiceImplementationClass) { + Map> blockingMethodsPerServiceImplementationClass, LaunchMode launchMode) { GrpcContainer grpcContainer = Arc.container().instance(GrpcContainer.class).get(); if (grpcContainer == null) { throw new IllegalStateException("gRPC not initialized, GrpcContainer not found"); @@ -83,29 +83,29 @@ public void initializeGrpcServer(RuntimeValue vertxSupplier, this.blockingMethodsPerService = blockingMethodsPerServiceImplementationClass; GrpcServerConfiguration configuration = cfg.server; - final boolean devMode = ProfileManager.getLaunchMode() == LaunchMode.DEVELOPMENT; - if (devMode) { + if (launchMode == LaunchMode.DEVELOPMENT) { // start single server, not in a verticle, regardless of the configuration.instances // for reason unknown to me, verticles occasionally get undeployed on dev mode reload if (GrpcServerReloader.getServer() == null) { - devModeStart(grpcContainer, vertx, configuration, shutdown); + devModeStart(grpcContainer, vertx, configuration, shutdown, launchMode); } else { devModeReload(grpcContainer); } } else { - prodStart(grpcContainer, vertx, configuration); + prodStart(grpcContainer, vertx, configuration, launchMode); } } - private void prodStart(GrpcContainer grpcContainer, Vertx vertx, GrpcServerConfiguration configuration) { + private void prodStart(GrpcContainer grpcContainer, Vertx vertx, GrpcServerConfiguration configuration, + LaunchMode launchMode) { CompletableFuture startResult = new CompletableFuture<>(); vertx.deployVerticle( new Supplier() { @Override public Verticle get() { - return new GrpcServerVerticle(configuration, grpcContainer); + return new GrpcServerVerticle(configuration, grpcContainer, launchMode); } }, new DeploymentOptions().setInstances(configuration.instances), @@ -115,7 +115,7 @@ public void handle(AsyncResult result) { if (result.failed()) { startResult.completeExceptionally(result.cause()); } else { - GrpcServerRecorder.this.postStartup(grpcContainer, configuration); + GrpcServerRecorder.this.postStartup(grpcContainer, configuration, launchMode == LaunchMode.TEST); startResult.complete(null); } @@ -134,7 +134,7 @@ public void handle(AsyncResult result) { } } - private void postStartup(GrpcContainer grpcContainer, GrpcServerConfiguration configuration) { + private void postStartup(GrpcContainer grpcContainer, GrpcServerConfiguration configuration, boolean test) { grpcContainer.getHealthStorage().stream().forEach(new Consumer() { //NOSONAR @Override public void accept(GrpcHealthStorage storage) { @@ -152,14 +152,14 @@ public void accept(BindableService service) { } }); LOGGER.infof("gRPC Server started on %s:%d [SSL enabled: %s]", - configuration.host, configuration.port, !configuration.plainText); + configuration.host, test ? configuration.testPort : configuration.port, !configuration.plainText); } private void devModeStart(GrpcContainer grpcContainer, Vertx vertx, GrpcServerConfiguration configuration, - ShutdownContext shutdown) { + ShutdownContext shutdown, LaunchMode launchMode) { CompletableFuture future = new CompletableFuture<>(); - VertxServer vertxServer = buildServer(vertx, configuration, grpcContainer, true) + VertxServer vertxServer = buildServer(vertx, configuration, grpcContainer, launchMode) .start(new Handler>() { // NOSONAR @Override public void handle(AsyncResult ar) { @@ -167,7 +167,7 @@ public void handle(AsyncResult ar) { LOGGER.error("Unable to start the gRPC server", ar.cause()); future.completeExceptionally(ar.cause()); } else { - postStartup(grpcContainer, configuration); + postStartup(grpcContainer, configuration, false); future.complete(true); grpcVerticleCount.incrementAndGet(); } @@ -281,9 +281,10 @@ public static int getVerticleCount() { } private VertxServer buildServer(Vertx vertx, GrpcServerConfiguration configuration, - GrpcContainer grpcContainer, boolean devMode) { + GrpcContainer grpcContainer, LaunchMode launchMode) { VertxServerBuilder builder = VertxServerBuilder - .forAddress(vertx, configuration.host, configuration.port); + .forAddress(vertx, configuration.host, + launchMode == LaunchMode.TEST ? configuration.testPort : configuration.port); AtomicBoolean usePlainText = new AtomicBoolean(); builder.useSsl(new Handler() { // NOSONAR @@ -352,7 +353,7 @@ public void handle(HttpServerOptions options) { builder.intercept(serverInterceptor); } - if (devMode) { + if (launchMode == LaunchMode.DEVELOPMENT) { builder.commandDecorator(new Consumer() { @Override public void accept(Runnable command) { @@ -374,7 +375,8 @@ public void handle(AsyncResult result) { } LOGGER.debugf("Starting gRPC Server on %s:%d [SSL enabled: %s]...", - configuration.host, configuration.port, !usePlainText.get()); + configuration.host, launchMode == LaunchMode.TEST ? configuration.testPort : configuration.port, + !usePlainText.get()); return builder.build(); } @@ -382,12 +384,14 @@ public void handle(AsyncResult result) { private class GrpcServerVerticle extends AbstractVerticle { private final GrpcServerConfiguration configuration; private final GrpcContainer grpcContainer; + private final LaunchMode launchMode; private VertxServer grpcServer; - GrpcServerVerticle(GrpcServerConfiguration configuration, GrpcContainer grpcContainer) { + GrpcServerVerticle(GrpcServerConfiguration configuration, GrpcContainer grpcContainer, LaunchMode launchMode) { this.configuration = configuration; this.grpcContainer = grpcContainer; + this.launchMode = launchMode; } @Override @@ -397,7 +401,7 @@ public void start(Promise startPromise) { "Unable to find bean exposing the `BindableService` interface - not starting the gRPC server"); return; } - grpcServer = buildServer(getVertx(), configuration, grpcContainer, false) + grpcServer = buildServer(getVertx(), configuration, grpcContainer, launchMode) .start(new Handler>() { // NOSONAR @Override public void handle(AsyncResult ar) { diff --git a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/config/GrpcServerConfiguration.java b/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/config/GrpcServerConfiguration.java index 7e509fb1f1e44..96d78bf9daf2e 100644 --- a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/config/GrpcServerConfiguration.java +++ b/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/config/GrpcServerConfiguration.java @@ -17,6 +17,12 @@ public class GrpcServerConfiguration { @ConfigItem(defaultValue = "9000") public int port; + /** + * The gRPC Server port used for tests. + */ + @ConfigItem(defaultValue = "9001") + public int testPort; + /** * The gRPC server host. */ diff --git a/integration-tests/grpc-health/src/test/resources/health-config.properties b/integration-tests/grpc-health/src/test/resources/health-config.properties index 59f323394965d..f51bd7f5053cb 100644 --- a/integration-tests/grpc-health/src/test/resources/health-config.properties +++ b/integration-tests/grpc-health/src/test/resources/health-config.properties @@ -1 +1,2 @@ -quarkus.grpc.clients.health-service.host=localhost \ No newline at end of file +quarkus.grpc.clients.health-service.host=localhost +quarkus.grpc.clients.health-service.port=9001 \ No newline at end of file diff --git a/integration-tests/grpc-health/src/test/resources/no-mp-health-config.properties b/integration-tests/grpc-health/src/test/resources/no-mp-health-config.properties index aa961ff8bff8a..cc409ac21fd7e 100644 --- a/integration-tests/grpc-health/src/test/resources/no-mp-health-config.properties +++ b/integration-tests/grpc-health/src/test/resources/no-mp-health-config.properties @@ -1,2 +1,3 @@ quarkus.grpc.clients.health-service.host=localhost +quarkus.grpc.clients.health-service.port=9001 quarkus.grpc.server.health.enabled=false \ No newline at end of file diff --git a/integration-tests/grpc-interceptors/src/main/resources/application.properties b/integration-tests/grpc-interceptors/src/main/resources/application.properties index f8a95fc9c4c11..d6ab01cee7bc5 100644 --- a/integration-tests/grpc-interceptors/src/main/resources/application.properties +++ b/integration-tests/grpc-interceptors/src/main/resources/application.properties @@ -1 +1,2 @@ -quarkus.grpc.clients.hello.host=localhost \ No newline at end of file +quarkus.grpc.clients.hello.host=localhost +%test.quarkus.grpc.clients.hello.port=9001 \ No newline at end of file diff --git a/integration-tests/grpc-mutual-auth/src/main/resources/application.properties b/integration-tests/grpc-mutual-auth/src/main/resources/application.properties index aa1852fb406d4..258bca4e2d373 100644 --- a/integration-tests/grpc-mutual-auth/src/main/resources/application.properties +++ b/integration-tests/grpc-mutual-auth/src/main/resources/application.properties @@ -1,4 +1,5 @@ quarkus.grpc.clients.hello.host=localhost +%test.quarkus.grpc.clients.hello.port=9001 quarkus.grpc.clients.hello.ssl.certificate=src/main/resources/tls/client.pem quarkus.grpc.clients.hello.ssl.key=src/main/resources/tls/client.key quarkus.grpc.clients.hello.ssl.trust-store=src/main/resources/tls/ca.pem diff --git a/integration-tests/grpc-mutual-auth/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldMutualTlsServiceTest.java b/integration-tests/grpc-mutual-auth/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldMutualTlsServiceTest.java index e5bb8f4480256..ffb6b81ef81da 100644 --- a/integration-tests/grpc-mutual-auth/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldMutualTlsServiceTest.java +++ b/integration-tests/grpc-mutual-auth/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldMutualTlsServiceTest.java @@ -35,7 +35,7 @@ public void init() throws SSLException { new File("src/main/resources/tls/client.key")); SslContext context = builder.build(); - channel = NettyChannelBuilder.forAddress("localhost", 9000) + channel = NettyChannelBuilder.forAddress("localhost", 9001) .sslContext(context) .build(); } diff --git a/integration-tests/grpc-plain-text-gzip/src/main/resources/application.properties b/integration-tests/grpc-plain-text-gzip/src/main/resources/application.properties index c5c793326226c..1464bddcdc719 100644 --- a/integration-tests/grpc-plain-text-gzip/src/main/resources/application.properties +++ b/integration-tests/grpc-plain-text-gzip/src/main/resources/application.properties @@ -1,2 +1,3 @@ quarkus.grpc.clients.hello.host=localhost +%test.quarkus.grpc.clients.hello.port=9001 quarkus.grpc.server.compression=gzip \ No newline at end of file diff --git a/integration-tests/grpc-plain-text-gzip/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldServiceTest.java b/integration-tests/grpc-plain-text-gzip/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldServiceTest.java index 1f775a5177ae8..534638ddae232 100644 --- a/integration-tests/grpc-plain-text-gzip/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldServiceTest.java +++ b/integration-tests/grpc-plain-text-gzip/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldServiceTest.java @@ -24,7 +24,7 @@ class HelloWorldServiceTest { @BeforeEach public void init() { - channel = ManagedChannelBuilder.forAddress("localhost", 9000).usePlaintext().build(); + channel = ManagedChannelBuilder.forAddress("localhost", 9001).usePlaintext().build(); } @AfterEach diff --git a/integration-tests/grpc-plain-text-mutiny/src/main/resources/application.properties b/integration-tests/grpc-plain-text-mutiny/src/main/resources/application.properties index f8a95fc9c4c11..d6ab01cee7bc5 100644 --- a/integration-tests/grpc-plain-text-mutiny/src/main/resources/application.properties +++ b/integration-tests/grpc-plain-text-mutiny/src/main/resources/application.properties @@ -1 +1,2 @@ -quarkus.grpc.clients.hello.host=localhost \ No newline at end of file +quarkus.grpc.clients.hello.host=localhost +%test.quarkus.grpc.clients.hello.port=9001 \ No newline at end of file diff --git a/integration-tests/grpc-plain-text-mutiny/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldServiceTest.java b/integration-tests/grpc-plain-text-mutiny/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldServiceTest.java index 1f775a5177ae8..534638ddae232 100644 --- a/integration-tests/grpc-plain-text-mutiny/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldServiceTest.java +++ b/integration-tests/grpc-plain-text-mutiny/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldServiceTest.java @@ -24,7 +24,7 @@ class HelloWorldServiceTest { @BeforeEach public void init() { - channel = ManagedChannelBuilder.forAddress("localhost", 9000).usePlaintext().build(); + channel = ManagedChannelBuilder.forAddress("localhost", 9001).usePlaintext().build(); } @AfterEach diff --git a/integration-tests/grpc-proto-v2/src/main/resources/application.properties b/integration-tests/grpc-proto-v2/src/main/resources/application.properties index f8a95fc9c4c11..d6ab01cee7bc5 100644 --- a/integration-tests/grpc-proto-v2/src/main/resources/application.properties +++ b/integration-tests/grpc-proto-v2/src/main/resources/application.properties @@ -1 +1,2 @@ -quarkus.grpc.clients.hello.host=localhost \ No newline at end of file +quarkus.grpc.clients.hello.host=localhost +%test.quarkus.grpc.clients.hello.port=9001 \ No newline at end of file diff --git a/integration-tests/grpc-proto-v2/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldServiceTest.java b/integration-tests/grpc-proto-v2/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldServiceTest.java index 265445239488e..1c3f4c28e3ba3 100644 --- a/integration-tests/grpc-proto-v2/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldServiceTest.java +++ b/integration-tests/grpc-proto-v2/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldServiceTest.java @@ -24,7 +24,7 @@ class HelloWorldServiceTest { @BeforeEach void setUp() { - channel = ManagedChannelBuilder.forAddress("localhost", 9000).usePlaintext().build(); + channel = ManagedChannelBuilder.forAddress("localhost", 9001).usePlaintext().build(); } @AfterEach diff --git a/integration-tests/grpc-streaming/src/main/resources/application.properties b/integration-tests/grpc-streaming/src/main/resources/application.properties index a1445ff5fa09d..6a85e94cd3acc 100644 --- a/integration-tests/grpc-streaming/src/main/resources/application.properties +++ b/integration-tests/grpc-streaming/src/main/resources/application.properties @@ -1 +1,2 @@ -quarkus.grpc.clients.streaming.host=localhost \ No newline at end of file +quarkus.grpc.clients.streaming.host=localhost +%test.quarkus.grpc.clients.streaming.port=9001 \ No newline at end of file diff --git a/integration-tests/grpc-streaming/src/test/java/io/quarkus/grpc/example/streaming/StreamingServiceTest.java b/integration-tests/grpc-streaming/src/test/java/io/quarkus/grpc/example/streaming/StreamingServiceTest.java index 7daeac4adadbd..ff8fa6ed9608f 100644 --- a/integration-tests/grpc-streaming/src/test/java/io/quarkus/grpc/example/streaming/StreamingServiceTest.java +++ b/integration-tests/grpc-streaming/src/test/java/io/quarkus/grpc/example/streaming/StreamingServiceTest.java @@ -29,7 +29,7 @@ public class StreamingServiceTest { @BeforeEach public void getChannel() { - channel = ManagedChannelBuilder.forAddress("localhost", 9000).usePlaintext().build(); + channel = ManagedChannelBuilder.forAddress("localhost", 9001).usePlaintext().build(); } @AfterEach diff --git a/integration-tests/grpc-tls/src/main/resources/application.properties b/integration-tests/grpc-tls/src/main/resources/application.properties index 246415387c7e3..05a8211b0179e 100644 --- a/integration-tests/grpc-tls/src/main/resources/application.properties +++ b/integration-tests/grpc-tls/src/main/resources/application.properties @@ -1,4 +1,5 @@ quarkus.grpc.clients.hello.host=localhost +%test.quarkus.grpc.clients.hello.port=9001 quarkus.grpc.clients.hello.ssl.trust-store=tls/ca.pem quarkus.grpc.server.ssl.certificate=tls/server.pem diff --git a/integration-tests/grpc-tls/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldTlsServiceTest.java b/integration-tests/grpc-tls/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldTlsServiceTest.java index 0ebdd90d1e1d8..aa6b3ebd9f83a 100644 --- a/integration-tests/grpc-tls/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldTlsServiceTest.java +++ b/integration-tests/grpc-tls/src/test/java/io/quarkus/grpc/examples/hello/HelloWorldTlsServiceTest.java @@ -33,7 +33,7 @@ public void init() throws SSLException { builder.trustManager(new File("src/main/resources/tls/ca.pem")); SslContext context = builder.build(); - channel = NettyChannelBuilder.forAddress("localhost", 9000) + channel = NettyChannelBuilder.forAddress("localhost", 9001) .sslContext(context) .build(); }