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);
}
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);
}
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();
}
Aggregations