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 {
|
||||
|
||||
@@ -12,28 +12,26 @@
|
||||
|spring.grpc.client.default-channel.max-inbound-message-size | |
|
||||
|spring.grpc.client.default-channel.max-inbound-metadata-size | |
|
||||
|spring.grpc.client.default-channel.negotiation-type | | The negotiation type for the channel. Default is {@link NegotiationType#PLAINTEXT}.
|
||||
|spring.grpc.client.default-channel.secure | `+++true+++` | Flag to say that strict SSL checks are not enabled (so the remote certificate could be anonymous).
|
||||
|spring.grpc.client.default-channel.secure | | Flag to say that strict SSL checks are not enabled (so the remote certificate could be anonymous).
|
||||
|spring.grpc.client.default-channel.ssl.bundle | | SSL bundle name.
|
||||
|spring.grpc.client.default-channel.ssl.enabled | | Whether to enable SSL support. Enabled automatically if "bundle" is provided unless specified otherwise.
|
||||
|spring.grpc.client.default-channel.user-agent | |
|
||||
|spring.grpc.server.address | | The address to bind to. could be a host:port combination or a pseudo URL like static://host:port. Can not be set if host or port are set independently.
|
||||
|spring.grpc.server.host | `+++*+++` | Server address to bind to. The default is any IP address ('*').
|
||||
|spring.grpc.server.host | | Server address to bind to. The default is any IP address ('*').
|
||||
|spring.grpc.server.keep-alive.max-age | | Maximum time a connection may exist before being gracefully terminated (default infinite).
|
||||
|spring.grpc.server.keep-alive.max-age-grace | | Maximum time for graceful connection termination (default infinite).
|
||||
|spring.grpc.server.keep-alive.max-idle | | Maximum time a connection can remain idle before being gracefully terminated (default infinite).
|
||||
|spring.grpc.server.keep-alive.permit-time | `+++5m+++` | Maximum keep-alive time clients are permitted to configure (default 5m).
|
||||
|spring.grpc.server.keep-alive.permit-without-calls | `+++false+++` | Whether clients are permitted to send keep alive pings when there are no outstanding RPCs on the connection (default false).
|
||||
|spring.grpc.server.keep-alive.time | `+++2h+++` | Duration without read activity before sending a keep alive ping (default 2h).
|
||||
|spring.grpc.server.keep-alive.timeout | `+++20s+++` | Maximum time to wait for read activity after sending a keep alive ping. If sender does not receive an acknowledgment within this time, it will close the connection (default 20s).
|
||||
|spring.grpc.server.max-inbound-message-size | `+++4194304B+++` | Maximum message size allowed to be received by the server (default 4MiB).
|
||||
|spring.grpc.server.max-inbound-metadata-size | `+++8192B+++` | Maximum metadata size allowed to be received by the server (default 8KiB).
|
||||
|spring.grpc.server.observations.enabled | `+++true+++` | Whether to enable Observations on the server.
|
||||
|spring.grpc.server.port | `+++9090+++` | Server port to listen on. When the value is 0, a random available port is selected. The default is 9090.
|
||||
|spring.grpc.server.reflection.enabled | `+++true+++` | Whether to enable Reflection on the gRPC server.
|
||||
|spring.grpc.server.shutdown-grace-period | `+++30s+++` | Maximum time to wait for the server to gracefully shutdown. When the value is negative, the server waits forever. When the value is 0, the server will force shutdown immediately. The default is 30 seconds.
|
||||
|spring.grpc.server.keep-alive.permit-time | | Maximum keep-alive time clients are permitted to configure (default 5m).
|
||||
|spring.grpc.server.keep-alive.permit-without-calls | | Whether clients are permitted to send keep alive pings when there are no outstanding RPCs on the connection (default false).
|
||||
|spring.grpc.server.keep-alive.time | | Duration without read activity before sending a keep alive ping (default 2h).
|
||||
|spring.grpc.server.keep-alive.timeout | | Maximum time to wait for read activity after sending a keep alive ping. If sender does not receive an acknowledgment within this time, it will close the connection (default 20s).
|
||||
|spring.grpc.server.max-inbound-message-size | | Maximum message size allowed to be received by the server (default 4MiB).
|
||||
|spring.grpc.server.max-inbound-metadata-size | | Maximum metadata size allowed to be received by the server (default 8KiB).
|
||||
|spring.grpc.server.port | | Server port to listen on. When the value is 0, a random available port is selected. The default is 9090.
|
||||
|spring.grpc.server.shutdown-grace-period | | Maximum time to wait for the server to gracefully shutdown. When the value is negative, the server waits forever. When the value is 0, the server will force shutdown immediately. The default is 30 seconds.
|
||||
|spring.grpc.server.ssl.bundle | | SSL bundle name.
|
||||
|spring.grpc.server.ssl.client-auth | | Client authentication mode.
|
||||
|spring.grpc.server.ssl.enabled | | Whether to enable SSL support. Enabled automatically if "bundle" is provided unless specified otherwise.
|
||||
|spring.grpc.server.ssl.secure | `+++true+++` | Flag to indicate that client authentication is secure (i.e. certificates are checked). Do not set this to false in production.
|
||||
|spring.grpc.server.ssl.secure | | Flag to indicate that client authentication is secure (i.e. certificates are checked). Do not set this to false in production.
|
||||
|
||||
|===
|
||||
@@ -51,7 +51,6 @@
|
||||
<groupId>org.springframework.grpc</groupId>
|
||||
<artifactId>spring-grpc-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
@@ -100,12 +99,6 @@
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.grpc</groupId>
|
||||
<artifactId>spring-grpc-test</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.springframework.grpc.autoconfigure.server;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -27,9 +30,6 @@ import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource;
|
||||
import org.springframework.util.unit.DataSize;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
/**
|
||||
* Tests for {@link GrpcServerProperties}.
|
||||
*
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
<version>0.2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>spring-grpc-test</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Spring gRPC Test</name>
|
||||
<description>Test support for gRPC programming</description>
|
||||
<url>https://github.com/spring-projects-experimental/spring-grpc</url>
|
||||
@@ -28,12 +27,22 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.grpc</groupId>
|
||||
<artifactId>spring-grpc-core</artifactId>
|
||||
<artifactId>spring-grpc-spring-boot-autoconfigure</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-testing</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-inprocess</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 org.springframework.grpc.client.DefaultGrpcChannelFactory;
|
||||
|
||||
import io.grpc.ChannelCredentials;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
import io.grpc.inprocess.InProcessChannelBuilder;
|
||||
|
||||
public class InProcessGrpcChannelFactory extends DefaultGrpcChannelFactory {
|
||||
|
||||
@Override
|
||||
protected ManagedChannelBuilder<?> newChannel(String path, ChannelCredentials creds) {
|
||||
return InProcessChannelBuilder.forName(path);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.grpc.server.DefaultGrpcServerFactory;
|
||||
import org.springframework.grpc.server.ServerBuilderCustomizer;
|
||||
|
||||
import io.grpc.inprocess.InProcessServerBuilder;
|
||||
|
||||
public class InProcessGrpcServerFactory extends DefaultGrpcServerFactory<InProcessServerBuilder> {
|
||||
|
||||
public InProcessGrpcServerFactory(String address,
|
||||
List<ServerBuilderCustomizer<InProcessServerBuilder>> serverBuilderCustomizers) {
|
||||
super(address, serverBuilderCustomizers);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InProcessServerBuilder newServerBuilder() {
|
||||
return InProcessServerBuilder.forName(address());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user