@Test public void nameResolutionErrorWithActiveChannels() throws Exception { final Subchannel readySubchannel = subchannels.values().iterator().next(); loadBalancer.handleResolvedAddressGroups(servers, affinity); loadBalancer.handleSubchannelState(readySubchannel, ConnectivityStateInfo.forNonError(READY)); loadBalancer.handleNameResolutionError(Status.NOT_FOUND.withDescription("nameResolutionError")); verify(mockHelper, times(3)).createSubchannel(any(EquivalentAddressGroup.class), any(Attributes.class)); verify(mockHelper, times(3)) .updateBalancingState(stateCaptor.capture(), pickerCaptor.capture()); Iterator<ConnectivityState> stateIterator = stateCaptor.getAllValues().iterator(); assertEquals(CONNECTING, stateIterator.next()); assertEquals(READY, stateIterator.next()); assertEquals(TRANSIENT_FAILURE, stateIterator.next()); LoadBalancer.PickResult pickResult = pickerCaptor.getValue().pickSubchannel(mockArgs); assertEquals(readySubchannel, pickResult.getSubchannel()); assertEquals(Status.OK.getCode(), pickResult.getStatus().getCode()); LoadBalancer.PickResult pickResult2 = pickerCaptor.getValue().pickSubchannel(mockArgs); assertEquals(readySubchannel, pickResult2.getSubchannel()); verifyNoMoreInteractions(mockHelper); }
@Override public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) { return new GrpclbLoadBalancer( helper, PickFirstBalancerFactory.getInstance(), RoundRobinLoadBalancerFactory.getInstance(), // TODO(zhangkun83): balancer sends load reporting RPCs from it, which also involves // channelExecutor thus may also run other tasks queued in the channelExecutor. If such // load should not be on the shared scheduled executor, we should use a combination of the // scheduled executor and the default app executor. SharedResourcePool.forResource(GrpcUtil.TIMER_SERVICE), TIME_PROVIDER); }
@Override public void updateSubchannelAddresses( LoadBalancer.Subchannel subchannel, EquivalentAddressGroup addrs) { checkArgument(subchannel instanceof SubchannelImpl, "subchannel must have been returned from createSubchannel"); ((SubchannelImpl) subchannel).subchannel.updateAddresses(addrs); }
@Test public void loadBalancerFactory_null() { LoadBalancer.Factory defaultValue = builder.loadBalancerFactory; builder.loadBalancerFactory(mock(LoadBalancer.Factory.class)); assertEquals(builder, builder.loadBalancerFactory(null)); assertEquals(defaultValue, builder.loadBalancerFactory); }
@Test public void nameResolutionErrorWithNoChannels() throws Exception { Status error = Status.NOT_FOUND.withDescription("nameResolutionError"); loadBalancer.handleNameResolutionError(error); verify(mockHelper).updateBalancingState(eq(TRANSIENT_FAILURE), pickerCaptor.capture()); LoadBalancer.PickResult pickResult = pickerCaptor.getValue().pickSubchannel(mockArgs); assertNull(pickResult.getSubchannel()); assertEquals(error, pickResult.getStatus()); verifyNoMoreInteractions(mockHelper); }
@Override public LoadBalancer newLoadBalancer(Helper helper) { return new GrpcRoundRobinLoadBalancer(helper); }
private LoadBalancer.Factory buildLoadBalanceFactory() { return GrpcRouteRoundRobinLbFactory.getInstance(); }
@ConditionalOnMissingBean @Bean public LoadBalancer.Factory defaultGrpcLoadBalancerFactory() { return RoundRobinLoadBalancerFactory.getInstance(); }
@VisibleForTesting LoadBalancer getDelegate() { return delegate; }
@Override public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) { return new RoundRobinLoadBalancer(helper); }
@Test public void loadBalancerFactory_normal() { LoadBalancer.Factory loadBalancerFactory = mock(LoadBalancer.Factory.class); assertEquals(builder, builder.loadBalancerFactory(loadBalancerFactory)); assertEquals(loadBalancerFactory, builder.loadBalancerFactory); }
@Test(expected = IllegalStateException.class) public void loadBalancerFactory_notAllowedWithDirectAddress() { directAddressBuilder.loadBalancerFactory(mock(LoadBalancer.Factory.class)); }
/** * get LoadBalancer.Factory for etcd client. * * @return loadBalancerFactory */ public LoadBalancer.Factory loadBalancerFactory() { return loadBalancerFactory; }