Search in sources :

Example 6 with NameResolver

use of io.grpc.NameResolver in project grpc-java by grpc.

the class ManagedChannelImplGetNameResolverTest method validAuthorityTarget_overrideAuthority.

@Test
public void validAuthorityTarget_overrideAuthority() throws Exception {
    String target = "foo.googleapis.com:8080";
    String overrideAuthority = "override.authority";
    URI expectedUri = new URI("defaultscheme", "", "/foo.googleapis.com:8080", null);
    NameResolver.Factory nameResolverFactory = new FakeNameResolverFactory(expectedUri.getScheme());
    NameResolver nameResolver = ManagedChannelImpl.getNameResolver(target, overrideAuthority, nameResolverFactory, NAMERESOLVER_ARGS);
    assertThat(nameResolver.getServiceAuthority()).isEqualTo(overrideAuthority);
}
Also used : URI(java.net.URI) NameResolver(io.grpc.NameResolver) Test(org.junit.Test)

Example 7 with NameResolver

use of io.grpc.NameResolver in project grpc-java by grpc.

the class XdsNameResolverProviderTest method newProvider_overrideBootstrap.

@Test
public void newProvider_overrideBootstrap() {
    Map<String, ?> b = ImmutableMap.of("node", ImmutableMap.of("id", "ENVOY_NODE_ID", "cluster", "ENVOY_CLUSTER"), "xds_servers", Collections.singletonList(ImmutableMap.of("server_uri", "trafficdirector.googleapis.com:443", "channel_creds", Collections.singletonList(ImmutableMap.of("type", "insecure")))));
    NameResolverRegistry registry = new NameResolverRegistry();
    XdsNameResolverProvider provider = XdsNameResolverProvider.createForTest("no-scheme", b);
    registry.register(provider);
    NameResolver resolver = registry.asFactory().newNameResolver(URI.create("no-scheme:///localhost"), args);
    resolver.start(mock(NameResolver.Listener2.class));
    assertThat(resolver).isInstanceOf(XdsNameResolver.class);
    assertThat(((XdsNameResolver) resolver).getXdsClient().getBootstrapInfo().node().getId()).isEqualTo("ENVOY_NODE_ID");
    resolver.shutdown();
    registry.deregister(provider);
}
Also used : NameResolver(io.grpc.NameResolver) NameResolverRegistry(io.grpc.NameResolverRegistry) Test(org.junit.Test)

Aggregations

NameResolver (io.grpc.NameResolver)7 URI (java.net.URI)6 Test (org.junit.Test)4 URISyntaxException (java.net.URISyntaxException)3 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)2 CreateSubchannelArgs (io.grpc.LoadBalancer.CreateSubchannelArgs)2 PickSubchannelArgs (io.grpc.LoadBalancer.PickSubchannelArgs)2 ProxiedSocketAddress (io.grpc.ProxiedSocketAddress)2 SocketAddress (java.net.SocketAddress)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ManagedChannel (io.grpc.ManagedChannel)1 NameResolverRegistry (io.grpc.NameResolverRegistry)1 ProxyDetector (io.grpc.ProxyDetector)1 ClientTransportFactoryBuilder (io.grpc.internal.ManagedChannelImplBuilder.ClientTransportFactoryBuilder)1 UnsupportedClientTransportFactoryBuilder (io.grpc.internal.ManagedChannelImplBuilder.UnsupportedClientTransportFactoryBuilder)1 PolicySelection (io.grpc.internal.ServiceConfigUtil.PolicySelection)1 InetSocketAddress (java.net.InetSocketAddress)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Nullable (javax.annotation.Nullable)1