1919import static com .google .common .truth .Truth .assertThat ;
2020import static org .mockito .AdditionalAnswers .delegatesTo ;
2121import static org .mockito .ArgumentMatchers .any ;
22+ import static org .mockito .ArgumentMatchers .anyList ;
2223import static org .mockito .ArgumentMatchers .argThat ;
2324import static org .mockito .ArgumentMatchers .eq ;
2425import static org .mockito .Mockito .inOrder ;
@@ -129,8 +130,6 @@ public void setXdsClient_reportMetrics() throws Exception {
129130 future .set (null );
130131 when (mockXdsClient .getSubscribedResourcesMetadataSnapshot ()).thenReturn (Futures .immediateFuture (
131132 ImmutableMap .of ()));
132- when (mockXdsClient .getSubscribedResourcesAuthoritySnapshot ())
133- .thenReturn (Futures .immediateFuture (ImmutableMap .of ()));
134133 when (mockXdsClient .reportServerConnections (any (ServerConnectionCallback .class )))
135134 .thenReturn (future );
136135 reporter .setXdsClient (mockXdsClient );
@@ -152,8 +151,6 @@ public void setXdsClient_reportCallbackMetrics_resourceCountsFails() {
152151 future .set (null );
153152 when (mockXdsClient .getSubscribedResourcesMetadataSnapshot ()).thenReturn (Futures .immediateFuture (
154153 ImmutableMap .of ()));
155- when (mockXdsClient .getSubscribedResourcesAuthoritySnapshot ())
156- .thenReturn (Futures .immediateFuture (ImmutableMap .of ()));
157154
158155 // Create a future that will throw an exception
159156 SettableFuture <Void > serverConnectionsFeature = SettableFuture .create ();
@@ -181,8 +178,6 @@ public void metricGauges() {
181178 future .set (null );
182179 when (mockXdsClient .getSubscribedResourcesMetadataSnapshot ()).thenReturn (Futures .immediateFuture (
183180 ImmutableMap .of ()));
184- when (mockXdsClient .getSubscribedResourcesAuthoritySnapshot ())
185- .thenReturn (Futures .immediateFuture (ImmutableMap .of ()));
186181 when (mockXdsClient .reportServerConnections (any (ServerConnectionCallback .class )))
187182 .thenReturn (future );
188183 reporter .setXdsClient (mockXdsClient );
@@ -238,7 +233,7 @@ public void metricReporterCallback() {
238233 @ Test
239234 public void reportCallbackMetrics_computeAndReportResourceCounts () {
240235 Map <XdsResourceType <?>, Map <String , ResourceMetadata >> metadataByType = new HashMap <>();
241- Map <XdsResourceType <?>, Map < String , String >> authorityByType = new HashMap <>();
236+ Map <String , String > resourceNameByAuthority = new HashMap <>();
242237 XdsResourceType <?> listenerResource = XdsListenerResource .getInstance ();
243238 XdsResourceType <?> routeConfigResource = XdsRouteConfigureResource .getInstance ();
244239 XdsResourceType <?> clusterResource = XdsClusterResource .getInstance ();
@@ -248,44 +243,37 @@ public void reportCallbackMetrics_computeAndReportResourceCounts() {
248243 long nanosLastUpdate = 1577923199_606042047L ;
249244
250245 Map <String , ResourceMetadata > ldsResourceMetadataMap = new HashMap <>();
251- Map <String , String > ldsAuthorityMap = new HashMap <>();
252246 ldsResourceMetadataMap .put ("resource1" ,
253247 ResourceMetadata .newResourceMetadataRequested ());
254- ldsAuthorityMap .put ("resource1" , "authority1" );
248+ resourceNameByAuthority .put ("resource1" , "authority1" );
255249 ResourceMetadata ackedLdsResource = ResourceMetadata .newResourceMetadataAcked (rawListener , "42" ,
256250 nanosLastUpdate );
257251 ldsResourceMetadataMap .put ("resource2" , ackedLdsResource );
258- ldsAuthorityMap .put ("resource2" , "authority2" );
252+ resourceNameByAuthority .put ("resource2" , "authority2" );
259253 ldsResourceMetadataMap .put ("resource3" ,
260254 ResourceMetadata .newResourceMetadataAcked (rawListener , "43" , nanosLastUpdate ));
261- ldsAuthorityMap .put ("resource3" , "authority3 " );
255+ resourceNameByAuthority .put ("resource3" , "authority2 " );
262256 ldsResourceMetadataMap .put ("resource4" ,
263257 ResourceMetadata .newResourceMetadataNacked (ackedLdsResource , "44" , nanosLastUpdate ,
264258 "nacked after previous ack" , true ));
265- ldsAuthorityMap .put ("resource4" , "authority4" );
259+ resourceNameByAuthority .put ("resource4" , "authority4" );
266260
267261 Map <String , ResourceMetadata > rdsResourceMetadataMap = new HashMap <>();
268- Map <String , String > rdsAuthorityMap = new HashMap <>();
269262 ResourceMetadata requestedRdsResourceMetadata = ResourceMetadata .newResourceMetadataRequested ();
270263 rdsResourceMetadataMap .put ("resource5" ,
271264 ResourceMetadata .newResourceMetadataNacked (requestedRdsResourceMetadata , "24" ,
272265 nanosLastUpdate , "nacked after request" , false ));
273- rdsAuthorityMap .put ("resource5" , "authority5" );
266+ resourceNameByAuthority .put ("resource5" , "authority5" );
274267 rdsResourceMetadataMap .put ("resource6" ,
275268 ResourceMetadata .newResourceMetadataDoesNotExist ());
276- rdsAuthorityMap .put ("resource6" , "authority6" );
269+ resourceNameByAuthority .put ("resource6" , "authority6" );
277270
278271 Map <String , ResourceMetadata > cdsResourceMetadataMap = new HashMap <>();
279- Map <String , String > cdsAuthorityMap = new HashMap <>();
280272 cdsResourceMetadataMap .put ("resource7" , ResourceMetadata .newResourceMetadataUnknown ());
281- cdsAuthorityMap .put ("resource7" , "authority7" );
282273
283274 metadataByType .put (listenerResource , ldsResourceMetadataMap );
284- authorityByType .put (listenerResource , ldsAuthorityMap );
285275 metadataByType .put (routeConfigResource , rdsResourceMetadataMap );
286- authorityByType .put (routeConfigResource , rdsAuthorityMap );
287276 metadataByType .put (clusterResource , cdsResourceMetadataMap );
288- authorityByType .put (clusterResource , cdsAuthorityMap );
289277
290278 SettableFuture <Void > reportServerConnectionsCompleted = SettableFuture .create ();
291279 reportServerConnectionsCompleted .set (null );
@@ -297,10 +285,8 @@ public void reportCallbackMetrics_computeAndReportResourceCounts() {
297285 when (mockXdsClient .getSubscribedResourcesMetadataSnapshot ())
298286 .thenReturn (getResourceMetadataCompleted );
299287
300- ListenableFuture <Map <XdsResourceType <?>, Map <String , String >>>
301- getResourceAuthorityCompleted = Futures .immediateFuture (authorityByType );
302- when (mockXdsClient .getSubscribedResourcesAuthoritySnapshot ())
303- .thenReturn (getResourceAuthorityCompleted );
288+ when (mockXdsClient .getResourceNameToAuthorityMap (anyList ()))
289+ .thenReturn (resourceNameByAuthority );
304290
305291 reporter .reportCallbackMetrics (mockBatchRecorder , mockXdsClient );
306292
@@ -310,7 +296,7 @@ public void reportCallbackMetrics_computeAndReportResourceCounts() {
310296 "requested" , listenerResource .typeUrl ())), any ());
311297 // LDS resources acked
312298 verify (mockBatchRecorder ).recordLongGauge (eqMetricInstrumentName ("grpc.xds_client.resources" ),
313- eq (2L ), eq (Arrays .asList (target , "authority3 " ,
299+ eq (2L ), eq (Arrays .asList (target , "authority2 " ,
314300 "acked" , listenerResource .typeUrl ())), any ());
315301 // LDS resource nacked but cached
316302 verify (mockBatchRecorder ).recordLongGauge (eqMetricInstrumentName ("grpc.xds_client.resources" ),
@@ -328,18 +314,16 @@ public void reportCallbackMetrics_computeAndReportResourceCounts() {
328314
329315 // CDS resource unknown
330316 verify (mockBatchRecorder ).recordLongGauge (eqMetricInstrumentName ("grpc.xds_client.resources" ),
331- eq (1L ), eq (Arrays .asList (target , "authority7 " ,
317+ eq (1L ), eq (Arrays .asList (target , "#old " ,
332318 "unknown" , clusterResource .typeUrl ())), any ());
333319 verifyNoMoreInteractions (mockBatchRecorder );
334320 }
335321
336322 @ Test
337323 public void reportCallbackMetrics_computeAndReportResourceCounts_emptyResources () {
338324 Map <XdsResourceType <?>, Map <String , ResourceMetadata >> metadataByType = new HashMap <>();
339- Map <XdsResourceType <?>, Map <String , String >> authorityByType = new HashMap <>();
340325 XdsResourceType <?> listenerResource = XdsListenerResource .getInstance ();
341326 metadataByType .put (listenerResource , Collections .emptyMap ());
342- authorityByType .put (listenerResource , Collections .emptyMap ());
343327
344328 SettableFuture <Void > reportServerConnectionsCompleted = SettableFuture .create ();
345329 reportServerConnectionsCompleted .set (null );
@@ -351,11 +335,6 @@ public void reportCallbackMetrics_computeAndReportResourceCounts_emptyResources(
351335 when (mockXdsClient .getSubscribedResourcesMetadataSnapshot ())
352336 .thenReturn (getResourceMetadataCompleted );
353337
354- ListenableFuture <Map <XdsResourceType <?>, Map <String , String >>>
355- getAuthorityCompleted = Futures .immediateFuture (authorityByType );
356- when (mockXdsClient .getSubscribedResourcesAuthoritySnapshot ())
357- .thenReturn (getAuthorityCompleted );
358-
359338 reporter .reportCallbackMetrics (mockBatchRecorder , mockXdsClient );
360339
361340 // Verify that reportResourceCountGauge is never called
0 commit comments