Skip to content

Commit c8fa46c

Browse files
committed
add testing methods
1 parent b61742c commit c8fa46c

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ boolean isReady() {
205205
return adsStream != null && adsStream.call != null && adsStream.call.isReady();
206206
}
207207

208+
@Nullable
209+
@VisibleForTesting
210+
Map<XdsResourceType<?>, String> getNonce() {
211+
if (adsStream == null) {
212+
return null;
213+
}
214+
return adsStream.respNonces;
215+
}
216+
208217
/**
209218
* Starts a timer for each requested resource that hasn't been responded to and
210219
* has been waiting for the channel to get ready.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void uncaughtException(Thread t, Throwable e) {
8484
final Map<ServerInfo, LoadReportClient> serverLrsClientMap =
8585
new HashMap<>();
8686

87-
private final Map<ServerInfo, ControlPlaneClient> serverCpClientMap = new HashMap<>();
87+
final Map<ServerInfo, ControlPlaneClient> serverCpClientMap = new HashMap<>();
8888
private final Map<XdsResourceType<? extends ResourceUpdate>,
8989
Map<String, ResourceSubscriber<? extends ResourceUpdate>>>
9090
resourceSubscribers = new HashMap<>();

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import io.grpc.xds.client.Bootstrapper.BootstrapInfo;
8888
import io.grpc.xds.client.Bootstrapper.CertificateProviderInfo;
8989
import io.grpc.xds.client.Bootstrapper.ServerInfo;
90+
import io.grpc.xds.client.ControlPlaneClientTestBase;
9091
import io.grpc.xds.client.EnvoyProtoData.Node;
9192
import io.grpc.xds.client.LoadStatsManager2.ClusterDropStats;
9293
import io.grpc.xds.client.Locality;
@@ -140,7 +141,7 @@
140141
@RunWith(JUnit4.class)
141142
// The base class was used to test both xds v2 and v3. V2 is dropped now so the base class is not
142143
// necessary. Still keep it for future version usage. Remove if too much trouble to maintain.
143-
public abstract class GrpcXdsClientImplTestBase {
144+
public abstract class GrpcXdsClientImplTestBase extends ControlPlaneClientTestBase {
144145
private static final String SERVER_URI = "trafficdirector.googleapis.com";
145146
private static final String SERVER_URI_CUSTOME_AUTHORITY = "trafficdirector2.googleapis.com";
146147
private static final String SERVER_URI_EMPTY_AUTHORITY = "trafficdirector3.googleapis.com";
@@ -2758,7 +2759,7 @@ public void edsResourceNotFound() {
27582759
}
27592760

27602761
@Test
2761-
public void edsAllowRespondAfterUnsubscription() {
2762+
public void edsCleanupNonceAfterUnsubscription() {
27622763
Assume.assumeFalse(ignoreResourceDeletion());
27632764

27642765
// Suppose we have an EDS subscription A.1
@@ -2776,6 +2777,7 @@ public void edsAllowRespondAfterUnsubscription() {
27762777
call.sendResponse(EDS, resourcesV1.values().asList(), VERSION_1, "0000");
27772778
// {A.1} -> ACK, version 1
27782779
verifyResourceMetadataAcked(EDS, "A.1", resourcesV1.get("A.1"), VERSION_1, TIME_INCREMENT);
2780+
call.verifyRequest(EDS, "A.1", VERSION_1, "0000", NODE);
27792781
verify(edsResourceWatcher, times(1)).onChanged(any());
27802782

27812783
// trigger an EDS resource unsubscription.
@@ -2784,17 +2786,9 @@ public void edsAllowRespondAfterUnsubscription() {
27842786
// 1) the EDS unsubscription caused by CDS PUSH e1 (client-side) and,
27852787
// 2) the immediate EDS PUSH from XdsServer (server-side) after CDS PUSH e1 (event e2).
27862788
xdsClient.cancelXdsResourceWatch(XdsEndpointResource.getInstance(), "A.1", edsResourceWatcher);
2787-
// FIX(1): allow to send empty subscription
2788-
call.verifyRequest(EDS, Collections.emptyList(), VERSION_1, "0000", NODE);
27892789
verifySubscribedResourcesMetadataSizes(0, 0, 0, 0);
2790-
// An EDS PUSH after CDS PUSH e1.
2791-
List<Message> endpointsV2 = ImmutableList.of(lbEndpointHealthy);
2792-
ImmutableMap<String, Any> resourcesV2 = ImmutableMap.of(
2793-
"A.1", Any.pack(mf.buildClusterLoadAssignment("A.1", endpointsV2, dropOverloads)));
2794-
call.sendResponse(EDS, resourcesV2.values().asList(), VERSION_2, "0001");
2795-
// FIX(2): allow to update resource version even if the subscription resource is empty
2796-
call.verifyRequest(EDS, Collections.emptyList(), VERSION_2, "0001", NODE);
2797-
verifyNoMoreInteractions(edsResourceWatcher);
2790+
// The nonce has been removed
2791+
assertThat(getNonceForResourceType(xdsClient, xdsServerInfo, EDS)).isNull();
27982792
}
27992793

28002794
@Test
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2024 The gRPC Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.grpc.xds.client;
18+
19+
import java.util.Map;
20+
21+
public abstract class ControlPlaneClientTestBase {
22+
protected static String getNonceForResourceType(XdsClientImpl xdsClient, Bootstrapper.ServerInfo serverInfo, XdsResourceType<?> type) {
23+
ControlPlaneClient controlPlaneClient = xdsClient.serverCpClientMap.get(serverInfo);
24+
Map<XdsResourceType<?>, String> nonceMap = controlPlaneClient.getNonce();
25+
if (nonceMap == null) {
26+
return null;
27+
}
28+
return nonceMap.get(type);
29+
}
30+
}

0 commit comments

Comments
 (0)