use of io.grpc.LoadBalancer in project grpc-java by grpc.
the class WeightedTargetLoadBalancer method shutdown.
@Override
public void shutdown() {
logger.log(XdsLogLevel.INFO, "Shutdown");
for (LoadBalancer childBalancer : childBalancers.values()) {
childBalancer.shutdown();
}
childBalancers.clear();
}
use of io.grpc.LoadBalancer in project grpc-java by grpc.
the class ClusterResolverLoadBalancerProviderTest method providesLoadBalancer.
@Test
public void providesLoadBalancer() {
Helper helper = mock(Helper.class);
SynchronizationContext syncContext = new SynchronizationContext(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
throw new AssertionError(e);
}
});
FakeClock fakeClock = new FakeClock();
NameResolverRegistry nsRegistry = new NameResolverRegistry();
NameResolver.Args args = NameResolver.Args.newBuilder().setDefaultPort(8080).setProxyDetector(GrpcUtil.NOOP_PROXY_DETECTOR).setSynchronizationContext(syncContext).setServiceConfigParser(mock(ServiceConfigParser.class)).setChannelLogger(mock(ChannelLogger.class)).build();
when(helper.getNameResolverRegistry()).thenReturn(nsRegistry);
when(helper.getNameResolverArgs()).thenReturn(args);
when(helper.getSynchronizationContext()).thenReturn(syncContext);
when(helper.getScheduledExecutorService()).thenReturn(fakeClock.getScheduledExecutorService());
when(helper.getAuthority()).thenReturn("api.google.com");
LoadBalancerProvider provider = new ClusterResolverLoadBalancerProvider();
LoadBalancer loadBalancer = provider.newLoadBalancer(helper);
assertThat(loadBalancer).isInstanceOf(ClusterResolverLoadBalancer.class);
}
use of io.grpc.LoadBalancer in project grpc-java by grpc.
the class CdsLoadBalancerProviderTest method providesLoadBalancer.
@Test
public void providesLoadBalancer() {
Helper helper = mock(Helper.class);
SynchronizationContext syncContext = new SynchronizationContext(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
throw new AssertionError(e);
}
});
when(helper.getSynchronizationContext()).thenReturn(syncContext);
LoadBalancerProvider provider = new CdsLoadBalancerProvider();
LoadBalancer loadBalancer = provider.newLoadBalancer(helper);
assertThat(loadBalancer).isInstanceOf(CdsLoadBalancer2.class);
}
use of io.grpc.LoadBalancer in project grpc-java by grpc.
the class AutoConfiguredLoadBalancerFactoryTest method handleResolvedAddressGroups_keepOldBalancer.
@Test
public void handleResolvedAddressGroups_keepOldBalancer() {
final List<EquivalentAddressGroup> servers = Collections.singletonList(new EquivalentAddressGroup(new SocketAddress() {
}));
Helper helper = new TestHelper() {
@Override
public Subchannel createSubchannel(CreateSubchannelArgs args) {
assertThat(args.getAddresses()).isEqualTo(servers);
return new TestSubchannel(args);
}
};
AutoConfiguredLoadBalancer lb = lbf.newLoadBalancer(helper);
LoadBalancer oldDelegate = lb.getDelegate();
Status handleResult = lb.tryHandleResolvedAddresses(ResolvedAddresses.newBuilder().setAddresses(servers).setAttributes(Attributes.EMPTY).setLoadBalancingPolicyConfig(null).build());
assertThat(handleResult.getCode()).isEqualTo(Status.Code.OK);
assertThat(lb.getDelegate()).isSameInstanceAs(oldDelegate);
}
use of io.grpc.LoadBalancer in project grpc-java by grpc.
the class ClusterManagerLoadBalancer method handleResolvedAddresses.
@Override
public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) {
logger.log(XdsLogLevel.DEBUG, "Received resolution result: {0}", resolvedAddresses);
ClusterManagerConfig config = (ClusterManagerConfig) resolvedAddresses.getLoadBalancingPolicyConfig();
Map<String, PolicySelection> newChildPolicies = config.childPolicies;
logger.log(XdsLogLevel.INFO, "Received cluster_manager lb config: child names={0}", newChildPolicies.keySet());
for (Map.Entry<String, PolicySelection> entry : newChildPolicies.entrySet()) {
final String name = entry.getKey();
LoadBalancerProvider childPolicyProvider = entry.getValue().getProvider();
Object childConfig = entry.getValue().getConfig();
if (!childLbStates.containsKey(name)) {
childLbStates.put(name, new ChildLbState(name, childPolicyProvider));
} else {
childLbStates.get(name).reactivate(childPolicyProvider);
}
LoadBalancer childLb = childLbStates.get(name).lb;
ResolvedAddresses childAddresses = resolvedAddresses.toBuilder().setLoadBalancingPolicyConfig(childConfig).build();
childLb.handleResolvedAddresses(childAddresses);
}
for (String name : childLbStates.keySet()) {
if (!newChildPolicies.containsKey(name)) {
childLbStates.get(name).deactivate();
}
}
// Must update channel picker before return so that new RPCs will not be routed to deleted
// clusters and resolver can remove them in service config.
updateOverallBalancingState();
}
Aggregations