use of io.grpc.xds.ClientXdsClient.XdsChannelFactory in project grpc-java by grpc.
the class ClientXdsClientTestBase method setUp.
@Before
public void setUp() throws IOException {
// Init mocks.
MockitoAnnotations.initMocks(this);
when(backoffPolicyProvider.get()).thenReturn(backoffPolicy1, backoffPolicy2);
when(backoffPolicy1.nextBackoffNanos()).thenReturn(10L, 100L);
when(backoffPolicy2.nextBackoffNanos()).thenReturn(20L, 200L);
// Start the server and the client.
originalEnableFaultInjection = ClientXdsClient.enableFaultInjection;
ClientXdsClient.enableFaultInjection = true;
originalEnableRbac = ClientXdsClient.enableRbac;
assertThat(originalEnableRbac).isTrue();
originalEnableLeastRequest = ClientXdsClient.enableLeastRequest;
ClientXdsClient.enableLeastRequest = true;
final String serverName = InProcessServerBuilder.generateName();
cleanupRule.register(InProcessServerBuilder.forName(serverName).addService(createAdsService()).addService(createLrsService()).directExecutor().build().start());
channel = cleanupRule.register(InProcessChannelBuilder.forName(serverName).directExecutor().build());
XdsChannelFactory xdsChannelFactory = new XdsChannelFactory() {
@Override
ManagedChannel create(ServerInfo serverInfo) {
if (serverInfo.target().equals(SERVER_URI)) {
return channel;
}
if (serverInfo.target().equals(SERVER_URI_CUSTOME_AUTHORITY)) {
if (channelForCustomAuthority == null) {
channelForCustomAuthority = cleanupRule.register(InProcessChannelBuilder.forName(serverName).directExecutor().build());
}
return channelForCustomAuthority;
}
if (serverInfo.target().equals(SERVER_URI_EMPTY_AUTHORITY)) {
if (channelForEmptyAuthority == null) {
channelForEmptyAuthority = cleanupRule.register(InProcessChannelBuilder.forName(serverName).directExecutor().build());
}
return channelForEmptyAuthority;
}
throw new IllegalArgumentException("Can not create channel for " + serverInfo);
}
};
Bootstrapper.BootstrapInfo bootstrapInfo = Bootstrapper.BootstrapInfo.builder().servers(Arrays.asList(Bootstrapper.ServerInfo.create(SERVER_URI, CHANNEL_CREDENTIALS, useProtocolV3()))).node(EnvoyProtoData.Node.newBuilder().build()).authorities(ImmutableMap.of("authority.xds.com", AuthorityInfo.create("xdstp://authority.xds.com/envoy.config.listener.v3.Listener/%s", ImmutableList.of(Bootstrapper.ServerInfo.create(SERVER_URI_CUSTOME_AUTHORITY, CHANNEL_CREDENTIALS, useProtocolV3()))), "", AuthorityInfo.create("xdstp:///envoy.config.listener.v3.Listener/%s", ImmutableList.of(Bootstrapper.ServerInfo.create(SERVER_URI_EMPTY_AUTHORITY, CHANNEL_CREDENTIALS, useProtocolV3()))))).certProviders(ImmutableMap.of("cert-instance-name", CertificateProviderInfo.create("file-watcher", ImmutableMap.<String, Object>of()))).build();
xdsClient = new ClientXdsClient(xdsChannelFactory, bootstrapInfo, Context.ROOT, fakeClock.getScheduledExecutorService(), backoffPolicyProvider, fakeClock.getStopwatchSupplier(), timeProvider, tlsContextManager);
assertThat(resourceDiscoveryCalls).isEmpty();
assertThat(loadReportCalls).isEmpty();
}
Aggregations