use of io.grpc.grpclb.GrpclbLoadBalancer.ErrorPicker in project grpc-java by grpc.
the class GrpclbLoadBalancerTest method nameResolutionFailsThenRecoverToDelegate.
@Test
public void nameResolutionFailsThenRecoverToDelegate() {
Status error = Status.NOT_FOUND.withDescription("www.google.com not found");
deliverNameResolutionError(error);
verify(helper).updatePicker(pickerCaptor.capture());
ErrorPicker errorPicker = (ErrorPicker) pickerCaptor.getValue();
assertSame(error, errorPicker.result.getStatus());
// Recover with a subsequent success
List<ResolvedServerInfoGroup> resolvedServers = createResolvedServerInfoGroupList(false);
Attributes resolutionAttrs = Attributes.newBuilder().set(RESOLUTION_ATTR, "yeah").build();
deliverResolvedAddresses(resolvedServers, resolutionAttrs);
verify(pickFirstBalancerFactory).newLoadBalancer(helper);
verify(pickFirstBalancer).handleResolvedAddresses(eq(resolvedServers), eq(resolutionAttrs));
verifyNoMoreInteractions(roundRobinBalancerFactory);
verifyNoMoreInteractions(roundRobinBalancer);
}
use of io.grpc.grpclb.GrpclbLoadBalancer.ErrorPicker in project grpc-java by grpc.
the class GrpclbLoadBalancerTest method nameResolutionFailsThenRecoverToGrpclb.
@Test
public void nameResolutionFailsThenRecoverToGrpclb() {
Status error = Status.NOT_FOUND.withDescription("www.google.com not found");
deliverNameResolutionError(error);
verify(helper).updatePicker(pickerCaptor.capture());
ErrorPicker errorPicker = (ErrorPicker) pickerCaptor.getValue();
assertSame(error, errorPicker.result.getStatus());
// Recover with a subsequent success
List<ResolvedServerInfoGroup> resolvedServers = createResolvedServerInfoGroupList(true);
EquivalentAddressGroup eag = resolvedServers.get(0).toEquivalentAddressGroup();
Attributes resolutionAttrs = Attributes.newBuilder().set(GrpclbConstants.ATTR_LB_POLICY, LbPolicy.GRPCLB).build();
deliverResolvedAddresses(resolvedServers, resolutionAttrs);
assertSame(LbPolicy.GRPCLB, balancer.getLbPolicy());
assertNull(balancer.getDelegate());
verify(helper).createOobChannel(eq(eag), eq(lbAuthority(0)));
verify(mockLbService).balanceLoad(lbResponseObserverCaptor.capture());
verifyNoMoreInteractions(pickFirstBalancerFactory);
verifyNoMoreInteractions(pickFirstBalancer);
verifyNoMoreInteractions(roundRobinBalancerFactory);
verifyNoMoreInteractions(roundRobinBalancer);
}
use of io.grpc.grpclb.GrpclbLoadBalancer.ErrorPicker in project grpc-java by grpc.
the class GrpclbLoadBalancerTest method grpclbBalanerCommErrors.
@Test
public void grpclbBalanerCommErrors() {
InOrder inOrder = inOrder(helper, mockLbService);
// Make the first LB address fail to connect
failingLbAuthorities.add(lbAuthority(0));
List<ResolvedServerInfoGroup> grpclbResolutionList = createResolvedServerInfoGroupList(true, true, true);
Attributes grpclbResolutionAttrs = Attributes.newBuilder().set(GrpclbConstants.ATTR_LB_POLICY, LbPolicy.GRPCLB).build();
deliverResolvedAddresses(grpclbResolutionList, grpclbResolutionAttrs);
// First LB addr fails to connect
inOrder.verify(helper).createOobChannel(eq(grpclbResolutionList.get(0).toEquivalentAddressGroup()), eq(lbAuthority(0)));
inOrder.verify(helper).updatePicker(isA(ErrorPicker.class));
assertEquals(2, fakeOobChannels.size());
assertTrue(fakeOobChannels.poll().isShutdown());
// Will move on to second LB addr
inOrder.verify(helper).createOobChannel(eq(grpclbResolutionList.get(1).toEquivalentAddressGroup()), eq(lbAuthority(1)));
inOrder.verify(mockLbService).balanceLoad(lbResponseObserverCaptor.capture());
StreamObserver<LoadBalanceResponse> lbResponseObserver = lbResponseObserverCaptor.getValue();
assertEquals(1, lbRequestObservers.size());
lbRequestObservers.poll();
assertEquals(1, fakeOobChannels.size());
assertFalse(fakeOobChannels.peek().isShutdown());
Status error1 = Status.UNAVAILABLE.withDescription("error1");
// Simulate that the stream on the second LB failed
lbResponseObserver.onError(error1.asException());
assertTrue(fakeOobChannels.poll().isShutdown());
inOrder.verify(helper).updatePicker(pickerCaptor.capture());
ErrorPicker errorPicker = (ErrorPicker) pickerCaptor.getValue();
assertEquals(error1.getCode(), errorPicker.result.getStatus().getCode());
assertTrue(errorPicker.result.getStatus().getDescription().contains(error1.getDescription()));
// Move on to the third LB.
inOrder.verify(helper).createOobChannel(eq(grpclbResolutionList.get(2).toEquivalentAddressGroup()), eq(lbAuthority(2)));
inOrder.verify(mockLbService).balanceLoad(lbResponseObserverCaptor.capture());
lbResponseObserver = lbResponseObserverCaptor.getValue();
assertEquals(1, lbRequestObservers.size());
lbRequestObservers.poll();
assertEquals(1, fakeOobChannels.size());
assertFalse(fakeOobChannels.peek().isShutdown());
// Simulate that the stream on the third LB closed without error. It is treated
// as an error.
lbResponseObserver.onCompleted();
assertTrue(fakeOobChannels.poll().isShutdown());
// Loop back to the first LB addr, which still fails.
inOrder.verify(helper).createOobChannel(eq(grpclbResolutionList.get(0).toEquivalentAddressGroup()), eq(lbAuthority(0)));
inOrder.verify(helper).updatePicker(isA(ErrorPicker.class));
assertEquals(2, fakeOobChannels.size());
assertTrue(fakeOobChannels.poll().isShutdown());
// Will move on to second LB addr
inOrder.verify(helper).createOobChannel(eq(grpclbResolutionList.get(1).toEquivalentAddressGroup()), eq(lbAuthority(1)));
inOrder.verify(mockLbService).balanceLoad(lbResponseObserverCaptor.capture());
lbResponseObserver = lbResponseObserverCaptor.getValue();
assertEquals(1, lbRequestObservers.size());
assertEquals(1, fakeOobChannels.size());
assertFalse(fakeOobChannels.peek().isShutdown());
// Finally it works.
lbResponseObserver.onNext(buildInitialResponse());
List<ServerEntry> backends = Arrays.asList(new ServerEntry("127.0.0.1", 2000, "token001"), new ServerEntry("127.0.0.1", 2010, "token002"));
lbResponseObserver.onNext(buildLbResponse(backends));
inOrder.verify(helper).createSubchannel(eq(new EquivalentAddressGroup(backends.get(0).addr)), any(Attributes.class));
inOrder.verify(helper).createSubchannel(eq(new EquivalentAddressGroup(backends.get(1).addr)), any(Attributes.class));
inOrder.verify(helper).updatePicker(same(GrpclbLoadBalancer.BUFFER_PICKER));
inOrder.verifyNoMoreInteractions();
}
use of io.grpc.grpclb.GrpclbLoadBalancer.ErrorPicker in project grpc-java by grpc.
the class GrpclbLoadBalancerTest method errorPicker.
@Test
public void errorPicker() {
PickSubchannelArgs mockArgs = mock(PickSubchannelArgs.class);
Status error = Status.UNAVAILABLE.withDescription("Just don't know why");
ErrorPicker picker = new ErrorPicker(error);
assertSame(error, picker.pickSubchannel(mockArgs).getStatus());
verifyNoMoreInteractions(mockArgs);
}
Aggregations