use of io.grpc.NameResolver.ConfigOrError in project grpc-java by grpc.
the class AutoConfiguredLoadBalancerFactoryTest method handleResolvedAddressGroups_delegateDoNotAcceptEmptyAddressList_nothing.
@Test
public void handleResolvedAddressGroups_delegateDoNotAcceptEmptyAddressList_nothing() throws Exception {
Helper helper = new TestHelper();
AutoConfiguredLoadBalancer lb = lbf.newLoadBalancer(helper);
Map<String, ?> serviceConfig = parseConfig("{\"loadBalancingConfig\": [ {\"test_lb\": { \"setting1\": \"high\" } } ] }");
ConfigOrError lbConfig = lbf.parseLoadBalancerPolicy(serviceConfig);
Status handleResult = lb.tryHandleResolvedAddresses(ResolvedAddresses.newBuilder().setAddresses(Collections.<EquivalentAddressGroup>emptyList()).setLoadBalancingPolicyConfig(lbConfig.getConfig()).build());
assertThat(testLbBalancer.canHandleEmptyAddressListFromNameResolution()).isFalse();
assertThat(handleResult.getCode()).isEqualTo(Status.Code.UNAVAILABLE);
assertThat(handleResult.getDescription()).startsWith("NameResolver returned no usable address");
assertThat(lb.getDelegate()).isSameInstanceAs(testLbBalancer);
}
use of io.grpc.NameResolver.ConfigOrError in project grpc-java by grpc.
the class AutoConfiguredLoadBalancerFactoryTest method parseLoadBalancerConfig_policyShouldBeIgnoredEvenIfUnknownPolicyExists.
@Test
public void parseLoadBalancerConfig_policyShouldBeIgnoredEvenIfUnknownPolicyExists() throws Exception {
Map<String, ?> serviceConfig = parseConfig("{\"loadBalancingConfig\": [{\"magic_balancer\": {} } ]," + "\"loadBalancingPolicy\": \"round_robin\" }");
ConfigOrError parsed = lbf.parseLoadBalancerPolicy(serviceConfig);
assertThat(parsed.getError()).isNotNull();
assertThat(parsed.getError().getDescription()).isEqualTo("None of [magic_balancer] specified by Service Config are available.");
}
use of io.grpc.NameResolver.ConfigOrError in project grpc-java by grpc.
the class AutoConfiguredLoadBalancerFactoryTest method channelTracing_lbPolicyChanged.
@Test
public void channelTracing_lbPolicyChanged() throws Exception {
List<EquivalentAddressGroup> servers = Collections.singletonList(new EquivalentAddressGroup(new SocketAddress() {
}));
Helper helper = new TestHelper() {
@Override
public Subchannel createSubchannel(CreateSubchannelArgs args) {
return new TestSubchannel(args);
}
};
AutoConfiguredLoadBalancer lb = new AutoConfiguredLoadBalancerFactory(GrpcUtil.DEFAULT_LB_POLICY).newLoadBalancer(helper);
Status handleResult = lb.tryHandleResolvedAddresses(ResolvedAddresses.newBuilder().setAddresses(servers).setAttributes(Attributes.EMPTY).build());
assertThat(handleResult.getCode()).isEqualTo(Status.Code.OK);
verifyNoMoreInteractions(channelLogger);
ConfigOrError testLbParsedConfig = ConfigOrError.fromConfig("foo");
nextParsedConfigOrError.set(testLbParsedConfig);
Map<String, ?> serviceConfig = parseConfig("{\"loadBalancingConfig\": [ {\"test_lb\": { } } ] }");
ConfigOrError lbConfigs = lbf.parseLoadBalancerPolicy(serviceConfig);
handleResult = lb.tryHandleResolvedAddresses(ResolvedAddresses.newBuilder().setAddresses(servers).setLoadBalancingPolicyConfig(lbConfigs.getConfig()).build());
assertThat(handleResult.getCode()).isEqualTo(Status.Code.OK);
verify(channelLogger).log(eq(ChannelLogLevel.INFO), eq("Load balancer changed from {0} to {1}"), eq("PickFirstLoadBalancer"), eq(testLbBalancer.getClass().getSimpleName()));
verify(channelLogger).log(eq(ChannelLogLevel.DEBUG), eq("Load-balancing config: {0}"), eq(testLbParsedConfig.getConfig()));
verifyNoMoreInteractions(channelLogger);
testLbParsedConfig = ConfigOrError.fromConfig("bar");
nextParsedConfigOrError.set(testLbParsedConfig);
serviceConfig = parseConfig("{\"loadBalancingConfig\": [ {\"test_lb\": { } } ] }");
lbConfigs = lbf.parseLoadBalancerPolicy(serviceConfig);
handleResult = lb.tryHandleResolvedAddresses(ResolvedAddresses.newBuilder().setAddresses(servers).setLoadBalancingPolicyConfig(lbConfigs.getConfig()).build());
assertThat(handleResult.getCode()).isEqualTo(Status.Code.OK);
verify(channelLogger).log(eq(ChannelLogLevel.DEBUG), eq("Load-balancing config: {0}"), eq(testLbParsedConfig.getConfig()));
verifyNoMoreInteractions(channelLogger);
}
use of io.grpc.NameResolver.ConfigOrError in project grpc-java by grpc.
the class AutoConfiguredLoadBalancerFactoryTest method parseLoadBalancerConfig_firstInvalidPolicy.
@Test
@SuppressWarnings("unchecked")
public void parseLoadBalancerConfig_firstInvalidPolicy() throws Exception {
when(testLbBalancerProvider.parseLoadBalancingPolicyConfig(any(Map.class))).thenReturn(ConfigOrError.fromError(Status.UNKNOWN));
Map<String, ?> serviceConfig = parseConfig("{\"loadBalancingConfig\": [" + "{\"test_lb\": {}}," + "{\"round_robin\": {} } ] }");
ConfigOrError parsed = lbf.parseLoadBalancerPolicy(serviceConfig);
assertThat(parsed).isNotNull();
assertThat(parsed.getConfig()).isNull();
assertThat(parsed.getError()).isEqualTo(Status.UNKNOWN);
}
use of io.grpc.NameResolver.ConfigOrError in project grpc-java by grpc.
the class AutoConfiguredLoadBalancerFactoryTest method parseLoadBalancerConfig_someProvidesAreNotAvailable.
@Test
public void parseLoadBalancerConfig_someProvidesAreNotAvailable() throws Exception {
Map<String, ?> serviceConfig = parseConfig("{\"loadBalancingConfig\": [ " + "{\"magic_balancer\": {} }," + "{\"round_robin\": {}} ] }");
ConfigOrError parsed = lbf.parseLoadBalancerPolicy(serviceConfig);
assertThat(parsed).isNotNull();
assertThat(parsed.getConfig()).isNotNull();
assertThat(((PolicySelection) parsed.getConfig()).config).isNotNull();
}
Aggregations