Java 类io.grpc.LoadBalancer 实例源码

项目:grpc-java    文件:RoundRobinLoadBalancerTest.java   
@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);
}
项目:grpc-java    文件:GrpclbLoadBalancerFactory.java   
@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);
}
项目:grpc-java    文件:ManagedChannelImpl.java   
@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);
}
项目:grpc-java    文件:AbstractManagedChannelImplBuilderTest.java   
@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);
}
项目:grpc-java    文件:RoundRobinLoadBalancerTest.java   
@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);
}
项目:saluki    文件:GrpcRouteRoundRobinLbFactory.java   
@Override
public LoadBalancer newLoadBalancer(Helper helper) {
  return new GrpcRoundRobinLoadBalancer(helper);
}
项目:saluki    文件:GrpcEngine.java   
private LoadBalancer.Factory buildLoadBalanceFactory() {
  return GrpcRouteRoundRobinLbFactory.getInstance();
}
项目:spring-boot-starter-grpc    文件:GrpcClientAutoConfiguration.java   
@ConditionalOnMissingBean
@Bean
public LoadBalancer.Factory defaultGrpcLoadBalancerFactory() {
    return RoundRobinLoadBalancerFactory.getInstance();
}
项目:grpc-java    文件:GrpclbLoadBalancer.java   
@VisibleForTesting
LoadBalancer getDelegate() {
  return delegate;
}
项目:grpc-java    文件:RoundRobinLoadBalancerFactory.java   
@Override
public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
  return new RoundRobinLoadBalancer(helper);
}
项目:grpc-java    文件:AbstractManagedChannelImplBuilderTest.java   
@Test
public void loadBalancerFactory_normal() {
  LoadBalancer.Factory loadBalancerFactory = mock(LoadBalancer.Factory.class);
  assertEquals(builder, builder.loadBalancerFactory(loadBalancerFactory));
  assertEquals(loadBalancerFactory, builder.loadBalancerFactory);
}
项目:grpc-java    文件:AbstractManagedChannelImplBuilderTest.java   
@Test(expected = IllegalStateException.class)
public void loadBalancerFactory_notAllowedWithDirectAddress() {
  directAddressBuilder.loadBalancerFactory(mock(LoadBalancer.Factory.class));
}
项目:jetcd    文件:ClientBuilder.java   
/**
 * get LoadBalancer.Factory for etcd client.
 *
 * @return loadBalancerFactory
 */
public LoadBalancer.Factory loadBalancerFactory() {
  return loadBalancerFactory;
}