Make inprocess server the default in tests
This commit is contained in:
@@ -51,11 +51,6 @@
|
||||
<artifactId>grpc-services</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
|
||||
@@ -19,7 +19,8 @@ import com.example.demo.proto.HelloReply;
|
||||
import com.example.demo.proto.HelloRequest;
|
||||
import com.example.demo.proto.SimpleGrpc;
|
||||
|
||||
@SpringBootTest(properties = "spring.grpc.client.channels.test.address=static://localhost:0")
|
||||
@SpringBootTest(properties = { "spring.grpc.client.channels.test.address=static://localhost:0",
|
||||
"spring.grpc.inprocess.enabled=false" })
|
||||
public class DemoApplicationTests {
|
||||
|
||||
private static Log log = LogFactory.getLog(DemoApplicationTests.class);
|
||||
|
||||
@@ -53,11 +53,6 @@
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-services</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- for testing unix domain sockets -->
|
||||
<groupId>io.netty</groupId>
|
||||
|
||||
@@ -18,7 +18,7 @@ import org.springframework.grpc.sample.proto.SimpleGrpc;
|
||||
import org.springframework.grpc.test.LocalGrpcPort;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
@SpringBootTest(properties = "spring.grpc.server.port=0")
|
||||
@SpringBootTest(properties = { "spring.grpc.server.port=0", "spring.grpc.inprocess.enabled=false" })
|
||||
public class GrpcServerApplicationTests {
|
||||
|
||||
private static Log log = LogFactory.getLog(GrpcServerApplicationTests.class);
|
||||
|
||||
@@ -18,32 +18,23 @@ 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
|
||||
@@ -60,30 +51,11 @@ class GrpcServerIntegrationTests {
|
||||
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" })
|
||||
@SpringBootTest(properties = { "spring.grpc.server.host=0.0.0.0", "spring.grpc.server.port=0",
|
||||
"spring.grpc.inprocess.enabled=false" })
|
||||
class ServerWithAnyIPv4AddressAndRandomPort {
|
||||
|
||||
@Test
|
||||
@@ -95,7 +67,8 @@ class GrpcServerIntegrationTests {
|
||||
}
|
||||
|
||||
@Nested
|
||||
@SpringBootTest(properties = { "spring.grpc.server.host=::", "spring.grpc.server.port=0" })
|
||||
@SpringBootTest(properties = { "spring.grpc.server.host=::", "spring.grpc.server.port=0",
|
||||
"spring.grpc.inprocess.enabled=false" })
|
||||
class ServerWithAnyIPv6AddressAndRandomPort {
|
||||
|
||||
@Test
|
||||
@@ -107,7 +80,8 @@ class GrpcServerIntegrationTests {
|
||||
}
|
||||
|
||||
@Nested
|
||||
@SpringBootTest(properties = { "spring.grpc.server.host=127.0.0.1", "spring.grpc.server.port=0" })
|
||||
@SpringBootTest(properties = { "spring.grpc.server.host=127.0.0.1", "spring.grpc.server.port=0",
|
||||
"spring.grpc.inprocess.enabled=false" })
|
||||
class ServerWithLocalhostAndRandomPort {
|
||||
|
||||
@Test
|
||||
@@ -120,7 +94,8 @@ class GrpcServerIntegrationTests {
|
||||
|
||||
@Nested
|
||||
@SpringBootTest(properties = { "spring.grpc.server.port=0",
|
||||
"spring.grpc.client.channels.test-channel.address=static://0.0.0.0:${local.grpc.port}" })
|
||||
"spring.grpc.client.channels.test-channel.address=static://0.0.0.0:${local.grpc.port}",
|
||||
"spring.grpc.inprocess.enabled=false" })
|
||||
@DirtiesContext
|
||||
class ServerConfiguredWithStaticClientChannel {
|
||||
|
||||
@@ -132,7 +107,8 @@ class GrpcServerIntegrationTests {
|
||||
}
|
||||
|
||||
@Nested
|
||||
@SpringBootTest(properties = "spring.grpc.server.address=unix:unix-test-channel")
|
||||
@SpringBootTest(
|
||||
properties = { "spring.grpc.server.address=unix:unix-test-channel", "spring.grpc.inprocess.enabled=false" })
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
class ServerWithUnixDomain {
|
||||
|
||||
@@ -147,7 +123,7 @@ class GrpcServerIntegrationTests {
|
||||
@SpringBootTest(properties = { "spring.grpc.server.port=0",
|
||||
"spring.grpc.client.channels.test-channel.address=static://0.0.0.0:${local.grpc.port}",
|
||||
"spring.grpc.client.channels.test-channel.negotiation-type=TLS",
|
||||
"spring.grpc.client.channels.test-channel.secure=false" })
|
||||
"spring.grpc.client.channels.test-channel.secure=false", "spring.grpc.inprocess.enabled=false" })
|
||||
@ActiveProfiles("ssl")
|
||||
@DirtiesContext
|
||||
class ServerWithSsl {
|
||||
@@ -165,7 +141,7 @@ class GrpcServerIntegrationTests {
|
||||
"spring.grpc.client.channels.test-channel.address=static://0.0.0.0:${local.grpc.port}",
|
||||
"spring.grpc.client.channels.test-channel.ssl.bundle=ssltest",
|
||||
"spring.grpc.client.channels.test-channel.negotiation-type=TLS",
|
||||
"spring.grpc.client.channels.test-channel.secure=false" })
|
||||
"spring.grpc.client.channels.test-channel.secure=false", "spring.grpc.inprocess.enabled=false" })
|
||||
@ActiveProfiles("ssl")
|
||||
@DirtiesContext
|
||||
class ServerWithClientAuth {
|
||||
|
||||
@@ -70,11 +70,6 @@
|
||||
<artifactId>micrometer-tracing-bridge-otel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.grpc</groupId>
|
||||
<artifactId>spring-grpc-test</artifactId>
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2024-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.grpc.test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.grpc.autoconfigure.client.GrpcClientAutoConfiguration;
|
||||
import org.springframework.grpc.autoconfigure.server.GrpcServerFactoryAutoConfiguration;
|
||||
import org.springframework.grpc.server.ServerBuilderCustomizer;
|
||||
import org.springframework.grpc.server.service.GrpcServiceDiscoverer;
|
||||
|
||||
import io.grpc.inprocess.InProcessServerBuilder;
|
||||
|
||||
@AutoConfiguration(before = { GrpcServerFactoryAutoConfiguration.class, GrpcClientAutoConfiguration.class })
|
||||
@ConditionalOnProperty(prefix = "spring.grpc.inprocess", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnNotWebApplication
|
||||
public class InProcessGrpcServerFactoryAutoConfiguration {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
org.springframework.grpc.test.InProcessGrpcServerFactoryAutoConfiguration
|
||||
|
||||
Reference in New Issue
Block a user