@@ -392,21 +392,24 @@ public void testLruCacheEvictionOnResize() throws IOException, ResourceInvalidEx
392392 .withOption (XDS_CONFIG_CALL_OPTION_KEY , defaultXdsConfig );
393393 GcpAuthenticationFilter filter = new GcpAuthenticationFilter ("FILTER_INSTANCE_NAME" , 2 );
394394 MethodDescriptor <Void , Void > methodDescriptor = TestMethodDescriptors .voidMethod ();
395+
395396 ClientInterceptor interceptor1 =
396397 filter .buildClientInterceptor (new GcpAuthenticationConfig (2 ), null , null );
397398 Channel mockChannel1 = Mockito .mock (Channel .class );
398399 ArgumentCaptor <CallOptions > captor = ArgumentCaptor .forClass (CallOptions .class );
399400 interceptor1 .interceptCall (methodDescriptor , callOptionsWithXds , mockChannel1 );
400401 verify (mockChannel1 ).newCall (eq (methodDescriptor ), captor .capture ());
401402 CallOptions options1 = captor .getValue ();
402- assertNotNull ( options1 . getCredentials ());
403+ // This will recreate the cache with max size of 1 and copy the credential for audience1.
403404 ClientInterceptor interceptor2 =
404405 filter .buildClientInterceptor (new GcpAuthenticationConfig (1 ), null , null );
405406 Channel mockChannel2 = Mockito .mock (Channel .class );
406407 interceptor2 .interceptCall (methodDescriptor , callOptionsWithXds , mockChannel2 );
407408 verify (mockChannel2 ).newCall (eq (methodDescriptor ), captor .capture ());
408409 CallOptions options2 = captor .getValue ();
409- assertNotNull (options2 .getCredentials ());
410+
411+ assertSame (options1 .getCredentials (), options2 .getCredentials ());
412+
410413 clusterConfig = new XdsConfig .XdsClusterConfig (
411414 CLUSTER_NAME , getCdsUpdate2 (), new EndpointConfig (StatusOr .fromValue (edsUpdate )));
412415 defaultXdsConfig = new XdsConfig .XdsConfigBuilder ()
@@ -417,13 +420,17 @@ public void testLruCacheEvictionOnResize() throws IOException, ResourceInvalidEx
417420 callOptionsWithXds = CallOptions .DEFAULT
418421 .withOption (CLUSTER_SELECTION_KEY , "cluster:cluster0" )
419422 .withOption (XDS_CONFIG_CALL_OPTION_KEY , defaultXdsConfig );
423+
424+ // This will evict the credential for audience1 and add new credential for audience2
420425 ClientInterceptor interceptor3 =
421426 filter .buildClientInterceptor (new GcpAuthenticationConfig (1 ), null , null );
422427 Channel mockChannel3 = Mockito .mock (Channel .class );
423428 interceptor3 .interceptCall (methodDescriptor , callOptionsWithXds , mockChannel3 );
424429 verify (mockChannel3 ).newCall (eq (methodDescriptor ), captor .capture ());
425430 CallOptions options3 = captor .getValue ();
426- assertNotNull (options3 .getCredentials ());
431+
432+ assertNotSame (options1 .getCredentials (), options3 .getCredentials ());
433+
427434 clusterConfig = new XdsConfig .XdsClusterConfig (
428435 CLUSTER_NAME , cdsUpdate , new EndpointConfig (StatusOr .fromValue (edsUpdate )));
429436 defaultXdsConfig = new XdsConfig .XdsConfigBuilder ()
@@ -435,16 +442,14 @@ public void testLruCacheEvictionOnResize() throws IOException, ResourceInvalidEx
435442 .withOption (CLUSTER_SELECTION_KEY , "cluster:cluster0" )
436443 .withOption (XDS_CONFIG_CALL_OPTION_KEY , defaultXdsConfig );
437444
445+ // This will create new credential for audience1 because it has been evicted
438446 ClientInterceptor interceptor4 =
439447 filter .buildClientInterceptor (new GcpAuthenticationConfig (1 ), null , null );
440448 Channel mockChannel4 = Mockito .mock (Channel .class );
441449 interceptor4 .interceptCall (methodDescriptor , callOptionsWithXds , mockChannel4 );
442450 verify (mockChannel4 ).newCall (eq (methodDescriptor ), captor .capture ());
443451 CallOptions options4 = captor .getValue ();
444- assertNotNull (options4 .getCredentials ());
445452
446- assertSame (options1 .getCredentials (), options2 .getCredentials ());
447- assertNotSame (options1 .getCredentials (), options3 .getCredentials ());
448453 assertNotSame (options1 .getCredentials (), options4 .getCredentials ());
449454 }
450455
0 commit comments