use of io.grpc.NameResolver.ConfigOrError in project grpc-java by grpc.
the class AutoConfiguredLoadBalancerFactoryTest method handleResolvedAddressGroups_shutsDownOldBalancer.
@Test
public void handleResolvedAddressGroups_shutsDownOldBalancer() throws Exception {
Map<String, ?> serviceConfig = parseConfig("{\"loadBalancingConfig\": [ {\"round_robin\": { } } ] }");
ConfigOrError lbConfigs = lbf.parseLoadBalancerPolicy(serviceConfig);
final List<EquivalentAddressGroup> servers = Collections.singletonList(new EquivalentAddressGroup(new SocketAddress() {
}));
Helper helper = new TestHelper() {
@Override
public Subchannel createSubchannel(CreateSubchannelArgs args) {
assertThat(args.getAddresses()).isEqualTo(servers);
return new TestSubchannel(args);
}
};
AutoConfiguredLoadBalancer lb = lbf.newLoadBalancer(helper);
final AtomicBoolean shutdown = new AtomicBoolean();
TestLoadBalancer testlb = new TestLoadBalancer() {
@Override
public void handleNameResolutionError(Status error) {
// noop
}
@Override
public void shutdown() {
shutdown.set(true);
}
};
lb.setDelegate(testlb);
Status handleResult = lb.tryHandleResolvedAddresses(ResolvedAddresses.newBuilder().setAddresses(servers).setLoadBalancingPolicyConfig(lbConfigs.getConfig()).build());
assertThat(handleResult.getCode()).isEqualTo(Status.Code.OK);
assertThat(lb.getDelegateProvider().getClass().getName()).isEqualTo("io.grpc.util.SecretRoundRobinLoadBalancerProvider$Provider");
assertTrue(shutdown.get());
}
use of io.grpc.NameResolver.ConfigOrError in project grpc-java by grpc.
the class AutoConfiguredLoadBalancerFactoryTest method parseLoadBalancerConfig_lbConfigPropagated.
@Test
public void parseLoadBalancerConfig_lbConfigPropagated() throws Exception {
Map<String, ?> rawServiceConfig = parseConfig("{\"loadBalancingConfig\": [" + "{\"grpclb\": {\"childPolicy\": [ {\"pick_first\": {} } ] } }" + "] }");
ConfigOrError parsed = lbf.parseLoadBalancerPolicy(rawServiceConfig);
assertThat(parsed).isNotNull();
assertThat(parsed.getConfig()).isNotNull();
PolicySelection policySelection = (PolicySelection) parsed.getConfig();
assertThat(policySelection.config).isNotNull();
assertThat(policySelection.provider).isInstanceOf(GrpclbLoadBalancerProvider.class);
verifyNoInteractions(channelLogger);
}
use of io.grpc.NameResolver.ConfigOrError in project grpc-java by grpc.
the class ServiceConfigStateTest method lookup_default_onPresent_onPresent.
@Test
public void lookup_default_onPresent_onPresent() {
ServiceConfigState scs = new ServiceConfigState(serviceConfig1, true);
ManagedChannelServiceConfig serviceConfig3 = new ManagedChannelServiceConfig(null, Collections.<String, MethodInfo>emptyMap(), Collections.<String, MethodInfo>emptyMap(), null, null, null);
ConfigOrError config3 = ConfigOrError.fromConfig(serviceConfig3);
scs.update(config2);
assertFalse(scs.shouldWaitOnServiceConfig());
assertSame(config2, scs.getCurrent());
scs.update(config3);
assertSame(config3, scs.getCurrent());
}
use of io.grpc.NameResolver.ConfigOrError in project grpc-java by grpc.
the class RingHashLoadBalancerProviderTest method parseLoadBalancingConfig_missingRingSize_useDefaults.
@Test
public void parseLoadBalancingConfig_missingRingSize_useDefaults() throws IOException {
String lbConfig = "{}";
ConfigOrError configOrError = provider.parseLoadBalancingPolicyConfig(parseJsonObject(lbConfig));
assertThat(configOrError.getConfig()).isNotNull();
RingHashConfig config = (RingHashConfig) configOrError.getConfig();
assertThat(config.minRingSize).isEqualTo(RingHashLoadBalancerProvider.DEFAULT_MIN_RING_SIZE);
assertThat(config.maxRingSize).isEqualTo(RingHashLoadBalancerProvider.DEFAULT_MAX_RING_SIZE);
}
use of io.grpc.NameResolver.ConfigOrError in project grpc-java by grpc.
the class RingHashLoadBalancerProviderTest method parseLoadBalancingConfig_zeroMinRingSize.
@Test
public void parseLoadBalancingConfig_zeroMinRingSize() throws IOException {
String lbConfig = "{\"minRingSize\" : 0, \"maxRingSize\" : 100}";
ConfigOrError configOrError = provider.parseLoadBalancingPolicyConfig(parseJsonObject(lbConfig));
assertThat(configOrError.getError()).isNotNull();
assertThat(configOrError.getError().getCode()).isEqualTo(Code.INVALID_ARGUMENT);
assertThat(configOrError.getError().getDescription()).isEqualTo("Invalid 'mingRingSize'/'maxRingSize'");
}
Aggregations