use of io.grpc.internal.AutoConfiguredLoadBalancerFactory.AutoConfiguredLoadBalancer in project grpc-java by grpc.
the class AutoConfiguredLoadBalancerFactoryTest method defaultIsPickFirst.
@Test
public void defaultIsPickFirst() {
AutoConfiguredLoadBalancer lb = lbf.newLoadBalancer(new TestHelper());
assertThat(lb.getDelegateProvider()).isInstanceOf(PickFirstLoadBalancerProvider.class);
assertThat(lb.getDelegate().getClass().getName()).contains("PickFirst");
}
use of io.grpc.internal.AutoConfiguredLoadBalancerFactory.AutoConfiguredLoadBalancer in project grpc-java by grpc.
the class AutoConfiguredLoadBalancerFactoryTest method handleResolvedAddressGroups_noLbPolicySelected_defaultToPickFirst.
@Test
public void handleResolvedAddressGroups_noLbPolicySelected_defaultToPickFirst() {
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);
Status handleResult = lb.tryHandleResolvedAddresses(ResolvedAddresses.newBuilder().setAddresses(servers).setLoadBalancingPolicyConfig(null).build());
assertThat(handleResult.getCode()).isEqualTo(Status.Code.OK);
assertThat(lb.getDelegate()).isInstanceOf(PickFirstLoadBalancer.class);
}
use of io.grpc.internal.AutoConfiguredLoadBalancerFactory.AutoConfiguredLoadBalancer in project grpc-java by grpc.
the class AutoConfiguredLoadBalancerFactoryTest method handleResolvedAddressGroups_noLbPolicySelected_defaultToCustomDefault.
@Test
public void handleResolvedAddressGroups_noLbPolicySelected_defaultToCustomDefault() {
AutoConfiguredLoadBalancer lb = new AutoConfiguredLoadBalancerFactory("test_lb").newLoadBalancer(new TestHelper());
List<EquivalentAddressGroup> servers = Collections.singletonList(new EquivalentAddressGroup(new SocketAddress() {
}));
Status handleResult = lb.tryHandleResolvedAddresses(ResolvedAddresses.newBuilder().setAddresses(servers).setLoadBalancingPolicyConfig(null).build());
assertThat(handleResult.getCode()).isEqualTo(Status.Code.OK);
assertThat(lb.getDelegate()).isSameInstanceAs(testLbBalancer);
}
use of io.grpc.internal.AutoConfiguredLoadBalancerFactory.AutoConfiguredLoadBalancer in project grpc-java by grpc.
the class AutoConfiguredLoadBalancerFactoryTest method handleResolvedAddressGroups_propagateLbConfigToDelegate.
@Test
@SuppressWarnings("unchecked")
public void handleResolvedAddressGroups_propagateLbConfigToDelegate() throws Exception {
Map<String, ?> rawServiceConfig = parseConfig("{\"loadBalancingConfig\": [ {\"test_lb\": { \"setting1\": \"high\" } } ] }");
ConfigOrError lbConfigs = lbf.parseLoadBalancerPolicy(rawServiceConfig);
assertThat(lbConfigs.getConfig()).isNotNull();
final List<EquivalentAddressGroup> servers = Collections.singletonList(new EquivalentAddressGroup(new SocketAddress() {
}));
Helper helper = new TestHelper();
AutoConfiguredLoadBalancer lb = lbf.newLoadBalancer(helper);
Status handleResult = lb.tryHandleResolvedAddresses(ResolvedAddresses.newBuilder().setAddresses(servers).setLoadBalancingPolicyConfig(lbConfigs.getConfig()).build());
verify(testLbBalancerProvider).newLoadBalancer(same(helper));
assertThat(handleResult.getCode()).isEqualTo(Status.Code.OK);
assertThat(lb.getDelegate()).isSameInstanceAs(testLbBalancer);
ArgumentCaptor<ResolvedAddresses> resultCaptor = ArgumentCaptor.forClass(ResolvedAddresses.class);
verify(testLbBalancer).handleResolvedAddresses(resultCaptor.capture());
assertThat(resultCaptor.getValue().getAddresses()).containsExactlyElementsIn(servers).inOrder();
verify(testLbBalancer, atLeast(0)).canHandleEmptyAddressListFromNameResolution();
ArgumentCaptor<Map<String, ?>> lbConfigCaptor = ArgumentCaptor.forClass(Map.class);
verify(testLbBalancerProvider).parseLoadBalancingPolicyConfig(lbConfigCaptor.capture());
assertThat(lbConfigCaptor.getValue()).containsExactly("setting1", "high");
verifyNoMoreInteractions(testLbBalancer);
rawServiceConfig = parseConfig("{\"loadBalancingConfig\": [ {\"test_lb\": { \"setting1\": \"low\" } } ] }");
lbConfigs = lbf.parseLoadBalancerPolicy(rawServiceConfig);
handleResult = lb.tryHandleResolvedAddresses(ResolvedAddresses.newBuilder().setAddresses(servers).setLoadBalancingPolicyConfig(lbConfigs.getConfig()).build());
resultCaptor = ArgumentCaptor.forClass(ResolvedAddresses.class);
verify(testLbBalancer, times(2)).handleResolvedAddresses(resultCaptor.capture());
assertThat(handleResult.getCode()).isEqualTo(Status.Code.OK);
assertThat(resultCaptor.getValue().getAddresses()).containsExactlyElementsIn(servers).inOrder();
verify(testLbBalancerProvider, times(2)).parseLoadBalancingPolicyConfig(lbConfigCaptor.capture());
assertThat(lbConfigCaptor.getValue()).containsExactly("setting1", "low");
// Service config didn't change policy, thus the delegateLb is not swapped
verifyNoMoreInteractions(testLbBalancer);
verify(testLbBalancerProvider).newLoadBalancer(any(Helper.class));
}
use of io.grpc.internal.AutoConfiguredLoadBalancerFactory.AutoConfiguredLoadBalancer in project grpc-java by grpc.
the class AutoConfiguredLoadBalancerFactoryTest method newLoadBalancer_isAuto.
@Test
public void newLoadBalancer_isAuto() {
AutoConfiguredLoadBalancer lb = lbf.newLoadBalancer(new TestHelper());
assertThat(lb).isInstanceOf(AutoConfiguredLoadBalancer.class);
}
Aggregations