@@ -271,7 +271,7 @@ public void nameResolutionError_afterChildPolicyInstantiated_propagateToDownstre
271
271
}
272
272
273
273
@ Test
274
- public void pick_addsLocalityLabel () {
274
+ public void pick_addsOptionalLabels () {
275
275
LoadBalancerProvider weightedTargetProvider = new WeightedTargetLoadBalancerProvider ();
276
276
WeightedTargetConfig weightedTargetConfig =
277
277
buildWeightedTargetConfig (ImmutableMap .of (locality , 10 ));
@@ -298,6 +298,31 @@ public void pick_addsLocalityLabel() {
298
298
// The value will be determined by the parent policy, so can be different than the value used in
299
299
// makeAddress() for the test.
300
300
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 );
301
326
}
302
327
303
328
@ Test
@@ -1061,10 +1086,14 @@ public void shutdown() {
1061
1086
}
1062
1087
1063
1088
void deliverSubchannelState (final Subchannel subchannel , ConnectivityState state ) {
1089
+ deliverSubchannelState (PickResult .withSubchannel (subchannel ), state );
1090
+ }
1091
+
1092
+ void deliverSubchannelState (final PickResult result , ConnectivityState state ) {
1064
1093
SubchannelPicker picker = new SubchannelPicker () {
1065
1094
@ Override
1066
1095
public PickResult pickSubchannel (PickSubchannelArgs args ) {
1067
- return PickResult . withSubchannel ( subchannel ) ;
1096
+ return result ;
1068
1097
}
1069
1098
};
1070
1099
helper .updateBalancingState (state , picker );
0 commit comments