@@ -271,7 +271,7 @@ public void nameResolutionError_afterChildPolicyInstantiated_propagateToDownstre
271271 }
272272
273273 @ Test
274- public void pick_addsLocalityLabel () {
274+ public void pick_addsOptionalLabels () {
275275 LoadBalancerProvider weightedTargetProvider = new WeightedTargetLoadBalancerProvider ();
276276 WeightedTargetConfig weightedTargetConfig =
277277 buildWeightedTargetConfig (ImmutableMap .of (locality , 10 ));
@@ -298,6 +298,31 @@ public void pick_addsLocalityLabel() {
298298 // The value will be determined by the parent policy, so can be different than the value used in
299299 // makeAddress() for the test.
300300 verify (detailsConsumer ).addOptionalLabel ("grpc.lb.locality" , locality .toString ());
301+ verify (detailsConsumer ).addOptionalLabel ("grpc.xds.cluster" , CLUSTER );
302+ }
303+
304+ @ Test
305+ public void pick_noResult_addsClusterLabel () {
306+ LoadBalancerProvider weightedTargetProvider = new WeightedTargetLoadBalancerProvider ();
307+ WeightedTargetConfig weightedTargetConfig =
308+ buildWeightedTargetConfig (ImmutableMap .of (locality , 10 ));
309+ ClusterImplConfig config = new ClusterImplConfig (CLUSTER , EDS_SERVICE_NAME , LRS_SERVER_INFO ,
310+ null , Collections .<DropOverload >emptyList (),
311+ GracefulSwitchLoadBalancer .createLoadBalancingPolicyConfig (
312+ weightedTargetProvider , weightedTargetConfig ),
313+ null , Collections .emptyMap ());
314+ EquivalentAddressGroup endpoint = makeAddress ("endpoint-addr" , locality );
315+ deliverAddressesAndConfig (Collections .singletonList (endpoint ), config );
316+ FakeLoadBalancer leafBalancer = Iterables .getOnlyElement (downstreamBalancers );
317+ leafBalancer .deliverSubchannelState (PickResult .withNoResult (), ConnectivityState .CONNECTING );
318+ assertThat (currentState ).isEqualTo (ConnectivityState .CONNECTING );
319+
320+ PickDetailsConsumer detailsConsumer = mock (PickDetailsConsumer .class );
321+ pickSubchannelArgs = new PickSubchannelArgsImpl (
322+ TestMethodDescriptors .voidMethod (), new Metadata (), CallOptions .DEFAULT , detailsConsumer );
323+ PickResult result = currentPicker .pickSubchannel (pickSubchannelArgs );
324+ assertThat (result .getStatus ().isOk ()).isTrue ();
325+ verify (detailsConsumer ).addOptionalLabel ("grpc.xds.cluster" , CLUSTER );
301326 }
302327
303328 @ Test
@@ -1061,10 +1086,14 @@ public void shutdown() {
10611086 }
10621087
10631088 void deliverSubchannelState (final Subchannel subchannel , ConnectivityState state ) {
1089+ deliverSubchannelState (PickResult .withSubchannel (subchannel ), state );
1090+ }
1091+
1092+ void deliverSubchannelState (final PickResult result , ConnectivityState state ) {
10641093 SubchannelPicker picker = new SubchannelPicker () {
10651094 @ Override
10661095 public PickResult pickSubchannel (PickSubchannelArgs args ) {
1067- return PickResult . withSubchannel ( subchannel ) ;
1096+ return result ;
10681097 }
10691098 };
10701099 helper .updateBalancingState (state , picker );
0 commit comments