Skip to content

Commit

Permalink
Constructing XdsClient with channel injected.
Browse files Browse the repository at this point in the history
  • Loading branch information
voidzcy committed Sep 15, 2020
1 parent ee89f3e commit 603d929
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 58 deletions.
9 changes: 2 additions & 7 deletions xds/src/main/java/io/grpc/xds/XdsClientImpl.java
Expand Up @@ -53,7 +53,6 @@
import io.grpc.SynchronizationContext.ScheduledHandle;
import io.grpc.internal.BackoffPolicy;
import io.grpc.stub.StreamObserver;
import io.grpc.xds.Bootstrapper.ServerInfo;
import io.grpc.xds.EnvoyProtoData.DropOverload;
import io.grpc.xds.EnvoyProtoData.Locality;
import io.grpc.xds.EnvoyProtoData.LocalityLbEndpoints;
Expand Down Expand Up @@ -196,18 +195,14 @@ final class XdsClientImpl extends XdsClient {

XdsClientImpl(
String targetName,
List<ServerInfo> servers, // list of management servers
XdsChannelFactory channelFactory,
XdsChannel channel,
Node node,
SynchronizationContext syncContext,
ScheduledExecutorService timeService,
BackoffPolicy.Provider backoffPolicyProvider,
Supplier<Stopwatch> stopwatchSupplier) {
this.targetName = checkNotNull(targetName, "targetName");
XdsChannel xdsChannel =
checkNotNull(channelFactory, "channelFactory")
.createChannel(checkNotNull(servers, "servers"));
this.xdsChannel = xdsChannel;
this.xdsChannel = checkNotNull(channel, "channel");
this.node = checkNotNull(node, "node");
this.syncContext = checkNotNull(syncContext, "syncContext");
this.timeService = checkNotNull(timeService, "timeService");
Expand Down
18 changes: 1 addition & 17 deletions xds/src/test/java/io/grpc/xds/XdsClientImplTest.java
Expand Up @@ -86,8 +86,6 @@
import io.grpc.internal.FakeClock.TaskFilter;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.GrpcCleanupRule;
import io.grpc.xds.Bootstrapper.ChannelCreds;
import io.grpc.xds.Bootstrapper.ServerInfo;
import io.grpc.xds.EnvoyProtoData.DropOverload;
import io.grpc.xds.EnvoyProtoData.LbEndpoint;
import io.grpc.xds.EnvoyProtoData.Locality;
Expand All @@ -100,7 +98,6 @@
import io.grpc.xds.XdsClient.EndpointUpdate;
import io.grpc.xds.XdsClient.EndpointWatcher;
import io.grpc.xds.XdsClient.XdsChannel;
import io.grpc.xds.XdsClient.XdsChannelFactory;
import io.grpc.xds.XdsClientImpl.MessagePrinter;
import java.io.IOException;
import java.util.ArrayDeque;
Expand Down Expand Up @@ -279,23 +276,10 @@ public void cancelled(Context context) {
channel =
cleanupRule.register(InProcessChannelBuilder.forName(serverName).directExecutor().build());

List<ServerInfo> servers =
ImmutableList.of(new ServerInfo(serverName, ImmutableList.<ChannelCreds>of(), null));
XdsChannelFactory channelFactory = new XdsChannelFactory() {
@Override
XdsChannel createChannel(List<ServerInfo> servers) {
ServerInfo serverInfo = Iterables.getOnlyElement(servers);
assertThat(serverInfo.getServerUri()).isEqualTo(serverName);
assertThat(serverInfo.getChannelCredentials()).isEmpty();
return new XdsChannel(channel, /* useProtocolV3= */ true);
}
};

xdsClient =
new XdsClientImpl(
TARGET_AUTHORITY,
servers,
channelFactory,
new XdsChannel(channel, /* useProtocolV3= */ true),
EnvoyProtoData.Node.newBuilder().build(),
syncContext,
fakeClock.getScheduledExecutorService(),
Expand Down
19 changes: 2 additions & 17 deletions xds/src/test/java/io/grpc/xds/XdsClientImplTestForListener.java
Expand Up @@ -64,15 +64,12 @@
import io.grpc.internal.FakeClock.TaskFilter;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.GrpcCleanupRule;
import io.grpc.xds.Bootstrapper.ChannelCreds;
import io.grpc.xds.Bootstrapper.ServerInfo;
import io.grpc.xds.EnvoyProtoData.Address;
import io.grpc.xds.EnvoyProtoData.Node;
import io.grpc.xds.XdsClient.ConfigWatcher;
import io.grpc.xds.XdsClient.ListenerUpdate;
import io.grpc.xds.XdsClient.ListenerWatcher;
import io.grpc.xds.XdsClient.XdsChannel;
import io.grpc.xds.XdsClient.XdsChannelFactory;
import io.grpc.xds.internal.sds.CommonTlsContextTestsUtil;
import java.io.IOException;
import java.util.ArrayDeque;
Expand Down Expand Up @@ -200,21 +197,9 @@ public void cancelled(Context context) {
channel =
cleanupRule.register(InProcessChannelBuilder.forName(serverName).directExecutor().build());

List<ServerInfo> servers =
ImmutableList.of(new ServerInfo(serverName, ImmutableList.<ChannelCreds>of(), null));
XdsChannelFactory channelFactory = new XdsChannelFactory() {
@Override
XdsChannel createChannel(List<ServerInfo> servers) {
ServerInfo serverInfo = Iterables.getOnlyElement(servers);
assertThat(serverInfo.getServerUri()).isEqualTo(serverName);
assertThat(serverInfo.getChannelCredentials()).isEmpty();
return new XdsChannel(channel, false);
}
};

xdsClient =
new XdsClientImpl("", servers, channelFactory, NODE, syncContext,
fakeClock.getScheduledExecutorService(), backoffPolicyProvider,
new XdsClientImpl("", new XdsChannel(channel, /* useProtocolV3= */ false), NODE,
syncContext, fakeClock.getScheduledExecutorService(), backoffPolicyProvider,
fakeClock.getStopwatchSupplier());
// Only the connection to management server is established, no RPC request is sent until at
// least one watcher is registered.
Expand Down
18 changes: 1 addition & 17 deletions xds/src/test/java/io/grpc/xds/XdsClientImplTestV2.java
Expand Up @@ -86,8 +86,6 @@
import io.grpc.internal.FakeClock.TaskFilter;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.GrpcCleanupRule;
import io.grpc.xds.Bootstrapper.ChannelCreds;
import io.grpc.xds.Bootstrapper.ServerInfo;
import io.grpc.xds.EnvoyProtoData.DropOverload;
import io.grpc.xds.EnvoyProtoData.LbEndpoint;
import io.grpc.xds.EnvoyProtoData.Locality;
Expand All @@ -100,7 +98,6 @@
import io.grpc.xds.XdsClient.EndpointUpdate;
import io.grpc.xds.XdsClient.EndpointWatcher;
import io.grpc.xds.XdsClient.XdsChannel;
import io.grpc.xds.XdsClient.XdsChannelFactory;
import io.grpc.xds.XdsClientImpl.MessagePrinter;
import java.io.IOException;
import java.util.ArrayDeque;
Expand Down Expand Up @@ -278,23 +275,10 @@ public void cancelled(Context context) {
channel =
cleanupRule.register(InProcessChannelBuilder.forName(serverName).directExecutor().build());

List<ServerInfo> servers =
ImmutableList.of(new ServerInfo(serverName, ImmutableList.<ChannelCreds>of(), null));
XdsChannelFactory channelFactory = new XdsChannelFactory() {
@Override
XdsChannel createChannel(List<ServerInfo> servers) {
ServerInfo serverInfo = Iterables.getOnlyElement(servers);
assertThat(serverInfo.getServerUri()).isEqualTo(serverName);
assertThat(serverInfo.getChannelCredentials()).isEmpty();
return new XdsChannel(channel, false);
}
};

xdsClient =
new XdsClientImpl(
TARGET_AUTHORITY,
servers,
channelFactory,
new XdsChannel(channel, /* useProtocolV3= */ false),
Node.newBuilder().build(),
syncContext,
fakeClock.getScheduledExecutorService(),
Expand Down

0 comments on commit 603d929

Please sign in to comment.