134
134
import org .mockito .junit .MockitoJUnit ;
135
135
import org .mockito .junit .MockitoRule ;
136
136
import org .mockito .stubbing .Answer ;
137
+ import org .mockito .verification .VerificationMode ;
137
138
138
139
/**
139
140
* Tests for {@link XdsClientImpl}.
@@ -2766,8 +2767,7 @@ public void edsCleanupNonceAfterUnsubscription() {
2766
2767
xdsClient .watchXdsResource (XdsEndpointResource .getInstance (), "A.1" , edsResourceWatcher );
2767
2768
DiscoveryRpcCall call = resourceDiscoveryCalls .poll ();
2768
2769
assertThat (call ).isNotNull ();
2769
- verifyResourceMetadataRequested (EDS , "A.1" );
2770
- verifySubscribedResourcesMetadataSizes (0 , 0 , 0 , 1 );
2770
+ call .verifyRequest (EDS , "A.1" , "" , "" , NODE );
2771
2771
2772
2772
// EDS -> {A.1}, version 1
2773
2773
List <Message > dropOverloads = ImmutableList .of ();
@@ -2776,19 +2776,17 @@ public void edsCleanupNonceAfterUnsubscription() {
2776
2776
"A.1" , Any .pack (mf .buildClusterLoadAssignment ("A.1" , endpointsV1 , dropOverloads )));
2777
2777
call .sendResponse (EDS , resourcesV1 .values ().asList (), VERSION_1 , "0000" );
2778
2778
// {A.1} -> ACK, version 1
2779
- verifyResourceMetadataAcked (EDS , "A.1" , resourcesV1 .get ("A.1" ), VERSION_1 , TIME_INCREMENT );
2780
2779
call .verifyRequest (EDS , "A.1" , VERSION_1 , "0000" , NODE );
2781
2780
verify (edsResourceWatcher , times (1 )).onChanged (any ());
2782
2781
2783
2782
// trigger an EDS resource unsubscription.
2784
- // This would probably be caused by CDS PUSH(let's say event e1) in the real world.
2785
- // Then there can be a potential data race between
2786
- // 1) the EDS unsubscription caused by CDS PUSH e1 (client-side) and,
2787
- // 2) the immediate EDS PUSH from XdsServer (server-side) after CDS PUSH e1 (event e2).
2788
2783
xdsClient .cancelXdsResourceWatch (XdsEndpointResource .getInstance (), "A.1" , edsResourceWatcher );
2789
2784
verifySubscribedResourcesMetadataSizes (0 , 0 , 0 , 0 );
2790
- // The nonce has been removed
2791
- assertThat (getNonceForResourceType (xdsClient , xdsServerInfo , EDS )).isNull ();
2785
+
2786
+ // When re-subscribing, the version and nonce were properly forgotten, so the request is the
2787
+ // same as the initial request
2788
+ xdsClient .watchXdsResource (XdsEndpointResource .getInstance (), "A.1" , edsResourceWatcher );
2789
+ call .verifyRequest (EDS , "A.1" , "" , "" , NODE , Mockito .timeout (2000 ).times (2 ));
2792
2790
}
2793
2791
2794
2792
@ Test
@@ -3821,10 +3819,22 @@ protected abstract static class DiscoveryRpcCall {
3821
3819
3822
3820
protected void verifyRequest (
3823
3821
XdsResourceType <?> type , List <String > resources , String versionInfo , String nonce ,
3824
- Node node ) {
3822
+ Node node , VerificationMode verificationMode ) {
3825
3823
throw new UnsupportedOperationException ();
3826
3824
}
3827
3825
3826
+ protected void verifyRequest (
3827
+ XdsResourceType <?> type , List <String > resources , String versionInfo , String nonce ,
3828
+ Node node ) {
3829
+ verifyRequest (type , resources , versionInfo , nonce , node , Mockito .timeout (2000 ));
3830
+ }
3831
+
3832
+ protected void verifyRequest (
3833
+ XdsResourceType <?> type , String resource , String versionInfo , String nonce ,
3834
+ Node node , VerificationMode verificationMode ) {
3835
+ verifyRequest (type , ImmutableList .of (resource ), versionInfo , nonce , node , verificationMode );
3836
+ }
3837
+
3828
3838
protected void verifyRequest (
3829
3839
XdsResourceType <?> type , String resource , String versionInfo , String nonce , Node node ) {
3830
3840
verifyRequest (type , ImmutableList .of (resource ), versionInfo , nonce , node );
0 commit comments