Skip to content

Commit 9a712c3

Browse files
committed
xds: Make XdsClient.ResourceStore package-private
There's no reason to use the interface outside of XdsClientImpl/ControlPlaneClient. Since XdsClientImpl implements the interface directly, its methods are still public. That can be a future cleanup.
1 parent bac8b32 commit 9a712c3

File tree

2 files changed

+16
-60
lines changed

2 files changed

+16
-60
lines changed

xds/src/main/java/io/grpc/xds/client/XdsClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ void handleResourceResponse(
428428
void handleStreamClosed(Status error, boolean shouldTryFallback);
429429
}
430430

431-
public interface ResourceStore {
431+
interface ResourceStore {
432432

433433
/**
434434
* Returns the collection of resources currently subscribed to which have an authority matching

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

Lines changed: 15 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ private void verifyResponse(ClientStatusResponse response) {
299299
assertThat(response.getConfigCount()).isEqualTo(1);
300300
ClientConfig clientConfig = response.getConfig(0);
301301
verifyClientConfigNode(clientConfig);
302-
verifyClientConfigNoResources(XDS_CLIENT_NO_RESOURCES, clientConfig);
302+
assertThat(clientConfig.getGenericXdsConfigsList()).isEmpty();
303303
assertThat(clientConfig.getClientScope()).isEmpty();
304304
}
305305

@@ -310,7 +310,7 @@ private Collection<String> verifyMultiResponse(ClientStatusResponse response, in
310310
for (int i = 0; i < numExpected; i++) {
311311
ClientConfig clientConfig = response.getConfig(i);
312312
verifyClientConfigNode(clientConfig);
313-
verifyClientConfigNoResources(XDS_CLIENT_NO_RESOURCES, clientConfig);
313+
assertThat(clientConfig.getGenericXdsConfigsList()).isEmpty();
314314
clientScopes.add(clientConfig.getClientScope());
315315
}
316316

@@ -382,16 +382,6 @@ public void getClientConfigForXdsClient_subscribedResourcesToGenericXdsConfig()
382382
.put(EDS, ImmutableMap.of("subscribedResourceName.EDS", METADATA_ACKED_EDS))
383383
.buildOrThrow();
384384
}
385-
386-
@Override
387-
public Map<String, XdsResourceType<?>> getSubscribedResourceTypesWithTypeUrl() {
388-
return ImmutableMap.of(
389-
LDS.typeUrl(), LDS,
390-
RDS.typeUrl(), RDS,
391-
CDS.typeUrl(), CDS,
392-
EDS.typeUrl(), EDS
393-
);
394-
}
395385
};
396386
ClientConfig clientConfig = CsdsService.getClientConfigForXdsClient(fakeXdsClient,
397387
FAKE_CLIENT_SCOPE);
@@ -403,31 +393,31 @@ public Map<String, XdsResourceType<?>> getSubscribedResourceTypesWithTypeUrl() {
403393
// is propagated to the correct resource types.
404394
int xdsConfigCount = clientConfig.getGenericXdsConfigsCount();
405395
assertThat(xdsConfigCount).isEqualTo(4);
406-
Map<XdsResourceType<?>, GenericXdsConfig> configDumps = mapConfigDumps(fakeXdsClient,
407-
clientConfig);
408-
assertThat(configDumps.keySet()).containsExactly(LDS, RDS, CDS, EDS);
396+
Map<String, GenericXdsConfig> configDumps = mapConfigDumps(clientConfig);
397+
assertThat(configDumps.keySet())
398+
.containsExactly(LDS.typeUrl(), RDS.typeUrl(), CDS.typeUrl(), EDS.typeUrl());
409399

410400
// LDS.
411-
GenericXdsConfig genericXdsConfigLds = configDumps.get(LDS);
401+
GenericXdsConfig genericXdsConfigLds = configDumps.get(LDS.typeUrl());
412402
assertThat(genericXdsConfigLds.getName()).isEqualTo("subscribedResourceName.LDS");
413403
assertThat(genericXdsConfigLds.getClientStatus()).isEqualTo(ClientResourceStatus.ACKED);
414404
assertThat(genericXdsConfigLds.getVersionInfo()).isEqualTo(VERSION_ACK_LDS);
415405
assertThat(genericXdsConfigLds.getXdsConfig()).isEqualTo(RAW_LISTENER);
416406

417407
// RDS.
418-
GenericXdsConfig genericXdsConfigRds = configDumps.get(RDS);
408+
GenericXdsConfig genericXdsConfigRds = configDumps.get(RDS.typeUrl());
419409
assertThat(genericXdsConfigRds.getClientStatus()).isEqualTo(ClientResourceStatus.ACKED);
420410
assertThat(genericXdsConfigRds.getVersionInfo()).isEqualTo(VERSION_ACK_RDS);
421411
assertThat(genericXdsConfigRds.getXdsConfig()).isEqualTo(RAW_ROUTE_CONFIGURATION);
422412

423413
// CDS.
424-
GenericXdsConfig genericXdsConfigCds = configDumps.get(CDS);
414+
GenericXdsConfig genericXdsConfigCds = configDumps.get(CDS.typeUrl());
425415
assertThat(genericXdsConfigCds.getClientStatus()).isEqualTo(ClientResourceStatus.ACKED);
426416
assertThat(genericXdsConfigCds.getVersionInfo()).isEqualTo(VERSION_ACK_CDS);
427417
assertThat(genericXdsConfigCds.getXdsConfig()).isEqualTo(RAW_CLUSTER);
428418

429419
// RDS.
430-
GenericXdsConfig genericXdsConfigEds = configDumps.get(EDS);
420+
GenericXdsConfig genericXdsConfigEds = configDumps.get(EDS.typeUrl());
431421
assertThat(genericXdsConfigEds.getClientStatus()).isEqualTo(ClientResourceStatus.ACKED);
432422
assertThat(genericXdsConfigEds.getVersionInfo()).isEqualTo(VERSION_ACK_EDS);
433423
assertThat(genericXdsConfigEds.getXdsConfig()).isEqualTo(RAW_CLUSTER_LOAD_ASSIGNMENT);
@@ -438,23 +428,11 @@ public void getClientConfigForXdsClient_noSubscribedResources() throws Interrupt
438428
ClientConfig clientConfig =
439429
CsdsService.getClientConfigForXdsClient(XDS_CLIENT_NO_RESOURCES, FAKE_CLIENT_SCOPE);
440430
verifyClientConfigNode(clientConfig);
441-
verifyClientConfigNoResources(XDS_CLIENT_NO_RESOURCES, clientConfig);
431+
assertThat(clientConfig.getGenericXdsConfigsList()).isEmpty();
442432
assertThat(clientConfig.getClientScope()).isEqualTo(FAKE_CLIENT_SCOPE);
443433
}
444434
}
445435

446-
/**
447-
* Assuming {@link MetadataToProtoTests} passes, and metadata converted to corresponding
448-
* config dumps correctly, perform a minimal verification of the general shape of ClientConfig.
449-
*/
450-
private static void verifyClientConfigNoResources(FakeXdsClient xdsClient,
451-
ClientConfig clientConfig) {
452-
int xdsConfigCount = clientConfig.getGenericXdsConfigsCount();
453-
assertThat(xdsConfigCount).isEqualTo(0);
454-
Map<XdsResourceType<?>, GenericXdsConfig> configDumps = mapConfigDumps(xdsClient, clientConfig);
455-
assertThat(configDumps).isEmpty();
456-
}
457-
458436
/**
459437
* Assuming {@link EnvoyProtoDataTest#convertNode} passes, perform a minimal check,
460438
* just verify the node itself is the one we expect.
@@ -465,21 +443,17 @@ private static void verifyClientConfigNode(ClientConfig clientConfig) {
465443
assertThat(node).isEqualTo(BOOTSTRAP_NODE.toEnvoyProtoNode());
466444
}
467445

468-
private static Map<XdsResourceType<?>, GenericXdsConfig> mapConfigDumps(FakeXdsClient client,
469-
ClientConfig config) {
470-
Map<XdsResourceType<?>, GenericXdsConfig> xdsConfigMap = new HashMap<>();
446+
private static Map<String, GenericXdsConfig> mapConfigDumps(ClientConfig config) {
447+
Map<String, GenericXdsConfig> xdsConfigMap = new HashMap<>();
471448
List<GenericXdsConfig> xdsConfigList = config.getGenericXdsConfigsList();
472449
for (GenericXdsConfig genericXdsConfig : xdsConfigList) {
473-
XdsResourceType<?> type = client.getSubscribedResourceTypesWithTypeUrl()
474-
.get(genericXdsConfig.getTypeUrl());
475-
assertThat(type).isNotNull();
476-
assertThat(xdsConfigMap).doesNotContainKey(type);
477-
xdsConfigMap.put(type, genericXdsConfig);
450+
assertThat(xdsConfigMap).doesNotContainKey(genericXdsConfig.getTypeUrl());
451+
xdsConfigMap.put(genericXdsConfig.getTypeUrl(), genericXdsConfig);
478452
}
479453
return xdsConfigMap;
480454
}
481455

482-
private static class FakeXdsClient extends XdsClient implements XdsClient.ResourceStore {
456+
private static class FakeXdsClient extends XdsClient {
483457
protected Map<XdsResourceType<?>, Map<String, ResourceMetadata>>
484458
getSubscribedResourcesMetadata() {
485459
return ImmutableMap.of();
@@ -495,24 +469,6 @@ private static class FakeXdsClient extends XdsClient implements XdsClient.Resour
495469
public BootstrapInfo getBootstrapInfo() {
496470
return BOOTSTRAP_INFO;
497471
}
498-
499-
@Nullable
500-
@Override
501-
public Collection<String> getSubscribedResources(
502-
ServerInfo serverInfo, XdsResourceType<? extends ResourceUpdate> type) {
503-
return null;
504-
}
505-
506-
@Override
507-
public void startMissingResourceTimers(Collection<String> resourceNames,
508-
XdsResourceType<?> resourceType) {
509-
// do nothing
510-
}
511-
512-
@Override
513-
public Map<String, XdsResourceType<?>> getSubscribedResourceTypesWithTypeUrl() {
514-
return ImmutableMap.of();
515-
}
516472
}
517473

518474
private static class FakeXdsClientPoolFactory implements XdsClientPoolFactory {

0 commit comments

Comments
 (0)