use of io.grpc.LoadBalancer in project grpc-java by grpc.
the class PriorityLoadBalancerTest method tearDown.
@After
public void tearDown() {
priorityLb.shutdown();
for (LoadBalancer lb : fooBalancers) {
verify(lb).shutdown();
}
for (LoadBalancer lb : barBalancers) {
verify(lb).shutdown();
}
assertThat(fakeClock.getPendingTasks()).isEmpty();
}
use of io.grpc.LoadBalancer in project grpc-java by grpc.
the class ClusterImplLoadBalancerProviderTest method providesLoadBalancer.
@Test
public void providesLoadBalancer() {
Helper helper = mock(Helper.class);
when(helper.getAuthority()).thenReturn("api.google.com");
LoadBalancerProvider provider = new ClusterImplLoadBalancerProvider();
LoadBalancer loadBalancer = provider.newLoadBalancer(helper);
assertThat(loadBalancer).isInstanceOf(ClusterImplLoadBalancer.class);
}
use of io.grpc.LoadBalancer in project grpc-java by grpc.
the class HealthCheckingLoadBalancerFactoryTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
for (int i = 0; i < NUM_SUBCHANNELS; i++) {
HealthImpl healthImpl = new HealthImpl();
healthImpls[i] = healthImpl;
Server server = InProcessServerBuilder.forName("health-check-test-" + i).addService(healthImpl).directExecutor().build().start();
servers[i] = server;
ManagedChannel channel = InProcessChannelBuilder.forName("health-check-test-" + i).directExecutor().build();
channels[i] = channel;
EquivalentAddressGroup eag = new EquivalentAddressGroup(new FakeSocketAddress("address-" + i));
eags[i] = eag;
List<EquivalentAddressGroup> eagList = Arrays.asList(eag);
eagLists[i] = eagList;
mockStateListeners[i] = mock(SubchannelStateListener.class);
}
resolvedAddressList = Arrays.asList(eags);
when(backoffPolicyProvider.get()).thenReturn(backoffPolicy1, backoffPolicy2);
when(backoffPolicy1.nextBackoffNanos()).thenReturn(11L, 21L, 31L);
when(backoffPolicy2.nextBackoffNanos()).thenReturn(12L, 22L, 32L);
hcLbFactory = new HealthCheckingLoadBalancerFactory(origLbFactory, backoffPolicyProvider, clock.getStopwatchSupplier());
hcLb = hcLbFactory.newLoadBalancer(origHelper);
// Make sure all calls into the hcLb is from the syncContext
hcLbEventDelivery = new LoadBalancer() {
// Per LoadBalancer API, no more callbacks will be called after shutdown() is called.
boolean shutdown;
@Override
public void handleResolvedAddresses(final ResolvedAddresses resolvedAddresses) {
syncContext.execute(new Runnable() {
@Override
public void run() {
if (!shutdown) {
hcLb.handleResolvedAddresses(resolvedAddresses);
}
}
});
}
@Override
public void handleNameResolutionError(Status error) {
throw new AssertionError("Not supposed to be called");
}
@Override
public void shutdown() {
syncContext.execute(new Runnable() {
@Override
public void run() {
if (!shutdown) {
shutdown = true;
hcLb.shutdown();
}
}
});
}
};
verify(origLbFactory).newLoadBalancer(any(Helper.class));
}
use of io.grpc.LoadBalancer in project grpc-java by grpc.
the class HealthCheckingLoadBalancerFactory method newLoadBalancer.
@Override
public LoadBalancer newLoadBalancer(Helper helper) {
HelperImpl wrappedHelper = new HelperImpl(helper);
LoadBalancer delegateBalancer = delegateFactory.newLoadBalancer(wrappedHelper);
return new HealthCheckingLoadBalancer(wrappedHelper, delegateBalancer);
}
use of io.grpc.LoadBalancer in project grpc-java by grpc.
the class WeightedTargetLoadBalancerTest method handleNameResolutionError.
@Test
public void handleNameResolutionError() {
ArgumentCaptor<SubchannelPicker> pickerCaptor = ArgumentCaptor.forClass(null);
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(null);
// Error before any child balancer created.
weightedTargetLb.handleNameResolutionError(Status.DATA_LOSS);
verify(helper).updateBalancingState(eq(TRANSIENT_FAILURE), pickerCaptor.capture());
PickResult pickResult = pickerCaptor.getValue().pickSubchannel(mock(PickSubchannelArgs.class));
assertThat(pickResult.getStatus().getCode()).isEqualTo(Status.Code.DATA_LOSS);
// Child configs updated.
Map<String, WeightedPolicySelection> targets = ImmutableMap.of(// {foo, 10, config0}
"target0", weightedLbConfig0, // {bar, 20, config1}
"target1", weightedLbConfig1, // {bar, 30, config2}
"target2", weightedLbConfig2, // {foo, 40, config3}
"target3", weightedLbConfig3);
weightedTargetLb.handleResolvedAddresses(ResolvedAddresses.newBuilder().setAddresses(ImmutableList.<EquivalentAddressGroup>of()).setLoadBalancingPolicyConfig(new WeightedTargetConfig(targets)).build());
verify(helper).updateBalancingState(eq(CONNECTING), eq(BUFFER_PICKER));
// Error after child balancers created.
weightedTargetLb.handleNameResolutionError(Status.ABORTED);
for (LoadBalancer childBalancer : childBalancers) {
verify(childBalancer).handleNameResolutionError(statusCaptor.capture());
assertThat(statusCaptor.getValue().getCode()).isEqualTo(Status.Code.ABORTED);
}
}
Aggregations