mirror of https://github.com/grpc/grpc-java.git
grpclb: fix pick_first mode shutdown without subchannels. (#6072)
This commit is contained in:
parent
e68e4004e4
commit
2c0b2de862
|
|
@ -341,8 +341,10 @@ final class GrpclbState {
|
||||||
subchannelPool.clear();
|
subchannelPool.clear();
|
||||||
break;
|
break;
|
||||||
case PICK_FIRST:
|
case PICK_FIRST:
|
||||||
checkState(subchannels.size() == 1, "Excessive Subchannels: %s", subchannels);
|
if (!subchannels.isEmpty()) {
|
||||||
subchannels.values().iterator().next().shutdown();
|
checkState(subchannels.size() == 1, "Excessive Subchannels: %s", subchannels);
|
||||||
|
subchannels.values().iterator().next().shutdown();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new AssertionError("Missing case for " + mode);
|
throw new AssertionError("Missing case for " + mode);
|
||||||
|
|
|
||||||
|
|
@ -1813,6 +1813,31 @@ public class GrpclbLoadBalancerTest {
|
||||||
.returnSubchannel(any(Subchannel.class), any(ConnectivityStateInfo.class));
|
.returnSubchannel(any(Subchannel.class), any(ConnectivityStateInfo.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shutdownWithoutSubchannel_roundRobin() throws Exception {
|
||||||
|
subtestShutdownWithoutSubchannel("round_robin");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shutdownWithoutSubchannel_pickFirst() throws Exception {
|
||||||
|
subtestShutdownWithoutSubchannel("pick_first");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void subtestShutdownWithoutSubchannel(String childPolicy) throws Exception {
|
||||||
|
String lbConfig = "{\"childPolicy\" : [ {\"" + childPolicy + "\" : {}} ]}";
|
||||||
|
List<EquivalentAddressGroup> grpclbResolutionList = createResolvedServerAddresses(true);
|
||||||
|
Attributes grpclbResolutionAttrs = Attributes.newBuilder().set(
|
||||||
|
LoadBalancer.ATTR_LOAD_BALANCING_CONFIG, parseJsonObject(lbConfig)).build();
|
||||||
|
deliverResolvedAddresses(grpclbResolutionList, grpclbResolutionAttrs);
|
||||||
|
verify(mockLbService).balanceLoad(lbResponseObserverCaptor.capture());
|
||||||
|
assertEquals(1, lbRequestObservers.size());
|
||||||
|
StreamObserver<LoadBalanceRequest> requestObserver = lbRequestObservers.poll();
|
||||||
|
|
||||||
|
verify(requestObserver, never()).onCompleted();
|
||||||
|
balancer.shutdown();
|
||||||
|
verify(requestObserver).onCompleted();
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Test
|
@Test
|
||||||
public void grpclbWorking_pickFirstMode_expectBackendsShuffled() throws Exception {
|
public void grpclbWorking_pickFirstMode_expectBackendsShuffled() throws Exception {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue