use of io.grpc.LoadBalancer in project grpc-java by grpc.
the class GracefulSwitchLoadBalancerTest method createSubchannelForwarded.
@Test
public void createSubchannelForwarded() {
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);
CreateSubchannelArgs createSubchannelArgs = newFakeCreateSubchannelArgs();
helper0.createSubchannel(createSubchannelArgs);
verify(mockHelper).createSubchannel(createSubchannelArgs);
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[1]));
LoadBalancer lb1 = balancers.get(lbPolicies[1]);
Helper helper1 = helpers.get(lb1);
createSubchannelArgs = newFakeCreateSubchannelArgs();
helper1.createSubchannel(createSubchannelArgs);
verify(mockHelper).createSubchannel(createSubchannelArgs);
createSubchannelArgs = newFakeCreateSubchannelArgs();
helper0.createSubchannel(createSubchannelArgs);
verify(mockHelper).createSubchannel(createSubchannelArgs);
verifyNoMoreInteractions(lb0, lb1);
}
use of io.grpc.LoadBalancer in project grpc-java by grpc.
the class GracefulSwitchLoadBalancerTest method shutdownTriggeredWhenSwitchAndForwardedWhenSwitchLbShutdown.
@Test
public void shutdownTriggeredWhenSwitchAndForwardedWhenSwitchLbShutdown() {
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]);
verify(lb1, never()).shutdown();
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[2]));
verify(lb1).shutdown();
LoadBalancer lb2 = balancers.get(lbPolicies[2]);
verify(lb0, never()).shutdown();
helpers.get(lb2).updateBalancingState(READY, mock(SubchannelPicker.class));
verify(lb0).shutdown();
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[3]));
LoadBalancer lb3 = balancers.get(lbPolicies[3]);
verify(lb2, never()).shutdown();
verify(lb3, never()).shutdown();
gracefulSwitchLb.shutdown();
verify(lb2).shutdown();
verify(lb3).shutdown();
verifyNoMoreInteractions(lb0, lb1, lb2, lb3);
}
use of io.grpc.LoadBalancer in project grpc-java by grpc.
the class GracefulSwitchLoadBalancerTest method newLbFactoryEqualToOldOneShouldHaveNoEffect.
@Test
public void newLbFactoryEqualToOldOneShouldHaveNoEffect() {
final List<LoadBalancer> balancers = new ArrayList<>();
final class LoadBalancerFactoryWithId extends LoadBalancer.Factory {
final int id;
LoadBalancerFactoryWithId(int id) {
this.id = id;
}
@Override
public LoadBalancer newLoadBalancer(Helper helper) {
LoadBalancer balancer = mock(LoadBalancer.class);
balancers.add(balancer);
return balancer;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof LoadBalancerFactoryWithId)) {
return false;
}
LoadBalancerFactoryWithId that = (LoadBalancerFactoryWithId) o;
return id == that.id;
}
@Override
public int hashCode() {
return id;
}
}
gracefulSwitchLb.switchTo(new LoadBalancerFactoryWithId(0));
assertThat(balancers).hasSize(1);
LoadBalancer lb0 = balancers.get(0);
gracefulSwitchLb.switchTo(new LoadBalancerFactoryWithId(0));
assertThat(balancers).hasSize(1);
gracefulSwitchLb.switchTo(new LoadBalancerFactoryWithId(1));
assertThat(balancers).hasSize(2);
LoadBalancer lb1 = balancers.get(1);
verify(lb0).shutdown();
verifyNoMoreInteractions(lb0, lb1);
}
use of io.grpc.LoadBalancer in project grpc-java by grpc.
the class GracefulSwitchLoadBalancerTest method canHandleEmptyAddressListFromNameResolutionForwardedToLatestPolicy.
@Test
public void canHandleEmptyAddressListFromNameResolutionForwardedToLatestPolicy() {
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);
assertThat(gracefulSwitchLb.canHandleEmptyAddressListFromNameResolution()).isFalse();
doReturn(true).when(lb0).canHandleEmptyAddressListFromNameResolution();
assertThat(gracefulSwitchLb.canHandleEmptyAddressListFromNameResolution()).isTrue();
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[1]));
LoadBalancer lb1 = balancers.get(lbPolicies[1]);
assertThat(gracefulSwitchLb.canHandleEmptyAddressListFromNameResolution()).isFalse();
doReturn(true).when(lb1).canHandleEmptyAddressListFromNameResolution();
assertThat(gracefulSwitchLb.canHandleEmptyAddressListFromNameResolution()).isTrue();
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[2]));
LoadBalancer lb2 = balancers.get(lbPolicies[2]);
assertThat(gracefulSwitchLb.canHandleEmptyAddressListFromNameResolution()).isFalse();
doReturn(true).when(lb2).canHandleEmptyAddressListFromNameResolution();
assertThat(gracefulSwitchLb.canHandleEmptyAddressListFromNameResolution()).isTrue();
}
use of io.grpc.LoadBalancer in project grpc-java by grpc.
the class GracefulSwitchLoadBalancerTest method updateBalancingStateIsGraceful.
@Test
public void updateBalancingStateIsGraceful() {
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);
verify(mockHelper).updateBalancingState(READY, picker);
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[1]));
LoadBalancer lb1 = balancers.get(lbPolicies[1]);
Helper helper1 = helpers.get(lb1);
picker = mock(SubchannelPicker.class);
helper1.updateBalancingState(CONNECTING, picker);
verify(mockHelper, never()).updateBalancingState(CONNECTING, picker);
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[2]));
verify(lb1).shutdown();
LoadBalancer lb2 = balancers.get(lbPolicies[2]);
Helper helper2 = helpers.get(lb2);
picker = mock(SubchannelPicker.class);
helper2.updateBalancingState(CONNECTING, picker);
verify(mockHelper, never()).updateBalancingState(CONNECTING, picker);
// lb2 reports READY
SubchannelPicker picker2 = mock(SubchannelPicker.class);
helper2.updateBalancingState(READY, picker2);
verify(lb0).shutdown();
verify(mockHelper).updateBalancingState(READY, picker2);
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[3]));
LoadBalancer lb3 = balancers.get(lbPolicies[3]);
Helper helper3 = helpers.get(lb3);
SubchannelPicker picker3 = mock(SubchannelPicker.class);
helper3.updateBalancingState(CONNECTING, picker3);
verify(mockHelper, never()).updateBalancingState(CONNECTING, picker3);
// lb2 out of READY
picker2 = mock(SubchannelPicker.class);
helper2.updateBalancingState(CONNECTING, picker2);
verify(mockHelper, never()).updateBalancingState(CONNECTING, picker2);
verify(mockHelper).updateBalancingState(CONNECTING, picker3);
verify(lb2).shutdown();
picker3 = mock(SubchannelPicker.class);
helper3.updateBalancingState(CONNECTING, picker3);
verify(mockHelper).updateBalancingState(CONNECTING, picker3);
verifyNoMoreInteractions(lb0, lb1, lb2, lb3);
}
Aggregations