From 8d863acc422f0cc6c3a1cefbd838aea3bca4f5da Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 20 Jan 2025 08:46:33 +0000 Subject: [PATCH] Add reactive test --- samples/grpc-reactive/build.gradle | 2 +- samples/grpc-reactive/pom.xml | 4 ++++ .../grpc/sample/GrpcServerApplicationTests.java | 17 ++++++++++++----- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/samples/grpc-reactive/build.gradle b/samples/grpc-reactive/build.gradle index fc48a41..eea289b 100644 --- a/samples/grpc-reactive/build.gradle +++ b/samples/grpc-reactive/build.gradle @@ -17,9 +17,9 @@ java { repositories { mavenCentral() + mavenLocal() maven { url 'https://repo.spring.io/milestone' } maven { url 'https://repo.spring.io/snapshot' } - mavenLocal() } dependencyManagement { diff --git a/samples/grpc-reactive/pom.xml b/samples/grpc-reactive/pom.xml index 0e51c20..1cbf323 100644 --- a/samples/grpc-reactive/pom.xml +++ b/samples/grpc-reactive/pom.xml @@ -74,6 +74,10 @@ io.projectreactor reactor-core + + io.projectreactor + reactor-test + com.salesforce.servicelibs reactor-grpc-stub diff --git a/samples/grpc-reactive/src/test/java/org/springframework/grpc/sample/GrpcServerApplicationTests.java b/samples/grpc-reactive/src/test/java/org/springframework/grpc/sample/GrpcServerApplicationTests.java index 1e1642d..494c8d8 100644 --- a/samples/grpc-reactive/src/test/java/org/springframework/grpc/sample/GrpcServerApplicationTests.java +++ b/samples/grpc-reactive/src/test/java/org/springframework/grpc/sample/GrpcServerApplicationTests.java @@ -14,11 +14,16 @@ import org.springframework.context.annotation.Lazy; import org.springframework.grpc.client.GrpcChannelFactory; import org.springframework.grpc.sample.proto.HelloReply; import org.springframework.grpc.sample.proto.HelloRequest; +import org.springframework.grpc.sample.proto.ReactorSimpleGrpc; +import org.springframework.grpc.sample.proto.ReactorSimpleGrpc.ReactorSimpleStub; import org.springframework.grpc.sample.proto.SimpleGrpc; import org.springframework.grpc.test.AutoConfigureInProcessTransport; import org.springframework.grpc.test.LocalGrpcPort; import org.springframework.test.annotation.DirtiesContext; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + @SpringBootTest @AutoConfigureInProcessTransport public class GrpcServerApplicationTests { @@ -30,7 +35,7 @@ public class GrpcServerApplicationTests { } @Autowired - private SimpleGrpc.SimpleBlockingStub stub; + private ReactorSimpleStub stub; @Test @DirtiesContext @@ -41,8 +46,10 @@ public class GrpcServerApplicationTests { @DirtiesContext void serverResponds() { log.info("Testing"); - HelloReply response = stub.sayHello(HelloRequest.newBuilder().setName("Alien").build()); - assertEquals("Hello ==> Alien", response.getMessage()); + Mono reply = stub.sayHello(HelloRequest.newBuilder().setName("Alien").build()); + StepVerifier.create(reply.map(response -> response.getMessage())) + .expectNext("Hello ==> Alien") + .verifyComplete(); } @TestConfiguration @@ -50,8 +57,8 @@ public class GrpcServerApplicationTests { @Bean @Lazy - SimpleGrpc.SimpleBlockingStub stub(GrpcChannelFactory channels, @LocalGrpcPort int port) { - return SimpleGrpc.newBlockingStub(channels.createChannel("0.0.0.0:" + port)); + ReactorSimpleStub stub(GrpcChannelFactory channels, @LocalGrpcPort int port) { + return ReactorSimpleGrpc.newReactorStub(channels.createChannel("0.0.0.0:" + port)); } }