Add inprocess factories and a test
This commit is contained in:
@@ -18,23 +18,32 @@ package org.springframework.grpc.sample;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledOnOs;
|
||||
import org.junit.jupiter.api.condition.OS;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.grpc.autoconfigure.server.GrpcServerProperties;
|
||||
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.SimpleGrpc;
|
||||
import org.springframework.grpc.server.GrpcServerFactory;
|
||||
import org.springframework.grpc.server.ServerBuilderCustomizer;
|
||||
import org.springframework.grpc.server.service.GrpcServiceDiscoverer;
|
||||
import org.springframework.grpc.test.InProcessGrpcChannelFactory;
|
||||
import org.springframework.grpc.test.InProcessGrpcServerFactory;
|
||||
import org.springframework.grpc.test.LocalGrpcPort;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.inprocess.InProcessServerBuilder;
|
||||
|
||||
/**
|
||||
* More detailed integration tests for {@link GrpcServerFactory gRPC server factories} and
|
||||
@@ -42,6 +51,37 @@ import io.grpc.ManagedChannel;
|
||||
*/
|
||||
class GrpcServerIntegrationTests {
|
||||
|
||||
@Nested
|
||||
@SpringBootTest
|
||||
class ServerWithInProcessChannel {
|
||||
|
||||
@Test
|
||||
void servesResponseToClient(@Autowired GrpcChannelFactory channels) {
|
||||
assertThatResponseIsServedToChannel(channels.createChannel("0.0.0.0:0").build());
|
||||
}
|
||||
|
||||
@TestConfiguration
|
||||
static class InProcessConfiguration {
|
||||
|
||||
@Bean
|
||||
InProcessGrpcServerFactory grpcServerFactory(GrpcServiceDiscoverer grpcServicesDiscoverer,
|
||||
List<ServerBuilderCustomizer<InProcessServerBuilder>> customizers) {
|
||||
InProcessGrpcServerFactory factory = new InProcessGrpcServerFactory("0.0.0.0:0", customizers);
|
||||
grpcServicesDiscoverer.findServices().forEach(factory::addService);
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
InProcessGrpcChannelFactory grpcChannelFactory() {
|
||||
InProcessGrpcChannelFactory factory = new InProcessGrpcChannelFactory();
|
||||
factory.setVirtualTargets(path -> path);
|
||||
return factory;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Nested
|
||||
@SpringBootTest(properties = { "spring.grpc.server.host=0.0.0.0", "spring.grpc.server.port=0" })
|
||||
class ServerWithAnyIPv4AddressAndRandomPort {
|
||||
|
||||
Reference in New Issue
Block a user