Search in sources :

Example 21 with LoadBalancer

use of io.grpc.LoadBalancer 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);
}
Also used : Helper(io.grpc.LoadBalancer.Helper) Attributes(io.grpc.Attributes) LoadBalancer(io.grpc.LoadBalancer) ResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses) Test(org.junit.Test)

Example 22 with LoadBalancer

use of io.grpc.LoadBalancer 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);
}
Also used : Helper(io.grpc.LoadBalancer.Helper) SubchannelPicker(io.grpc.LoadBalancer.SubchannelPicker) LoadBalancer(io.grpc.LoadBalancer) Test(org.junit.Test)

Example 23 with LoadBalancer

use of io.grpc.LoadBalancer 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);
}
Also used : Helper(io.grpc.LoadBalancer.Helper) SubchannelPicker(io.grpc.LoadBalancer.SubchannelPicker) LoadBalancer(io.grpc.LoadBalancer) Test(org.junit.Test)

Example 24 with LoadBalancer

use of io.grpc.LoadBalancer in project grpc-java by grpc.

the class GracefulSwitchLoadBalancerTest method switchWhileOldPolicyIsNotReady.

@Test
public void switchWhileOldPolicyIsNotReady() {
    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);
    picker = mock(SubchannelPicker.class);
    helper0.updateBalancingState(CONNECTING, picker);
    verify(lb0, never()).shutdown();
    gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[1]));
    verify(lb0).shutdown();
    LoadBalancer lb1 = balancers.get(lbPolicies[1]);
    Helper helper1 = helpers.get(lb1);
    picker = mock(SubchannelPicker.class);
    helper1.updateBalancingState(CONNECTING, picker);
    verify(mockHelper).updateBalancingState(CONNECTING, picker);
    verify(lb1, never()).shutdown();
    gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[2]));
    verify(lb1).shutdown();
    LoadBalancer lb2 = balancers.get(lbPolicies[2]);
    verifyNoMoreInteractions(lb0, lb1, lb2);
}
Also used : Helper(io.grpc.LoadBalancer.Helper) SubchannelPicker(io.grpc.LoadBalancer.SubchannelPicker) LoadBalancer(io.grpc.LoadBalancer) Test(org.junit.Test)

Example 25 with LoadBalancer

use of io.grpc.LoadBalancer in project grpc-java by grpc.

the class GracefulSwitchLoadBalancerTest method handleResolvedAddressesAndNameResolutionErrorForwardedToLatestPolicy.

@Test
public void handleResolvedAddressesAndNameResolutionErrorForwardedToLatestPolicy() {
    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);
    ResolvedAddresses addresses = newFakeAddresses();
    gracefulSwitchLb.handleResolvedAddresses(addresses);
    verify(lb0).handleResolvedAddresses(addresses);
    gracefulSwitchLb.handleNameResolutionError(Status.DATA_LOSS);
    verify(lb0).handleNameResolutionError(Status.DATA_LOSS);
    gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[1]));
    LoadBalancer lb1 = balancers.get(lbPolicies[1]);
    addresses = newFakeAddresses();
    gracefulSwitchLb.handleResolvedAddresses(addresses);
    verify(lb0, never()).handleResolvedAddresses(addresses);
    verify(lb1).handleResolvedAddresses(addresses);
    gracefulSwitchLb.handleNameResolutionError(Status.ALREADY_EXISTS);
    verify(lb0, never()).handleNameResolutionError(Status.ALREADY_EXISTS);
    verify(lb1).handleNameResolutionError(Status.ALREADY_EXISTS);
    gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[2]));
    verify(lb1).shutdown();
    LoadBalancer lb2 = balancers.get(lbPolicies[2]);
    addresses = newFakeAddresses();
    gracefulSwitchLb.handleResolvedAddresses(addresses);
    verify(lb0, never()).handleResolvedAddresses(addresses);
    verify(lb1, never()).handleResolvedAddresses(addresses);
    verify(lb2).handleResolvedAddresses(addresses);
    gracefulSwitchLb.handleNameResolutionError(Status.CANCELLED);
    verify(lb0, never()).handleNameResolutionError(Status.CANCELLED);
    verify(lb1, never()).handleNameResolutionError(Status.CANCELLED);
    verify(lb2).handleNameResolutionError(Status.CANCELLED);
    verifyNoMoreInteractions(lb0, lb1, lb2);
}
Also used : Helper(io.grpc.LoadBalancer.Helper) SubchannelPicker(io.grpc.LoadBalancer.SubchannelPicker) LoadBalancer(io.grpc.LoadBalancer) ResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses) Test(org.junit.Test)

Aggregations

LoadBalancer (io.grpc.LoadBalancer)27 Test (org.junit.Test)22 Helper (io.grpc.LoadBalancer.Helper)20 SubchannelPicker (io.grpc.LoadBalancer.SubchannelPicker)13 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)7 PolicySelection (io.grpc.internal.ServiceConfigUtil.PolicySelection)5 ResolvedAddresses (io.grpc.LoadBalancer.ResolvedAddresses)4 LoadBalancerProvider (io.grpc.LoadBalancerProvider)4 Status (io.grpc.Status)4 PriorityLbConfig (io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig)4 PriorityChildConfig (io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig.PriorityChildConfig)4 Attributes (io.grpc.Attributes)2 CreateSubchannelArgs (io.grpc.LoadBalancer.CreateSubchannelArgs)2 PickResult (io.grpc.LoadBalancer.PickResult)2 PickSubchannelArgs (io.grpc.LoadBalancer.PickSubchannelArgs)2 SynchronizationContext (io.grpc.SynchronizationContext)2 GracefulSwitchLoadBalancer (io.grpc.util.GracefulSwitchLoadBalancer)2 ErrorPicker (io.grpc.xds.XdsSubchannelPickers.ErrorPicker)2 InetSocketAddress (java.net.InetSocketAddress)2 SocketAddress (java.net.SocketAddress)2