|
17 | 17 | package io.grpc.xds; |
18 | 18 |
|
19 | 19 | import static com.google.common.truth.Truth.assertThat; |
| 20 | +import static org.junit.Assert.assertNotNull; |
| 21 | +import static org.junit.Assert.assertSame; |
20 | 22 | import static org.mockito.Mockito.mock; |
21 | 23 | import static org.mockito.Mockito.verify; |
| 24 | +import static org.mockito.Mockito.when; |
22 | 25 |
|
23 | 26 | import com.google.common.util.concurrent.SettableFuture; |
24 | 27 | import io.envoyproxy.envoy.service.discovery.v3.AggregatedDiscoveryServiceGrpc; |
|
35 | 38 | import io.grpc.InsecureServerCredentials; |
36 | 39 | import io.grpc.ManagedChannelBuilder; |
37 | 40 | import io.grpc.MethodDescriptor; |
| 41 | +import io.grpc.NameResolver; |
| 42 | +import io.grpc.NameResolverProvider; |
| 43 | +import io.grpc.NameResolverRegistry; |
38 | 44 | import io.grpc.NoopClientCall; |
39 | 45 | import io.grpc.Server; |
40 | 46 | import io.grpc.Status; |
|
43 | 49 | import io.grpc.testing.TestMethodDescriptors; |
44 | 50 | import io.grpc.xds.client.Bootstrapper; |
45 | 51 | import io.grpc.xds.client.XdsTransportFactory; |
| 52 | +import java.net.URI; |
46 | 53 | import java.util.concurrent.BlockingQueue; |
47 | 54 | import java.util.concurrent.LinkedBlockingQueue; |
48 | 55 | import java.util.concurrent.TimeUnit; |
| 56 | +import java.util.concurrent.atomic.AtomicReference; |
49 | 57 | import org.junit.After; |
50 | 58 | import org.junit.Before; |
51 | 59 | import org.junit.Rule; |
@@ -280,6 +288,48 @@ public void configureChannelBuilder(ManagedChannelBuilder<?> builder) { |
280 | 288 | transport.shutdown(); |
281 | 289 | } |
282 | 290 |
|
| 291 | + @Test |
| 292 | + public void useChannelConfigurator_setsChildChannelConfigurator() { |
| 293 | + final AtomicReference<NameResolver.Args> capturedArgs = new AtomicReference<>(); |
| 294 | + NameResolverProvider testProvider = new NameResolverProvider() { |
| 295 | + @Override |
| 296 | + public NameResolver newNameResolver(URI targetUri, NameResolver.Args args) { |
| 297 | + capturedArgs.set(args); |
| 298 | + NameResolver resolver = mock(NameResolver.class); |
| 299 | + when(resolver.getServiceAuthority()).thenReturn("localhost:8080"); |
| 300 | + return resolver; |
| 301 | + } |
| 302 | + |
| 303 | + @Override |
| 304 | + public String getDefaultScheme() { |
| 305 | + return "test-xds-transport"; |
| 306 | + } |
| 307 | + |
| 308 | + @Override |
| 309 | + protected boolean isAvailable() { |
| 310 | + return true; |
| 311 | + } |
| 312 | + |
| 313 | + @Override |
| 314 | + protected int priority() { |
| 315 | + return 10; |
| 316 | + } |
| 317 | + }; |
| 318 | + NameResolverRegistry.getDefaultRegistry().register(testProvider); |
| 319 | + try { |
| 320 | + ChannelConfigurator configurer = builder -> { }; |
| 321 | + GrpcXdsTransportFactory factory = new GrpcXdsTransportFactory(null, configurer); |
| 322 | + XdsTransportFactory.XdsTransport transport = factory.create( |
| 323 | + Bootstrapper.ServerInfo.create( |
| 324 | + "test-xds-transport://localhost:8080", InsecureChannelCredentials.create())); |
| 325 | + assertNotNull(capturedArgs.get()); |
| 326 | + assertSame(configurer, capturedArgs.get().getChildChannelConfigurator()); |
| 327 | + transport.shutdown(); |
| 328 | + } finally { |
| 329 | + NameResolverRegistry.getDefaultRegistry().deregister(testProvider); |
| 330 | + } |
| 331 | + } |
| 332 | + |
283 | 333 | @Test |
284 | 334 | public void useChannelConfigurator_throwsException_propagates() { |
285 | 335 | final RuntimeException testException = new RuntimeException("test exception"); |
|
0 commit comments