Search in sources :

Example 51 with Helper

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());
}
Also used : ForwardingLoadBalancerHelper(io.grpc.util.ForwardingLoadBalancerHelper) Helper(io.grpc.LoadBalancer.Helper) AutoConfiguredLoadBalancer(io.grpc.internal.AutoConfiguredLoadBalancerFactory.AutoConfiguredLoadBalancer) Status(io.grpc.Status) EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) ConfigOrError(io.grpc.NameResolver.ConfigOrError) ResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses) Test(org.junit.Test)

Example 52 with Helper

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());
}
Also used : Helper(io.grpc.LoadBalancer.Helper) ChildPolicyReportingHelper(io.grpc.rls.LbPolicyConfiguration.ChildPolicyWrapper.ChildPolicyReportingHelper) SynchronizationContext(io.grpc.SynchronizationContext) LoadBalancer(io.grpc.LoadBalancer) ChannelLogger(io.grpc.ChannelLogger) UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) Before(org.junit.Before)

Example 53 with Helper

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);
}
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 54 with Helper

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

Example 55 with Helper

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

Aggregations

Helper (io.grpc.LoadBalancer.Helper)59 Test (org.junit.Test)57 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)28 SubchannelPicker (io.grpc.LoadBalancer.SubchannelPicker)21 LoadBalancer (io.grpc.LoadBalancer)20 MockClientTransportInfo (io.grpc.internal.TestUtils.MockClientTransportInfo)20 Subchannel (io.grpc.LoadBalancer.Subchannel)18 Metadata (io.grpc.Metadata)16 Status (io.grpc.Status)14 PickSubchannelArgs (io.grpc.LoadBalancer.PickSubchannelArgs)13 SocketAddress (java.net.SocketAddress)13 ForwardingSubchannel (io.grpc.util.ForwardingSubchannel)12 UnsupportedClientTransportFactoryBuilder (io.grpc.internal.ManagedChannelImplBuilder.UnsupportedClientTransportFactoryBuilder)10 ConfigOrError (io.grpc.NameResolver.ConfigOrError)9 AutoConfiguredLoadBalancer (io.grpc.internal.AutoConfiguredLoadBalancerFactory.AutoConfiguredLoadBalancer)9 ClientTransportFactoryBuilder (io.grpc.internal.ManagedChannelImplBuilder.ClientTransportFactoryBuilder)9 PolicySelection (io.grpc.internal.ServiceConfigUtil.PolicySelection)9 ForwardingLoadBalancerHelper (io.grpc.util.ForwardingLoadBalancerHelper)9 ClientStreamTracer (io.grpc.ClientStreamTracer)7 ManagedChannel (io.grpc.ManagedChannel)7