use of io.grpc.LoadBalancer in project grpc-java by grpc.
the class GracefulSwitchLoadBalancerTest method requestConnectionForwardedToLatestPolicies.
@Test
public void requestConnectionForwardedToLatestPolicies() {
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.requestConnection();
verify(lb0).requestConnection();
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[1]));
LoadBalancer lb1 = balancers.get(lbPolicies[1]);
gracefulSwitchLb.requestConnection();
verify(lb1).requestConnection();
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[2]));
verify(lb1).shutdown();
LoadBalancer lb2 = balancers.get(lbPolicies[2]);
gracefulSwitchLb.requestConnection();
verify(lb2).requestConnection();
// lb2 reports READY
helpers.get(lb2).updateBalancingState(READY, mock(SubchannelPicker.class));
verify(lb0).shutdown();
gracefulSwitchLb.requestConnection();
verify(lb2, times(2)).requestConnection();
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[3]));
LoadBalancer lb3 = balancers.get(lbPolicies[3]);
gracefulSwitchLb.requestConnection();
verify(lb3).requestConnection();
verifyNoMoreInteractions(lb0, lb1, lb2, lb3);
}
use of io.grpc.LoadBalancer in project grpc-java by grpc.
the class GracefulSwitchLoadBalancerTest method newPolicyNameTheSameAsCurrentPolicy_shouldShutdownPendingLb.
@Test
public void newPolicyNameTheSameAsCurrentPolicy_shouldShutdownPendingLb() {
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[0]));
LoadBalancer lb0 = balancers.get(lbPolicies[0]);
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[0]));
assertThat(balancers.get(lbPolicies[0])).isSameInstanceAs(lb0);
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[0]));
verify(lb1).shutdown();
assertThat(balancers.get(lbPolicies[0])).isSameInstanceAs(lb0);
verifyNoMoreInteractions(lb0, lb1);
}
Aggregations