Search in sources :

Example 26 with ConfigOrError

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

the class ManagedChannelImplTest method nameResolverHelper_emptyConfigSucceeds.

@Test
public void nameResolverHelper_emptyConfigSucceeds() {
    boolean retryEnabled = false;
    int maxRetryAttemptsLimit = 2;
    int maxHedgedAttemptsLimit = 3;
    AutoConfiguredLoadBalancerFactory autoConfiguredLoadBalancerFactory = new AutoConfiguredLoadBalancerFactory("pick_first");
    ScParser parser = new ScParser(retryEnabled, maxRetryAttemptsLimit, maxHedgedAttemptsLimit, autoConfiguredLoadBalancerFactory);
    ConfigOrError coe = parser.parseServiceConfig(ImmutableMap.<String, Object>of());
    assertThat(coe.getError()).isNull();
    ManagedChannelServiceConfig cfg = (ManagedChannelServiceConfig) coe.getConfig();
    assertThat(cfg.getMethodConfig(method)).isEqualTo(ManagedChannelServiceConfig.empty().getMethodConfig(method));
}
Also used : ConfigOrError(io.grpc.NameResolver.ConfigOrError) Test(org.junit.Test)

Example 27 with ConfigOrError

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

the class ManagedChannelImplTest method nameResolverHelper_badConfigFails.

@Test
public void nameResolverHelper_badConfigFails() {
    boolean retryEnabled = false;
    int maxRetryAttemptsLimit = 2;
    int maxHedgedAttemptsLimit = 3;
    AutoConfiguredLoadBalancerFactory autoConfiguredLoadBalancerFactory = new AutoConfiguredLoadBalancerFactory("pick_first");
    ScParser parser = new ScParser(retryEnabled, maxRetryAttemptsLimit, maxHedgedAttemptsLimit, autoConfiguredLoadBalancerFactory);
    ConfigOrError coe = parser.parseServiceConfig(ImmutableMap.<String, Object>of("methodConfig", "bogus"));
    assertThat(coe.getError()).isNotNull();
    assertThat(coe.getError().getCode()).isEqualTo(Code.UNKNOWN);
    assertThat(coe.getError().getDescription()).contains("failed to parse service config");
    assertThat(coe.getError().getCause()).isInstanceOf(ClassCastException.class);
}
Also used : ConfigOrError(io.grpc.NameResolver.ConfigOrError) Test(org.junit.Test)

Example 28 with ConfigOrError

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

the class ManagedChannelImplTest method nameResolverHelper_noConfigChosen.

@Test
public void nameResolverHelper_noConfigChosen() {
    boolean retryEnabled = false;
    int maxRetryAttemptsLimit = 2;
    int maxHedgedAttemptsLimit = 3;
    AutoConfiguredLoadBalancerFactory autoConfiguredLoadBalancerFactory = new AutoConfiguredLoadBalancerFactory("pick_first");
    ScParser parser = new ScParser(retryEnabled, maxRetryAttemptsLimit, maxHedgedAttemptsLimit, autoConfiguredLoadBalancerFactory);
    ConfigOrError coe = parser.parseServiceConfig(ImmutableMap.of("loadBalancingConfig", ImmutableList.of()));
    assertThat(coe.getError()).isNull();
    ManagedChannelServiceConfig cfg = (ManagedChannelServiceConfig) coe.getConfig();
    assertThat(cfg.getLoadBalancingConfig()).isNull();
}
Also used : ConfigOrError(io.grpc.NameResolver.ConfigOrError) Test(org.junit.Test)

Example 29 with ConfigOrError

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

the class DnsNameResolverTest method parseServiceConfig_noChoiceIsNull.

@Test
public void parseServiceConfig_noChoiceIsNull() {
    ConfigOrError result = DnsNameResolver.parseServiceConfig(Arrays.asList("grpc_config=[]"), new Random(), "localhost");
    assertThat(result).isNull();
}
Also used : Random(java.util.Random) ConfigOrError(io.grpc.NameResolver.ConfigOrError) Test(org.junit.Test)

Example 30 with ConfigOrError

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

the class DnsNameResolverTest method parseServiceConfig_capturesParseError.

@Test
public void parseServiceConfig_capturesParseError() {
    ConfigOrError result = DnsNameResolver.parseServiceConfig(Arrays.asList("grpc_config=bogus"), new Random(), "localhost");
    assertThat(result).isNotNull();
    assertThat(result.getError().getCode()).isEqualTo(Status.Code.UNKNOWN);
    assertThat(result.getError().getDescription()).contains("failed to parse TXT records");
}
Also used : Random(java.util.Random) ConfigOrError(io.grpc.NameResolver.ConfigOrError) Test(org.junit.Test)

Aggregations

ConfigOrError (io.grpc.NameResolver.ConfigOrError)57 Test (org.junit.Test)52 PolicySelection (io.grpc.internal.ServiceConfigUtil.PolicySelection)10 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)9 Helper (io.grpc.LoadBalancer.Helper)9 Status (io.grpc.Status)9 AutoConfiguredLoadBalancer (io.grpc.internal.AutoConfiguredLoadBalancerFactory.AutoConfiguredLoadBalancer)7 ForwardingLoadBalancerHelper (io.grpc.util.ForwardingLoadBalancerHelper)7 Map (java.util.Map)7 InetSocketAddress (java.net.InetSocketAddress)6 SocketAddress (java.net.SocketAddress)4 Random (java.util.Random)4 CreateSubchannelArgs (io.grpc.LoadBalancer.CreateSubchannelArgs)3 ResolvedAddresses (io.grpc.LoadBalancer.ResolvedAddresses)3 LoadBalancerProvider (io.grpc.LoadBalancerProvider)3 LoadBalancerRegistry (io.grpc.LoadBalancerRegistry)3 LeastRequestConfig (io.grpc.xds.LeastRequestLoadBalancer.LeastRequestConfig)3 LbConfig (io.grpc.internal.ServiceConfigUtil.LbConfig)2 RingHashConfig (io.grpc.xds.RingHashLoadBalancer.RingHashConfig)2 LinkedHashMap (java.util.LinkedHashMap)2