use of io.grpc.LoadBalancer.Helper in project grpc-java by grpc.
the class AutoConfiguredLoadBalancerFactoryTest method handleResolvedAddressGroups_delegateAcceptsEmptyAddressList.
@Test
public void handleResolvedAddressGroups_delegateAcceptsEmptyAddressList() throws Exception {
Helper helper = new TestHelper();
AutoConfiguredLoadBalancer lb = lbf.newLoadBalancer(helper);
Map<String, ?> rawServiceConfig = parseConfig("{\"loadBalancingConfig\": [ {\"test_lb2\": { \"setting1\": \"high\" } } ] }");
ConfigOrError lbConfigs = lbf.parseLoadBalancerPolicy(rawServiceConfig);
Status handleResult = lb.tryHandleResolvedAddresses(ResolvedAddresses.newBuilder().setAddresses(Collections.<EquivalentAddressGroup>emptyList()).setLoadBalancingPolicyConfig(lbConfigs.getConfig()).build());
assertThat(handleResult.getCode()).isEqualTo(Status.Code.OK);
assertThat(lb.getDelegate()).isSameInstanceAs(testLbBalancer2);
assertThat(testLbBalancer2.canHandleEmptyAddressListFromNameResolution()).isTrue();
ArgumentCaptor<ResolvedAddresses> resultCaptor = ArgumentCaptor.forClass(ResolvedAddresses.class);
verify(testLbBalancer2).handleResolvedAddresses(resultCaptor.capture());
assertThat(resultCaptor.getValue().getAddresses()).isEmpty();
assertThat(resultCaptor.getValue().getLoadBalancingPolicyConfig()).isEqualTo(nextParsedConfigOrError2.get().getConfig());
}
use of io.grpc.LoadBalancer.Helper in project grpc-java by grpc.
the class LbPolicyConfigurationTest method setUp.
@Before
public void setUp() {
doReturn(mock(ChannelLogger.class)).when(helper).getChannelLogger();
doReturn(new SynchronizationContext(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
throw new AssertionError(e);
}
})).when(helper).getSynchronizationContext();
doReturn(mock(LoadBalancer.class)).when(lbProvider).newLoadBalancer(any(Helper.class));
doReturn(ConfigOrError.fromConfig(new Object())).when(lbProvider).parseLoadBalancingPolicyConfig(ArgumentMatchers.<Map<String, ?>>any());
}
use of io.grpc.LoadBalancer.Helper in project grpc-java by grpc.
the class HealthCheckingLoadBalancerFactoryTest method util_newHealthCheckingLoadBalancer.
@Test
public void util_newHealthCheckingLoadBalancer() {
LoadBalancer.Factory hcFactory = new LoadBalancer.Factory() {
@Override
public LoadBalancer newLoadBalancer(Helper helper) {
return HealthCheckingLoadBalancerUtil.newHealthCheckingLoadBalancer(origLbFactory, helper);
}
};
// hcLb and wrappedHelper are already set in setUp(). For this special test case, we
// clear wrappedHelper so that we can create hcLb again with the util.
wrappedHelper = null;
hcLb = hcFactory.newLoadBalancer(origHelper);
// Verify that HC works
Attributes resolutionAttrs = attrsWithHealthCheckService("BarService");
ResolvedAddresses result = ResolvedAddresses.newBuilder().setAddresses(resolvedAddressList).setAttributes(resolutionAttrs).build();
hcLbEventDelivery.handleResolvedAddresses(result);
verify(origLb).handleResolvedAddresses(result);
createSubchannel(0, Attributes.EMPTY);
assertThat(healthImpls[0].calls).isEmpty();
deliverSubchannelState(0, ConnectivityStateInfo.forNonError(READY));
assertThat(healthImpls[0].calls).hasSize(1);
}
use of io.grpc.LoadBalancer.Helper in project grpc-java by grpc.
the class GracefulSwitchLoadBalancerTest method newPolicyNameTheSameAsPendingPolicy_shouldHaveNoEffect.
@Test
public void newPolicyNameTheSameAsPendingPolicy_shouldHaveNoEffect() {
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[0]));
LoadBalancer lb0 = balancers.get(lbPolicies[0]);
Helper helper0 = helpers.get(lb0);
SubchannelPicker picker = mock(SubchannelPicker.class);
helper0.updateBalancingState(READY, picker);
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[1]));
LoadBalancer lb1 = balancers.get(lbPolicies[1]);
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[1]));
assertThat(balancers.get(lbPolicies[1])).isSameInstanceAs(lb1);
verifyNoMoreInteractions(lb0, lb1);
}
use of io.grpc.LoadBalancer.Helper in project grpc-java by grpc.
the class GracefulSwitchLoadBalancerTest method switchWhileOldPolicyGoesFromReadyToNotReady.
@Test
public void switchWhileOldPolicyGoesFromReadyToNotReady() {
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[0]));
LoadBalancer lb0 = balancers.get(lbPolicies[0]);
Helper helper0 = helpers.get(lb0);
SubchannelPicker picker = mock(SubchannelPicker.class);
helper0.updateBalancingState(READY, picker);
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[1]));
verify(lb0, never()).shutdown();
LoadBalancer lb1 = balancers.get(lbPolicies[1]);
Helper helper1 = helpers.get(lb1);
SubchannelPicker picker1 = mock(SubchannelPicker.class);
helper1.updateBalancingState(CONNECTING, picker1);
verify(mockHelper, never()).updateBalancingState(CONNECTING, picker1);
picker = mock(SubchannelPicker.class);
helper0.updateBalancingState(CONNECTING, picker);
verify(lb0).shutdown();
verify(mockHelper, never()).updateBalancingState(CONNECTING, picker);
verify(mockHelper).updateBalancingState(CONNECTING, picker1);
picker1 = mock(SubchannelPicker.class);
helper1.updateBalancingState(READY, picker1);
verify(mockHelper).updateBalancingState(READY, picker1);
verifyNoMoreInteractions(lb0, lb1);
}
Aggregations