Add reactive test

This commit is contained in:
Dave Syer
2025-01-20 08:46:33 +00:00
parent 24b9e42a6f
commit 8d863acc42
3 changed files with 17 additions and 6 deletions

View File

@@ -17,9 +17,9 @@ java {
repositories {
mavenCentral()
mavenLocal()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
mavenLocal()
}
dependencyManagement {

View File

@@ -74,6 +74,10 @@
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
</dependency>
<dependency>
<groupId>com.salesforce.servicelibs</groupId>
<artifactId>reactor-grpc-stub</artifactId>

View File

@@ -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<HelloReply> 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));
}
}