### Question:
GrpcChannelsProvider { Map<String, GrpcChannelDescriptor> channels() { return channelConfigs; } private  GrpcChannelsProvider(Map<String, GrpcChannelDescriptor> channelDescriptors); static GrpcChannelsProvider create(); static GrpcChannelsProvider create(Config config); static GrpcChannelsProvider.Builder builder(); static GrpcChannelsProvider.Builder builder(Config config); ManagedChannel channel(String name); static final String DEFAULT_CHANNEL_NAME; static final String DEFAULT_HOST; static final String CFG_KEY_CHANNELS; static final int DEFAULT_PORT; }### Answer:
@Test public void testConfigLoading() { String[] expectedChannelConfigNames = new String[] { DEFAULT_HOST_PORT_CFG, DEFAULT_HOST_CFG, DEFAULT_PORT_CFG, DEFAULT_HOST_SSL_ONE_WAY_CFG, DEFAULT_PORT_SSL_CFG, DEFAULT_HOST_PORT_SSL_DISABLED_CFG }; assertThat(grpcConfig.channels().size(), equalTo(expectedChannelConfigNames.length + 2)); assertThat(grpcConfig.channels().keySet(), hasItems(expectedChannelConfigNames)); assertThat(grpcConfig.channels().keySet(), hasItems(GrpcChannelsProvider.DEFAULT_CHANNEL_NAME)); }
@Test public void testDefaultHostPortConfig() { GrpcChannelDescriptor chCfg = grpcConfig.channels().get(DEFAULT_HOST_PORT_CFG); assertThat(chCfg.host(), equalTo("localhost")); assertThat(chCfg.port(), equalTo(1408)); assertThat(chCfg.tlsDescriptor().isPresent(), is(false)); assertThat(chCfg.target().isPresent(), is(false)); assertThat(chCfg.loadBalancerPolicy().isPresent(), is(false)); assertThat(chCfg.nameResolverFactory().isPresent(), is(false)); }
@Test public void testDefaultHostConfig() { GrpcChannelDescriptor chCfg = grpcConfig.channels().get(DEFAULT_HOST_CFG); assertThat(chCfg.host(), equalTo("localhost")); assertThat(chCfg.port(), equalTo(4096)); assertThat(chCfg.tlsDescriptor().isPresent(), is(false)); assertThat(chCfg.target().isPresent(), is(false)); assertThat(chCfg.loadBalancerPolicy().isPresent(), is(false)); assertThat(chCfg.nameResolverFactory().isPresent(), is(false)); }
@Test public void testDefaultPortConfig() { GrpcChannelDescriptor chCfg = grpcConfig.channels().get(DEFAULT_PORT_CFG); assertThat(chCfg.host(), equalTo("non_default_host.com")); assertThat(chCfg.port(), equalTo(1408)); assertThat(chCfg.tlsDescriptor().isPresent(), is(false)); assertThat(chCfg.target().isPresent(), is(false)); assertThat(chCfg.loadBalancerPolicy().isPresent(), is(false)); assertThat(chCfg.nameResolverFactory().isPresent(), is(false)); }
@Test public void testDefaultHostPortSslDisabledConfig() { GrpcChannelDescriptor chCfg = grpcConfig.channels().get(DEFAULT_HOST_PORT_SSL_DISABLED_CFG); assertThat(chCfg.host(), equalTo("localhost")); assertThat(chCfg.port(), equalTo(1408)); Optional<GrpcTlsDescriptor> descriptor = chCfg.tlsDescriptor(); assertThat(descriptor.isPresent(), is(false)); }