19
19
import static com .google .common .truth .Truth .assertThat ;
20
20
import static org .mockito .AdditionalAnswers .delegatesTo ;
21
21
import static org .mockito .ArgumentMatchers .any ;
22
+ import static org .mockito .ArgumentMatchers .anyList ;
22
23
import static org .mockito .ArgumentMatchers .argThat ;
23
24
import static org .mockito .ArgumentMatchers .eq ;
24
25
import static org .mockito .Mockito .inOrder ;
@@ -129,8 +130,6 @@ public void setXdsClient_reportMetrics() throws Exception {
129
130
future .set (null );
130
131
when (mockXdsClient .getSubscribedResourcesMetadataSnapshot ()).thenReturn (Futures .immediateFuture (
131
132
ImmutableMap .of ()));
132
- when (mockXdsClient .getSubscribedResourcesAuthoritySnapshot ())
133
- .thenReturn (Futures .immediateFuture (ImmutableMap .of ()));
134
133
when (mockXdsClient .reportServerConnections (any (ServerConnectionCallback .class )))
135
134
.thenReturn (future );
136
135
reporter .setXdsClient (mockXdsClient );
@@ -152,8 +151,6 @@ public void setXdsClient_reportCallbackMetrics_resourceCountsFails() {
152
151
future .set (null );
153
152
when (mockXdsClient .getSubscribedResourcesMetadataSnapshot ()).thenReturn (Futures .immediateFuture (
154
153
ImmutableMap .of ()));
155
- when (mockXdsClient .getSubscribedResourcesAuthoritySnapshot ())
156
- .thenReturn (Futures .immediateFuture (ImmutableMap .of ()));
157
154
158
155
// Create a future that will throw an exception
159
156
SettableFuture <Void > serverConnectionsFeature = SettableFuture .create ();
@@ -181,8 +178,6 @@ public void metricGauges() {
181
178
future .set (null );
182
179
when (mockXdsClient .getSubscribedResourcesMetadataSnapshot ()).thenReturn (Futures .immediateFuture (
183
180
ImmutableMap .of ()));
184
- when (mockXdsClient .getSubscribedResourcesAuthoritySnapshot ())
185
- .thenReturn (Futures .immediateFuture (ImmutableMap .of ()));
186
181
when (mockXdsClient .reportServerConnections (any (ServerConnectionCallback .class )))
187
182
.thenReturn (future );
188
183
reporter .setXdsClient (mockXdsClient );
@@ -238,7 +233,7 @@ public void metricReporterCallback() {
238
233
@ Test
239
234
public void reportCallbackMetrics_computeAndReportResourceCounts () {
240
235
Map <XdsResourceType <?>, Map <String , ResourceMetadata >> metadataByType = new HashMap <>();
241
- Map <XdsResourceType <?>, Map < String , String >> authorityByType = new HashMap <>();
236
+ Map <String , String > resourceNameByAuthority = new HashMap <>();
242
237
XdsResourceType <?> listenerResource = XdsListenerResource .getInstance ();
243
238
XdsResourceType <?> routeConfigResource = XdsRouteConfigureResource .getInstance ();
244
239
XdsResourceType <?> clusterResource = XdsClusterResource .getInstance ();
@@ -248,44 +243,37 @@ public void reportCallbackMetrics_computeAndReportResourceCounts() {
248
243
long nanosLastUpdate = 1577923199_606042047L ;
249
244
250
245
Map <String , ResourceMetadata > ldsResourceMetadataMap = new HashMap <>();
251
- Map <String , String > ldsAuthorityMap = new HashMap <>();
252
246
ldsResourceMetadataMap .put ("resource1" ,
253
247
ResourceMetadata .newResourceMetadataRequested ());
254
- ldsAuthorityMap .put ("resource1" , "authority1" );
248
+ resourceNameByAuthority .put ("resource1" , "authority1" );
255
249
ResourceMetadata ackedLdsResource = ResourceMetadata .newResourceMetadataAcked (rawListener , "42" ,
256
250
nanosLastUpdate );
257
251
ldsResourceMetadataMap .put ("resource2" , ackedLdsResource );
258
- ldsAuthorityMap .put ("resource2" , "authority2" );
252
+ resourceNameByAuthority .put ("resource2" , "authority2" );
259
253
ldsResourceMetadataMap .put ("resource3" ,
260
254
ResourceMetadata .newResourceMetadataAcked (rawListener , "43" , nanosLastUpdate ));
261
- ldsAuthorityMap .put ("resource3" , "authority3 " );
255
+ resourceNameByAuthority .put ("resource3" , "authority2 " );
262
256
ldsResourceMetadataMap .put ("resource4" ,
263
257
ResourceMetadata .newResourceMetadataNacked (ackedLdsResource , "44" , nanosLastUpdate ,
264
258
"nacked after previous ack" , true ));
265
- ldsAuthorityMap .put ("resource4" , "authority4" );
259
+ resourceNameByAuthority .put ("resource4" , "authority4" );
266
260
267
261
Map <String , ResourceMetadata > rdsResourceMetadataMap = new HashMap <>();
268
- Map <String , String > rdsAuthorityMap = new HashMap <>();
269
262
ResourceMetadata requestedRdsResourceMetadata = ResourceMetadata .newResourceMetadataRequested ();
270
263
rdsResourceMetadataMap .put ("resource5" ,
271
264
ResourceMetadata .newResourceMetadataNacked (requestedRdsResourceMetadata , "24" ,
272
265
nanosLastUpdate , "nacked after request" , false ));
273
- rdsAuthorityMap .put ("resource5" , "authority5" );
266
+ resourceNameByAuthority .put ("resource5" , "authority5" );
274
267
rdsResourceMetadataMap .put ("resource6" ,
275
268
ResourceMetadata .newResourceMetadataDoesNotExist ());
276
- rdsAuthorityMap .put ("resource6" , "authority6" );
269
+ resourceNameByAuthority .put ("resource6" , "authority6" );
277
270
278
271
Map <String , ResourceMetadata > cdsResourceMetadataMap = new HashMap <>();
279
- Map <String , String > cdsAuthorityMap = new HashMap <>();
280
272
cdsResourceMetadataMap .put ("resource7" , ResourceMetadata .newResourceMetadataUnknown ());
281
- cdsAuthorityMap .put ("resource7" , "authority7" );
282
273
283
274
metadataByType .put (listenerResource , ldsResourceMetadataMap );
284
- authorityByType .put (listenerResource , ldsAuthorityMap );
285
275
metadataByType .put (routeConfigResource , rdsResourceMetadataMap );
286
- authorityByType .put (routeConfigResource , rdsAuthorityMap );
287
276
metadataByType .put (clusterResource , cdsResourceMetadataMap );
288
- authorityByType .put (clusterResource , cdsAuthorityMap );
289
277
290
278
SettableFuture <Void > reportServerConnectionsCompleted = SettableFuture .create ();
291
279
reportServerConnectionsCompleted .set (null );
@@ -297,10 +285,8 @@ public void reportCallbackMetrics_computeAndReportResourceCounts() {
297
285
when (mockXdsClient .getSubscribedResourcesMetadataSnapshot ())
298
286
.thenReturn (getResourceMetadataCompleted );
299
287
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 );
304
290
305
291
reporter .reportCallbackMetrics (mockBatchRecorder , mockXdsClient );
306
292
@@ -310,7 +296,7 @@ public void reportCallbackMetrics_computeAndReportResourceCounts() {
310
296
"requested" , listenerResource .typeUrl ())), any ());
311
297
// LDS resources acked
312
298
verify (mockBatchRecorder ).recordLongGauge (eqMetricInstrumentName ("grpc.xds_client.resources" ),
313
- eq (2L ), eq (Arrays .asList (target , "authority3 " ,
299
+ eq (2L ), eq (Arrays .asList (target , "authority2 " ,
314
300
"acked" , listenerResource .typeUrl ())), any ());
315
301
// LDS resource nacked but cached
316
302
verify (mockBatchRecorder ).recordLongGauge (eqMetricInstrumentName ("grpc.xds_client.resources" ),
@@ -328,18 +314,16 @@ public void reportCallbackMetrics_computeAndReportResourceCounts() {
328
314
329
315
// CDS resource unknown
330
316
verify (mockBatchRecorder ).recordLongGauge (eqMetricInstrumentName ("grpc.xds_client.resources" ),
331
- eq (1L ), eq (Arrays .asList (target , "authority7 " ,
317
+ eq (1L ), eq (Arrays .asList (target , "#old " ,
332
318
"unknown" , clusterResource .typeUrl ())), any ());
333
319
verifyNoMoreInteractions (mockBatchRecorder );
334
320
}
335
321
336
322
@ Test
337
323
public void reportCallbackMetrics_computeAndReportResourceCounts_emptyResources () {
338
324
Map <XdsResourceType <?>, Map <String , ResourceMetadata >> metadataByType = new HashMap <>();
339
- Map <XdsResourceType <?>, Map <String , String >> authorityByType = new HashMap <>();
340
325
XdsResourceType <?> listenerResource = XdsListenerResource .getInstance ();
341
326
metadataByType .put (listenerResource , Collections .emptyMap ());
342
- authorityByType .put (listenerResource , Collections .emptyMap ());
343
327
344
328
SettableFuture <Void > reportServerConnectionsCompleted = SettableFuture .create ();
345
329
reportServerConnectionsCompleted .set (null );
@@ -351,11 +335,6 @@ public void reportCallbackMetrics_computeAndReportResourceCounts_emptyResources(
351
335
when (mockXdsClient .getSubscribedResourcesMetadataSnapshot ())
352
336
.thenReturn (getResourceMetadataCompleted );
353
337
354
- ListenableFuture <Map <XdsResourceType <?>, Map <String , String >>>
355
- getAuthorityCompleted = Futures .immediateFuture (authorityByType );
356
- when (mockXdsClient .getSubscribedResourcesAuthoritySnapshot ())
357
- .thenReturn (getAuthorityCompleted );
358
-
359
338
reporter .reportCallbackMetrics (mockBatchRecorder , mockXdsClient );
360
339
361
340
// Verify that reportResourceCountGauge is never called
0 commit comments