Skip to content

Commit 2f85328

Browse files
committed
Address comment
1 parent b0632fc commit 2f85328

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

xds/src/test/java/io/grpc/xds/GcpAuthenticationFilterTest.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static io.grpc.xds.XdsTestUtils.getWrrLbConfigAsMap;
2929
import static org.junit.Assert.assertEquals;
3030
import static org.junit.Assert.assertNotNull;
31+
import static org.junit.Assert.assertNotSame;
3132
import static org.junit.Assert.assertNull;
3233
import static org.junit.Assert.assertSame;
3334
import static org.junit.Assert.assertTrue;
@@ -377,6 +378,76 @@ public void testLruCacheAcrossInterceptors() throws IOException, ResourceInvalid
377378
assertSame(capturedOptions1.getCredentials(), capturedOptions2.getCredentials());
378379
}
379380

381+
@Test
382+
public void testLruCacheEvictionOnResize() throws IOException, ResourceInvalidException {
383+
XdsConfig.XdsClusterConfig clusterConfig = new XdsConfig.XdsClusterConfig(
384+
CLUSTER_NAME, cdsUpdate, new EndpointConfig(StatusOr.fromValue(edsUpdate)));
385+
XdsConfig defaultXdsConfig = new XdsConfig.XdsConfigBuilder()
386+
.setListener(ldsUpdate)
387+
.setRoute(rdsUpdate)
388+
.setVirtualHost(rdsUpdate.virtualHosts.get(0))
389+
.addCluster(CLUSTER_NAME, StatusOr.fromValue(clusterConfig)).build();
390+
CallOptions callOptionsWithXds = CallOptions.DEFAULT
391+
.withOption(CLUSTER_SELECTION_KEY, "cluster:cluster0")
392+
.withOption(XDS_CONFIG_CALL_OPTION_KEY, defaultXdsConfig);
393+
GcpAuthenticationFilter filter = new GcpAuthenticationFilter("FILTER_INSTANCE_NAME", 2);
394+
MethodDescriptor<Void, Void> methodDescriptor = TestMethodDescriptors.voidMethod();
395+
ClientInterceptor interceptor1 =
396+
filter.buildClientInterceptor(new GcpAuthenticationConfig(2), null, null);
397+
Channel mockChannel1 = Mockito.mock(Channel.class);
398+
ArgumentCaptor<CallOptions> captor = ArgumentCaptor.forClass(CallOptions.class);
399+
interceptor1.interceptCall(methodDescriptor, callOptionsWithXds, mockChannel1);
400+
verify(mockChannel1).newCall(eq(methodDescriptor), captor.capture());
401+
CallOptions options1 = captor.getValue();
402+
assertNotNull(options1.getCredentials());
403+
ClientInterceptor interceptor2 =
404+
filter.buildClientInterceptor(new GcpAuthenticationConfig(1), null, null);
405+
Channel mockChannel2 = Mockito.mock(Channel.class);
406+
interceptor2.interceptCall(methodDescriptor, callOptionsWithXds, mockChannel2);
407+
verify(mockChannel2).newCall(eq(methodDescriptor), captor.capture());
408+
CallOptions options2 = captor.getValue();
409+
assertNotNull(options2.getCredentials());
410+
clusterConfig = new XdsConfig.XdsClusterConfig(
411+
CLUSTER_NAME, getCdsUpdate2(), new EndpointConfig(StatusOr.fromValue(edsUpdate)));
412+
defaultXdsConfig = new XdsConfig.XdsConfigBuilder()
413+
.setListener(ldsUpdate)
414+
.setRoute(rdsUpdate)
415+
.setVirtualHost(rdsUpdate.virtualHosts.get(0))
416+
.addCluster(CLUSTER_NAME, StatusOr.fromValue(clusterConfig)).build();
417+
callOptionsWithXds = CallOptions.DEFAULT
418+
.withOption(CLUSTER_SELECTION_KEY, "cluster:cluster0")
419+
.withOption(XDS_CONFIG_CALL_OPTION_KEY, defaultXdsConfig);
420+
ClientInterceptor interceptor3 =
421+
filter.buildClientInterceptor(new GcpAuthenticationConfig(1), null, null);
422+
Channel mockChannel3 = Mockito.mock(Channel.class);
423+
interceptor3.interceptCall(methodDescriptor, callOptionsWithXds, mockChannel3);
424+
verify(mockChannel3).newCall(eq(methodDescriptor), captor.capture());
425+
CallOptions options3 = captor.getValue();
426+
assertNotNull(options3.getCredentials());
427+
clusterConfig = new XdsConfig.XdsClusterConfig(
428+
CLUSTER_NAME, cdsUpdate, new EndpointConfig(StatusOr.fromValue(edsUpdate)));
429+
defaultXdsConfig = new XdsConfig.XdsConfigBuilder()
430+
.setListener(ldsUpdate)
431+
.setRoute(rdsUpdate)
432+
.setVirtualHost(rdsUpdate.virtualHosts.get(0))
433+
.addCluster(CLUSTER_NAME, StatusOr.fromValue(clusterConfig)).build();
434+
callOptionsWithXds = CallOptions.DEFAULT
435+
.withOption(CLUSTER_SELECTION_KEY, "cluster:cluster0")
436+
.withOption(XDS_CONFIG_CALL_OPTION_KEY, defaultXdsConfig);
437+
438+
ClientInterceptor interceptor4 =
439+
filter.buildClientInterceptor(new GcpAuthenticationConfig(1), null, null);
440+
Channel mockChannel4 = Mockito.mock(Channel.class);
441+
interceptor4.interceptCall(methodDescriptor, callOptionsWithXds, mockChannel4);
442+
verify(mockChannel4).newCall(eq(methodDescriptor), captor.capture());
443+
CallOptions options4 = captor.getValue();
444+
assertNotNull(options4.getCredentials());
445+
446+
assertSame(options1.getCredentials(), options2.getCredentials());
447+
assertNotSame(options1.getCredentials(), options3.getCredentials());
448+
assertNotSame(options1.getCredentials(), options4.getCredentials());
449+
}
450+
380451
private static LdsUpdate getLdsUpdate() {
381452
Filter.NamedFilterConfig routerFilterConfig = new Filter.NamedFilterConfig(
382453
serverName, RouterFilter.ROUTER_CONFIG);
@@ -419,6 +490,19 @@ private static CdsUpdate getCdsUpdate() {
419490
}
420491
}
421492

493+
private static CdsUpdate getCdsUpdate2() {
494+
ImmutableMap.Builder<String, Object> parsedMetadata = ImmutableMap.builder();
495+
parsedMetadata.put("FILTER_INSTANCE_NAME", new AudienceWrapper("NEW_TEST_AUDIENCE"));
496+
try {
497+
CdsUpdate.Builder cdsUpdate = CdsUpdate.forEds(
498+
CLUSTER_NAME, EDS_NAME, null, null, null, null, false)
499+
.lbPolicyConfig(getWrrLbConfigAsMap());
500+
return cdsUpdate.parsedMetadata(parsedMetadata.build()).build();
501+
} catch (IOException ex) {
502+
return null;
503+
}
504+
}
505+
422506
private static CdsUpdate getCdsUpdateWithIncorrectAudienceWrapper() throws IOException {
423507
ImmutableMap.Builder<String, Object> parsedMetadata = ImmutableMap.builder();
424508
parsedMetadata.put("FILTER_INSTANCE_NAME", "TEST_AUDIENCE");

0 commit comments

Comments
 (0)