Avoid NettyServerBuilder when unnecessary

These code locations just needed a generic gRPC server, without any
transport-specific configuration. Use vanilla ManagedServerBuilder
instead of hard-coding to Netty, as we would suggest to our users.
This commit is contained in:
Eric Anderson 2023-05-31 12:45:03 -07:00
parent 217103cd5e
commit 33a402d924
3 changed files with 11 additions and 9 deletions

View File

@ -34,12 +34,12 @@ import io.grpc.ForwardingClientCall.SimpleForwardingClientCall;
import io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener; import io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener;
import io.grpc.Grpc; import io.grpc.Grpc;
import io.grpc.InsecureChannelCredentials; import io.grpc.InsecureChannelCredentials;
import io.grpc.InsecureServerCredentials;
import io.grpc.ManagedChannel; import io.grpc.ManagedChannel;
import io.grpc.Metadata; import io.grpc.Metadata;
import io.grpc.MethodDescriptor; import io.grpc.MethodDescriptor;
import io.grpc.Server; import io.grpc.Server;
import io.grpc.Status; import io.grpc.Status;
import io.grpc.netty.NettyServerBuilder;
import io.grpc.protobuf.services.ProtoReflectionService; import io.grpc.protobuf.services.ProtoReflectionService;
import io.grpc.services.AdminInterface; import io.grpc.services.AdminInterface;
import io.grpc.stub.StreamObserver; import io.grpc.stub.StreamObserver;
@ -242,7 +242,7 @@ public final class XdsTestClient {
private void run() { private void run() {
statsServer = statsServer =
NettyServerBuilder.forPort(statsPort) Grpc.newServerBuilderForPort(statsPort, InsecureServerCredentials.create())
.addService(new XdsStatsImpl()) .addService(new XdsStatsImpl())
.addService(new ConfigureUpdateServiceImpl()) .addService(new ConfigureUpdateServiceImpl())
.addService(ProtoReflectionService.newInstance()) .addService(ProtoReflectionService.newInstance())

View File

@ -19,6 +19,7 @@ package io.grpc.testing.integration;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import io.grpc.ForwardingServerCall.SimpleForwardingServerCall; import io.grpc.ForwardingServerCall.SimpleForwardingServerCall;
import io.grpc.Grpc;
import io.grpc.InsecureServerCredentials; import io.grpc.InsecureServerCredentials;
import io.grpc.Metadata; import io.grpc.Metadata;
import io.grpc.Server; import io.grpc.Server;
@ -28,7 +29,6 @@ import io.grpc.ServerInterceptor;
import io.grpc.ServerInterceptors; import io.grpc.ServerInterceptors;
import io.grpc.Status; import io.grpc.Status;
import io.grpc.health.v1.HealthCheckResponse.ServingStatus; import io.grpc.health.v1.HealthCheckResponse.ServingStatus;
import io.grpc.netty.NettyServerBuilder;
import io.grpc.protobuf.services.HealthStatusManager; import io.grpc.protobuf.services.HealthStatusManager;
import io.grpc.protobuf.services.ProtoReflectionService; import io.grpc.protobuf.services.ProtoReflectionService;
import io.grpc.services.AdminInterface; import io.grpc.services.AdminInterface;
@ -177,7 +177,7 @@ public final class XdsTestServer {
health = new HealthStatusManager(); health = new HealthStatusManager();
if (secureMode) { if (secureMode) {
maintenanceServer = maintenanceServer =
NettyServerBuilder.forPort(maintenancePort) Grpc.newServerBuilderForPort(maintenancePort, InsecureServerCredentials.create())
.addService(new XdsUpdateHealthServiceImpl(health)) .addService(new XdsUpdateHealthServiceImpl(health))
.addService(health.getHealthService()) .addService(health.getHealthService())
.addService(ProtoReflectionService.newInstance()) .addService(ProtoReflectionService.newInstance())
@ -194,7 +194,7 @@ public final class XdsTestServer {
server.start(); server.start();
} else { } else {
server = server =
NettyServerBuilder.forPort(port) Grpc.newServerBuilderForPort(port, InsecureServerCredentials.create())
.addService( .addService(
ServerInterceptors.intercept( ServerInterceptors.intercept(
new TestServiceImpl(serverId, host), new TestInfoInterceptor(host))) new TestServiceImpl(serverId, host), new TestInfoInterceptor(host)))

View File

@ -51,9 +51,10 @@ import io.envoyproxy.envoy.extensions.filters.http.router.v3.Router;
import io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager; import io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager;
import io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter; import io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter;
import io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.Rds; import io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.Rds;
import io.grpc.Grpc;
import io.grpc.InsecureServerCredentials;
import io.grpc.NameResolverRegistry; import io.grpc.NameResolverRegistry;
import io.grpc.Server; import io.grpc.Server;
import io.grpc.netty.NettyServerBuilder;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -114,10 +115,11 @@ public class ControlPlaneRule extends TestWatcher {
try { try {
controlPlaneService = new XdsTestControlPlaneService(); controlPlaneService = new XdsTestControlPlaneService();
loadReportingService = new XdsTestLoadReportingService(); loadReportingService = new XdsTestLoadReportingService();
NettyServerBuilder controlPlaneServerBuilder = NettyServerBuilder.forPort(0) server = Grpc.newServerBuilderForPort(0, InsecureServerCredentials.create())
.addService(controlPlaneService) .addService(controlPlaneService)
.addService(loadReportingService); .addService(loadReportingService)
server = controlPlaneServerBuilder.build().start(); .build()
.start();
} catch (Exception e) { } catch (Exception e) {
throw new AssertionError("unable to start the control plane server", e); throw new AssertionError("unable to start the control plane server", e);
} }