Search in sources :

Example 1 with NameResolverRegistry

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

the class ClusterResolverLoadBalancerProviderTest method providesLoadBalancer.

@Test
public void providesLoadBalancer() {
    Helper helper = mock(Helper.class);
    SynchronizationContext syncContext = new SynchronizationContext(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            throw new AssertionError(e);
        }
    });
    FakeClock fakeClock = new FakeClock();
    NameResolverRegistry nsRegistry = new NameResolverRegistry();
    NameResolver.Args args = NameResolver.Args.newBuilder().setDefaultPort(8080).setProxyDetector(GrpcUtil.NOOP_PROXY_DETECTOR).setSynchronizationContext(syncContext).setServiceConfigParser(mock(ServiceConfigParser.class)).setChannelLogger(mock(ChannelLogger.class)).build();
    when(helper.getNameResolverRegistry()).thenReturn(nsRegistry);
    when(helper.getNameResolverArgs()).thenReturn(args);
    when(helper.getSynchronizationContext()).thenReturn(syncContext);
    when(helper.getScheduledExecutorService()).thenReturn(fakeClock.getScheduledExecutorService());
    when(helper.getAuthority()).thenReturn("api.google.com");
    LoadBalancerProvider provider = new ClusterResolverLoadBalancerProvider();
    LoadBalancer loadBalancer = provider.newLoadBalancer(helper);
    assertThat(loadBalancer).isInstanceOf(ClusterResolverLoadBalancer.class);
}
Also used : FakeClock(io.grpc.internal.FakeClock) LoadBalancer(io.grpc.LoadBalancer) NameResolverRegistry(io.grpc.NameResolverRegistry) Helper(io.grpc.LoadBalancer.Helper) SynchronizationContext(io.grpc.SynchronizationContext) LoadBalancerProvider(io.grpc.LoadBalancerProvider) ServiceConfigParser(io.grpc.NameResolver.ServiceConfigParser) NameResolver(io.grpc.NameResolver) Test(org.junit.Test)

Example 2 with NameResolverRegistry

use of io.grpc.NameResolverRegistry 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)

Example 3 with NameResolverRegistry

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

the class XdsNameResolverProviderTest method newProvider_multipleScheme.

@Test
public void newProvider_multipleScheme() {
    NameResolverRegistry registry = NameResolverRegistry.getDefaultRegistry();
    XdsNameResolverProvider provider0 = XdsNameResolverProvider.createForTest("no-scheme", null);
    registry.register(provider0);
    XdsNameResolverProvider provider1 = XdsNameResolverProvider.createForTest("new-xds-scheme", new HashMap<String, String>());
    registry.register(provider1);
    assertThat(registry.asFactory().newNameResolver(URI.create("xds:///localhost"), args)).isNotNull();
    assertThat(registry.asFactory().newNameResolver(URI.create("new-xds-scheme:///localhost"), args)).isNotNull();
    assertThat(registry.asFactory().newNameResolver(URI.create("no-scheme:///localhost"), args)).isNotNull();
    registry.deregister(provider1);
    assertThat(registry.asFactory().newNameResolver(URI.create("new-xds-scheme:///localhost"), args)).isNull();
    registry.deregister(provider0);
    assertThat(registry.asFactory().newNameResolver(URI.create("xds:///localhost"), args)).isNotNull();
}
Also used : NameResolverRegistry(io.grpc.NameResolverRegistry) Test(org.junit.Test)

Aggregations

NameResolverRegistry (io.grpc.NameResolverRegistry)3 Test (org.junit.Test)3 NameResolver (io.grpc.NameResolver)2 LoadBalancer (io.grpc.LoadBalancer)1 Helper (io.grpc.LoadBalancer.Helper)1 LoadBalancerProvider (io.grpc.LoadBalancerProvider)1 ServiceConfigParser (io.grpc.NameResolver.ServiceConfigParser)1 SynchronizationContext (io.grpc.SynchronizationContext)1 FakeClock (io.grpc.internal.FakeClock)1