mirror of https://github.com/grpc/grpc-java.git
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.
This commit is contained in:
parent
bac8b32043
commit
9a712c3f77
|
@ -428,7 +428,7 @@ public abstract class XdsClient {
|
||||||
void handleStreamClosed(Status error, boolean shouldTryFallback);
|
void handleStreamClosed(Status error, boolean shouldTryFallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ResourceStore {
|
interface ResourceStore {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the collection of resources currently subscribed to which have an authority matching
|
* Returns the collection of resources currently subscribed to which have an authority matching
|
||||||
|
|
|
@ -299,7 +299,7 @@ public class CsdsServiceTest {
|
||||||
assertThat(response.getConfigCount()).isEqualTo(1);
|
assertThat(response.getConfigCount()).isEqualTo(1);
|
||||||
ClientConfig clientConfig = response.getConfig(0);
|
ClientConfig clientConfig = response.getConfig(0);
|
||||||
verifyClientConfigNode(clientConfig);
|
verifyClientConfigNode(clientConfig);
|
||||||
verifyClientConfigNoResources(XDS_CLIENT_NO_RESOURCES, clientConfig);
|
assertThat(clientConfig.getGenericXdsConfigsList()).isEmpty();
|
||||||
assertThat(clientConfig.getClientScope()).isEmpty();
|
assertThat(clientConfig.getClientScope()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,7 +310,7 @@ public class CsdsServiceTest {
|
||||||
for (int i = 0; i < numExpected; i++) {
|
for (int i = 0; i < numExpected; i++) {
|
||||||
ClientConfig clientConfig = response.getConfig(i);
|
ClientConfig clientConfig = response.getConfig(i);
|
||||||
verifyClientConfigNode(clientConfig);
|
verifyClientConfigNode(clientConfig);
|
||||||
verifyClientConfigNoResources(XDS_CLIENT_NO_RESOURCES, clientConfig);
|
assertThat(clientConfig.getGenericXdsConfigsList()).isEmpty();
|
||||||
clientScopes.add(clientConfig.getClientScope());
|
clientScopes.add(clientConfig.getClientScope());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,16 +382,6 @@ public class CsdsServiceTest {
|
||||||
.put(EDS, ImmutableMap.of("subscribedResourceName.EDS", METADATA_ACKED_EDS))
|
.put(EDS, ImmutableMap.of("subscribedResourceName.EDS", METADATA_ACKED_EDS))
|
||||||
.buildOrThrow();
|
.buildOrThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, XdsResourceType<?>> getSubscribedResourceTypesWithTypeUrl() {
|
|
||||||
return ImmutableMap.of(
|
|
||||||
LDS.typeUrl(), LDS,
|
|
||||||
RDS.typeUrl(), RDS,
|
|
||||||
CDS.typeUrl(), CDS,
|
|
||||||
EDS.typeUrl(), EDS
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
ClientConfig clientConfig = CsdsService.getClientConfigForXdsClient(fakeXdsClient,
|
ClientConfig clientConfig = CsdsService.getClientConfigForXdsClient(fakeXdsClient,
|
||||||
FAKE_CLIENT_SCOPE);
|
FAKE_CLIENT_SCOPE);
|
||||||
|
@ -403,31 +393,31 @@ public class CsdsServiceTest {
|
||||||
// is propagated to the correct resource types.
|
// is propagated to the correct resource types.
|
||||||
int xdsConfigCount = clientConfig.getGenericXdsConfigsCount();
|
int xdsConfigCount = clientConfig.getGenericXdsConfigsCount();
|
||||||
assertThat(xdsConfigCount).isEqualTo(4);
|
assertThat(xdsConfigCount).isEqualTo(4);
|
||||||
Map<XdsResourceType<?>, GenericXdsConfig> configDumps = mapConfigDumps(fakeXdsClient,
|
Map<String, GenericXdsConfig> configDumps = mapConfigDumps(clientConfig);
|
||||||
clientConfig);
|
assertThat(configDumps.keySet())
|
||||||
assertThat(configDumps.keySet()).containsExactly(LDS, RDS, CDS, EDS);
|
.containsExactly(LDS.typeUrl(), RDS.typeUrl(), CDS.typeUrl(), EDS.typeUrl());
|
||||||
|
|
||||||
// LDS.
|
// LDS.
|
||||||
GenericXdsConfig genericXdsConfigLds = configDumps.get(LDS);
|
GenericXdsConfig genericXdsConfigLds = configDumps.get(LDS.typeUrl());
|
||||||
assertThat(genericXdsConfigLds.getName()).isEqualTo("subscribedResourceName.LDS");
|
assertThat(genericXdsConfigLds.getName()).isEqualTo("subscribedResourceName.LDS");
|
||||||
assertThat(genericXdsConfigLds.getClientStatus()).isEqualTo(ClientResourceStatus.ACKED);
|
assertThat(genericXdsConfigLds.getClientStatus()).isEqualTo(ClientResourceStatus.ACKED);
|
||||||
assertThat(genericXdsConfigLds.getVersionInfo()).isEqualTo(VERSION_ACK_LDS);
|
assertThat(genericXdsConfigLds.getVersionInfo()).isEqualTo(VERSION_ACK_LDS);
|
||||||
assertThat(genericXdsConfigLds.getXdsConfig()).isEqualTo(RAW_LISTENER);
|
assertThat(genericXdsConfigLds.getXdsConfig()).isEqualTo(RAW_LISTENER);
|
||||||
|
|
||||||
// RDS.
|
// RDS.
|
||||||
GenericXdsConfig genericXdsConfigRds = configDumps.get(RDS);
|
GenericXdsConfig genericXdsConfigRds = configDumps.get(RDS.typeUrl());
|
||||||
assertThat(genericXdsConfigRds.getClientStatus()).isEqualTo(ClientResourceStatus.ACKED);
|
assertThat(genericXdsConfigRds.getClientStatus()).isEqualTo(ClientResourceStatus.ACKED);
|
||||||
assertThat(genericXdsConfigRds.getVersionInfo()).isEqualTo(VERSION_ACK_RDS);
|
assertThat(genericXdsConfigRds.getVersionInfo()).isEqualTo(VERSION_ACK_RDS);
|
||||||
assertThat(genericXdsConfigRds.getXdsConfig()).isEqualTo(RAW_ROUTE_CONFIGURATION);
|
assertThat(genericXdsConfigRds.getXdsConfig()).isEqualTo(RAW_ROUTE_CONFIGURATION);
|
||||||
|
|
||||||
// CDS.
|
// CDS.
|
||||||
GenericXdsConfig genericXdsConfigCds = configDumps.get(CDS);
|
GenericXdsConfig genericXdsConfigCds = configDumps.get(CDS.typeUrl());
|
||||||
assertThat(genericXdsConfigCds.getClientStatus()).isEqualTo(ClientResourceStatus.ACKED);
|
assertThat(genericXdsConfigCds.getClientStatus()).isEqualTo(ClientResourceStatus.ACKED);
|
||||||
assertThat(genericXdsConfigCds.getVersionInfo()).isEqualTo(VERSION_ACK_CDS);
|
assertThat(genericXdsConfigCds.getVersionInfo()).isEqualTo(VERSION_ACK_CDS);
|
||||||
assertThat(genericXdsConfigCds.getXdsConfig()).isEqualTo(RAW_CLUSTER);
|
assertThat(genericXdsConfigCds.getXdsConfig()).isEqualTo(RAW_CLUSTER);
|
||||||
|
|
||||||
// RDS.
|
// RDS.
|
||||||
GenericXdsConfig genericXdsConfigEds = configDumps.get(EDS);
|
GenericXdsConfig genericXdsConfigEds = configDumps.get(EDS.typeUrl());
|
||||||
assertThat(genericXdsConfigEds.getClientStatus()).isEqualTo(ClientResourceStatus.ACKED);
|
assertThat(genericXdsConfigEds.getClientStatus()).isEqualTo(ClientResourceStatus.ACKED);
|
||||||
assertThat(genericXdsConfigEds.getVersionInfo()).isEqualTo(VERSION_ACK_EDS);
|
assertThat(genericXdsConfigEds.getVersionInfo()).isEqualTo(VERSION_ACK_EDS);
|
||||||
assertThat(genericXdsConfigEds.getXdsConfig()).isEqualTo(RAW_CLUSTER_LOAD_ASSIGNMENT);
|
assertThat(genericXdsConfigEds.getXdsConfig()).isEqualTo(RAW_CLUSTER_LOAD_ASSIGNMENT);
|
||||||
|
@ -438,23 +428,11 @@ public class CsdsServiceTest {
|
||||||
ClientConfig clientConfig =
|
ClientConfig clientConfig =
|
||||||
CsdsService.getClientConfigForXdsClient(XDS_CLIENT_NO_RESOURCES, FAKE_CLIENT_SCOPE);
|
CsdsService.getClientConfigForXdsClient(XDS_CLIENT_NO_RESOURCES, FAKE_CLIENT_SCOPE);
|
||||||
verifyClientConfigNode(clientConfig);
|
verifyClientConfigNode(clientConfig);
|
||||||
verifyClientConfigNoResources(XDS_CLIENT_NO_RESOURCES, clientConfig);
|
assertThat(clientConfig.getGenericXdsConfigsList()).isEmpty();
|
||||||
assertThat(clientConfig.getClientScope()).isEqualTo(FAKE_CLIENT_SCOPE);
|
assertThat(clientConfig.getClientScope()).isEqualTo(FAKE_CLIENT_SCOPE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Assuming {@link MetadataToProtoTests} passes, and metadata converted to corresponding
|
|
||||||
* config dumps correctly, perform a minimal verification of the general shape of ClientConfig.
|
|
||||||
*/
|
|
||||||
private static void verifyClientConfigNoResources(FakeXdsClient xdsClient,
|
|
||||||
ClientConfig clientConfig) {
|
|
||||||
int xdsConfigCount = clientConfig.getGenericXdsConfigsCount();
|
|
||||||
assertThat(xdsConfigCount).isEqualTo(0);
|
|
||||||
Map<XdsResourceType<?>, GenericXdsConfig> configDumps = mapConfigDumps(xdsClient, clientConfig);
|
|
||||||
assertThat(configDumps).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assuming {@link EnvoyProtoDataTest#convertNode} passes, perform a minimal check,
|
* Assuming {@link EnvoyProtoDataTest#convertNode} passes, perform a minimal check,
|
||||||
* just verify the node itself is the one we expect.
|
* just verify the node itself is the one we expect.
|
||||||
|
@ -465,21 +443,17 @@ public class CsdsServiceTest {
|
||||||
assertThat(node).isEqualTo(BOOTSTRAP_NODE.toEnvoyProtoNode());
|
assertThat(node).isEqualTo(BOOTSTRAP_NODE.toEnvoyProtoNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<XdsResourceType<?>, GenericXdsConfig> mapConfigDumps(FakeXdsClient client,
|
private static Map<String, GenericXdsConfig> mapConfigDumps(ClientConfig config) {
|
||||||
ClientConfig config) {
|
Map<String, GenericXdsConfig> xdsConfigMap = new HashMap<>();
|
||||||
Map<XdsResourceType<?>, GenericXdsConfig> xdsConfigMap = new HashMap<>();
|
|
||||||
List<GenericXdsConfig> xdsConfigList = config.getGenericXdsConfigsList();
|
List<GenericXdsConfig> xdsConfigList = config.getGenericXdsConfigsList();
|
||||||
for (GenericXdsConfig genericXdsConfig : xdsConfigList) {
|
for (GenericXdsConfig genericXdsConfig : xdsConfigList) {
|
||||||
XdsResourceType<?> type = client.getSubscribedResourceTypesWithTypeUrl()
|
assertThat(xdsConfigMap).doesNotContainKey(genericXdsConfig.getTypeUrl());
|
||||||
.get(genericXdsConfig.getTypeUrl());
|
xdsConfigMap.put(genericXdsConfig.getTypeUrl(), genericXdsConfig);
|
||||||
assertThat(type).isNotNull();
|
|
||||||
assertThat(xdsConfigMap).doesNotContainKey(type);
|
|
||||||
xdsConfigMap.put(type, genericXdsConfig);
|
|
||||||
}
|
}
|
||||||
return xdsConfigMap;
|
return xdsConfigMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FakeXdsClient extends XdsClient implements XdsClient.ResourceStore {
|
private static class FakeXdsClient extends XdsClient {
|
||||||
protected Map<XdsResourceType<?>, Map<String, ResourceMetadata>>
|
protected Map<XdsResourceType<?>, Map<String, ResourceMetadata>>
|
||||||
getSubscribedResourcesMetadata() {
|
getSubscribedResourcesMetadata() {
|
||||||
return ImmutableMap.of();
|
return ImmutableMap.of();
|
||||||
|
@ -495,24 +469,6 @@ public class CsdsServiceTest {
|
||||||
public BootstrapInfo getBootstrapInfo() {
|
public BootstrapInfo getBootstrapInfo() {
|
||||||
return BOOTSTRAP_INFO;
|
return BOOTSTRAP_INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public Collection<String> getSubscribedResources(
|
|
||||||
ServerInfo serverInfo, XdsResourceType<? extends ResourceUpdate> type) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startMissingResourceTimers(Collection<String> resourceNames,
|
|
||||||
XdsResourceType<?> resourceType) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, XdsResourceType<?>> getSubscribedResourceTypesWithTypeUrl() {
|
|
||||||
return ImmutableMap.of();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FakeXdsClientPoolFactory implements XdsClientPoolFactory {
|
private static class FakeXdsClientPoolFactory implements XdsClientPoolFactory {
|
||||||
|
|
Loading…
Reference in New Issue