diff --git a/samples/grpc-server-netty-shaded/pom.xml b/samples/grpc-server-netty-shaded/pom.xml
index 03ece69..2e85e9d 100644
--- a/samples/grpc-server-netty-shaded/pom.xml
+++ b/samples/grpc-server-netty-shaded/pom.xml
@@ -51,11 +51,6 @@
grpc-services
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
org.springframework.boot
spring-boot-devtools
diff --git a/samples/grpc-server-netty-shaded/src/test/java/com/example/demo/DemoApplicationTests.java b/samples/grpc-server-netty-shaded/src/test/java/com/example/demo/DemoApplicationTests.java
index fcd2dd9..f332422 100644
--- a/samples/grpc-server-netty-shaded/src/test/java/com/example/demo/DemoApplicationTests.java
+++ b/samples/grpc-server-netty-shaded/src/test/java/com/example/demo/DemoApplicationTests.java
@@ -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);
diff --git a/samples/grpc-server/pom.xml b/samples/grpc-server/pom.xml
index ca2b32b..5d66be6 100644
--- a/samples/grpc-server/pom.xml
+++ b/samples/grpc-server/pom.xml
@@ -53,11 +53,6 @@
io.grpc
grpc-services
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
io.netty
diff --git a/samples/grpc-server/src/test/java/org/springframework/grpc/sample/GrpcServerApplicationTests.java b/samples/grpc-server/src/test/java/org/springframework/grpc/sample/GrpcServerApplicationTests.java
index eae86b8..38e62cf 100644
--- a/samples/grpc-server/src/test/java/org/springframework/grpc/sample/GrpcServerApplicationTests.java
+++ b/samples/grpc-server/src/test/java/org/springframework/grpc/sample/GrpcServerApplicationTests.java
@@ -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);
diff --git a/samples/grpc-server/src/test/java/org/springframework/grpc/sample/GrpcServerIntegrationTests.java b/samples/grpc-server/src/test/java/org/springframework/grpc/sample/GrpcServerIntegrationTests.java
index 98db393..30d8e7f 100644
--- a/samples/grpc-server/src/test/java/org/springframework/grpc/sample/GrpcServerIntegrationTests.java
+++ b/samples/grpc-server/src/test/java/org/springframework/grpc/sample/GrpcServerIntegrationTests.java
@@ -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> 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 {
diff --git a/samples/grpc-tomcat/pom.xml b/samples/grpc-tomcat/pom.xml
index c50b9ec..613ea78 100644
--- a/samples/grpc-tomcat/pom.xml
+++ b/samples/grpc-tomcat/pom.xml
@@ -70,11 +70,6 @@
micrometer-tracing-bridge-otel
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
org.springframework.grpc
spring-grpc-test
diff --git a/spring-grpc-test/src/main/java/org/springframework/grpc/test/InProcessGrpcServerFactoryAutoConfiguration.java b/spring-grpc-test/src/main/java/org/springframework/grpc/test/InProcessGrpcServerFactoryAutoConfiguration.java
new file mode 100644
index 0000000..48aaab0
--- /dev/null
+++ b/spring-grpc-test/src/main/java/org/springframework/grpc/test/InProcessGrpcServerFactoryAutoConfiguration.java
@@ -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> 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;
+ }
+
+}
diff --git a/spring-grpc-test/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-grpc-test/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
new file mode 100644
index 0000000..2098b62
--- /dev/null
+++ b/spring-grpc-test/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -0,0 +1,2 @@
+org.springframework.grpc.test.InProcessGrpcServerFactoryAutoConfiguration
+