28
28
import static org .mockito .ArgumentMatchers .anyInt ;
29
29
import static org .mockito .ArgumentMatchers .anyLong ;
30
30
import static org .mockito .ArgumentMatchers .eq ;
31
+ import static org .mockito .Mockito .atLeast ;
31
32
import static org .mockito .Mockito .lenient ;
32
33
import static org .mockito .Mockito .mock ;
33
34
import static org .mockito .Mockito .never ;
@@ -449,7 +450,7 @@ public void resolving_ldsResourceUpdateRdsName() {
449
450
// Two new service config updates triggered:
450
451
// - with load balancing config being able to select cluster1 and cluster2
451
452
// - with load balancing config being able to select cluster2 only
452
- verify (mockListener , times (2 )).onResult2 (resultCaptor .capture ());
453
+ verify (mockListener , times (3 )).onResult2 (resultCaptor .capture ());
453
454
assertServiceConfigForLoadBalancingConfig (
454
455
Arrays .asList (cluster1 , cluster2 ),
455
456
(Map <String , ?>) resultCaptor .getAllValues ().get (0 ).getServiceConfig ().getConfig ());
@@ -1070,7 +1071,9 @@ public void resolved_resourceUpdateAfterCallStarted() {
1070
1071
assertCallSelectClusterResult (call1 , configSelector , "another-cluster" , 20.0 );
1071
1072
1072
1073
firstCall .deliverErrorStatus (); // completes previous call
1073
- verify (mockListener , times (2 )).onResult2 (resolutionResultCaptor .capture ());
1074
+ // Two updates: one for XdsNameResolver releasing the cluster, and another for
1075
+ // XdsDependencyManager updating the XdsConfig
1076
+ verify (mockListener , times (3 )).onResult2 (resolutionResultCaptor .capture ());
1074
1077
result = resolutionResultCaptor .getValue ();
1075
1078
assertServiceConfigForLoadBalancingConfig (
1076
1079
Arrays .asList (cluster2 , "another-cluster" ),
@@ -1100,7 +1103,7 @@ public void resolved_resourceUpdatedBeforeCallStarted() {
1100
1103
ImmutableMap .of ())));
1101
1104
// Two consecutive service config updates: one for removing clcuster1,
1102
1105
// one for adding "another=cluster".
1103
- verify (mockListener , times (2 )).onResult2 (resolutionResultCaptor .capture ());
1106
+ verify (mockListener , times (3 )).onResult2 (resolutionResultCaptor .capture ());
1104
1107
ResolutionResult result = resolutionResultCaptor .getValue ();
1105
1108
assertServiceConfigForLoadBalancingConfig (
1106
1109
Arrays .asList (cluster2 , "another-cluster" ),
@@ -1155,7 +1158,7 @@ public void resolved_raceBetweenCallAndRepeatedResourceUpdate() {
1155
1158
cluster2 , Collections .emptyList (),
1156
1159
TimeUnit .SECONDS .toNanos (15L ), null , false ),
1157
1160
ImmutableMap .of ())));
1158
- verifyNoMoreInteractions (mockListener ); // no cluster added/deleted
1161
+ verify (mockListener , times ( 2 )). onResult2 ( resolutionResultCaptor . capture ());
1159
1162
assertCallSelectClusterResult (call1 , configSelector , "another-cluster" , 15.0 );
1160
1163
}
1161
1164
@@ -1187,7 +1190,13 @@ public void resolved_raceBetweenClusterReleasedAndResourceUpdateAddBackAgain() {
1187
1190
null , false ),
1188
1191
ImmutableMap .of ())));
1189
1192
testCall .deliverErrorStatus ();
1190
- verifyNoMoreInteractions (mockListener );
1193
+ verify (mockListener , times (3 )).onResult2 (resolutionResultCaptor .capture ());
1194
+ assertServiceConfigForLoadBalancingConfig (
1195
+ Arrays .asList (cluster1 , cluster2 ), resolutionResultCaptor .getAllValues ().get (1 ));
1196
+ assertServiceConfigForLoadBalancingConfig (
1197
+ Arrays .asList (cluster1 , cluster2 ), resolutionResultCaptor .getAllValues ().get (2 ));
1198
+ assertServiceConfigForLoadBalancingConfig (
1199
+ Arrays .asList (cluster1 , cluster2 ), resolutionResultCaptor .getAllValues ().get (3 ));
1191
1200
}
1192
1201
1193
1202
@ SuppressWarnings ("unchecked" )
@@ -1268,7 +1277,7 @@ public void resolved_simpleCallSucceeds_routeToRls() {
1268
1277
"routeLookupConfig" ,
1269
1278
ImmutableMap .of ("lookupService" , "rls-cbt.googleapis.com" ),
1270
1279
"childPolicy" ,
1271
- ImmutableList .of (ImmutableMap .of ("cds_experimental" , ImmutableMap .of ())),
1280
+ ImmutableList .of (ImmutableMap .of ("cds_experimental" , ImmutableMap .of ("is_dynamic" , true ))),
1272
1281
"childPolicyConfigTargetFieldName" ,
1273
1282
"cluster" );
1274
1283
Map <String , ?> expectedClusterManagerLbConfig = ImmutableMap .of (
@@ -1315,7 +1324,7 @@ public void resolved_simpleCallSucceeds_routeToRls() {
1315
1324
"routeLookupConfig" ,
1316
1325
ImmutableMap .of ("lookupService" , "rls-cbt-2.googleapis.com" ),
1317
1326
"childPolicy" ,
1318
- ImmutableList .of (ImmutableMap .of ("cds_experimental" , ImmutableMap .of ())),
1327
+ ImmutableList .of (ImmutableMap .of ("cds_experimental" , ImmutableMap .of ("is_dynamic" , true ))),
1319
1328
"childPolicyConfigTargetFieldName" ,
1320
1329
"cluster" );
1321
1330
Map <String , ?> expectedClusterManagerLbConfig2 = ImmutableMap .of (
@@ -1656,7 +1665,7 @@ private void assertEmptyResolutionResult(String resource) {
1656
1665
}
1657
1666
1658
1667
private void assertClusterResolutionResult (CallInfo call , String expectedCluster ) {
1659
- verify (mockListener ).onResult2 (resolutionResultCaptor .capture ());
1668
+ verify (mockListener , atLeast ( 1 ) ).onResult2 (resolutionResultCaptor .capture ());
1660
1669
ResolutionResult result = resolutionResultCaptor .getValue ();
1661
1670
InternalConfigSelector configSelector = result .getAttributes ().get (InternalConfigSelector .KEY );
1662
1671
assertCallSelectClusterResult (call , configSelector , expectedCluster , null );
@@ -1744,6 +1753,13 @@ private InternalConfigSelector resolveToClusters() {
1744
1753
return result .getAttributes ().get (InternalConfigSelector .KEY );
1745
1754
}
1746
1755
1756
+ private static void assertServiceConfigForLoadBalancingConfig (
1757
+ List <String > clusters , ResolutionResult result ) {
1758
+ @ SuppressWarnings ("unchecked" )
1759
+ Map <String , ?> config = (Map <String , ?>) result .getServiceConfig ().getConfig ();
1760
+ assertServiceConfigForLoadBalancingConfig (clusters , config );
1761
+ }
1762
+
1747
1763
/**
1748
1764
* Verifies the raw service config contains an xDS load balancing config for the given clusters.
1749
1765
*/
@@ -1847,7 +1863,9 @@ public void generateServiceConfig_forClusterManagerLoadBalancingConfig() throws
1847
1863
+ " \" lookupService\" : \" rls.bigtable.google.com\" \n "
1848
1864
+ " },\n "
1849
1865
+ " \" childPolicy\" : [\n "
1850
- + " {\" cds_experimental\" : {}}\n "
1866
+ + " {\" cds_experimental\" : {\n "
1867
+ + " \" is_dynamic\" : true\n "
1868
+ + " }}\n "
1851
1869
+ " ],\n "
1852
1870
+ " \" childPolicyConfigTargetFieldName\" : \" cluster\" \n "
1853
1871
+ " }\n "
@@ -2035,7 +2053,7 @@ public void resolved_faultAbortInLdsUpdate() {
2035
2053
FaultAbort .forHeader (FaultConfig .FractionalPercent .perMillion (600_000 )),
2036
2054
null );
2037
2055
xdsClient .deliverLdsUpdateWithFaultInjection (cluster1 , httpFilterFaultConfig , null , null , null );
2038
- verify (mockListener ).onResult2 (resolutionResultCaptor .capture ());
2056
+ verify (mockListener , times ( 2 ) ).onResult2 (resolutionResultCaptor .capture ());
2039
2057
result = resolutionResultCaptor .getValue ();
2040
2058
configSelector = result .getAttributes ().get (InternalConfigSelector .KEY );
2041
2059
observer = startNewCall (TestMethodDescriptors .voidMethod (), configSelector ,
@@ -2051,7 +2069,7 @@ public void resolved_faultAbortInLdsUpdate() {
2051
2069
FaultAbort .forHeader (FaultConfig .FractionalPercent .perMillion (0 )),
2052
2070
null );
2053
2071
xdsClient .deliverLdsUpdateWithFaultInjection (cluster1 , httpFilterFaultConfig , null , null , null );
2054
- verify (mockListener ).onResult2 (resolutionResultCaptor .capture ());
2072
+ verify (mockListener , times ( 3 ) ).onResult2 (resolutionResultCaptor .capture ());
2055
2073
result = resolutionResultCaptor .getValue ();
2056
2074
configSelector = result .getAttributes ().get (InternalConfigSelector .KEY );
2057
2075
observer = startNewCall (TestMethodDescriptors .voidMethod (), configSelector ,
@@ -2066,7 +2084,7 @@ public void resolved_faultAbortInLdsUpdate() {
2066
2084
FaultConfig .FractionalPercent .perMillion (600_000 )),
2067
2085
null );
2068
2086
xdsClient .deliverLdsUpdateWithFaultInjection (cluster1 , httpFilterFaultConfig , null , null , null );
2069
- verify (mockListener ).onResult2 (resolutionResultCaptor .capture ());
2087
+ verify (mockListener , times ( 4 ) ).onResult2 (resolutionResultCaptor .capture ());
2070
2088
result = resolutionResultCaptor .getValue ();
2071
2089
configSelector = result .getAttributes ().get (InternalConfigSelector .KEY );
2072
2090
observer = startNewCall (TestMethodDescriptors .voidMethod (), configSelector ,
@@ -2084,7 +2102,7 @@ public void resolved_faultAbortInLdsUpdate() {
2084
2102
FaultConfig .FractionalPercent .perMillion (400_000 )),
2085
2103
null );
2086
2104
xdsClient .deliverLdsUpdateWithFaultInjection (cluster1 , httpFilterFaultConfig , null , null , null );
2087
- verify (mockListener ).onResult2 (resolutionResultCaptor .capture ());
2105
+ verify (mockListener , times ( 5 ) ).onResult2 (resolutionResultCaptor .capture ());
2088
2106
result = resolutionResultCaptor .getValue ();
2089
2107
configSelector = result .getAttributes ().get (InternalConfigSelector .KEY );
2090
2108
observer = startNewCall (TestMethodDescriptors .voidMethod (), configSelector ,
@@ -2119,7 +2137,7 @@ public void resolved_faultDelayInLdsUpdate() {
2119
2137
httpFilterFaultConfig = FaultConfig .create (
2120
2138
FaultDelay .forHeader (FaultConfig .FractionalPercent .perMillion (600_000 )), null , null );
2121
2139
xdsClient .deliverLdsUpdateWithFaultInjection (cluster1 , httpFilterFaultConfig , null , null , null );
2122
- verify (mockListener ).onResult2 (resolutionResultCaptor .capture ());
2140
+ verify (mockListener , times ( 2 ) ).onResult2 (resolutionResultCaptor .capture ());
2123
2141
result = resolutionResultCaptor .getValue ();
2124
2142
configSelector = result .getAttributes ().get (InternalConfigSelector .KEY );
2125
2143
observer = startNewCall (TestMethodDescriptors .voidMethod (), configSelector ,
@@ -2130,7 +2148,7 @@ public void resolved_faultDelayInLdsUpdate() {
2130
2148
httpFilterFaultConfig = FaultConfig .create (
2131
2149
FaultDelay .forHeader (FaultConfig .FractionalPercent .perMillion (0 )), null , null );
2132
2150
xdsClient .deliverLdsUpdateWithFaultInjection (cluster1 , httpFilterFaultConfig , null , null , null );
2133
- verify (mockListener ).onResult2 (resolutionResultCaptor .capture ());
2151
+ verify (mockListener , times ( 3 ) ).onResult2 (resolutionResultCaptor .capture ());
2134
2152
result = resolutionResultCaptor .getValue ();
2135
2153
configSelector = result .getAttributes ().get (InternalConfigSelector .KEY );
2136
2154
observer = startNewCall (TestMethodDescriptors .voidMethod (), configSelector ,
@@ -2143,7 +2161,7 @@ public void resolved_faultDelayInLdsUpdate() {
2143
2161
null ,
2144
2162
null );
2145
2163
xdsClient .deliverLdsUpdateWithFaultInjection (cluster1 , httpFilterFaultConfig , null , null , null );
2146
- verify (mockListener ).onResult2 (resolutionResultCaptor .capture ());
2164
+ verify (mockListener , times ( 4 ) ).onResult2 (resolutionResultCaptor .capture ());
2147
2165
result = resolutionResultCaptor .getValue ();
2148
2166
configSelector = result .getAttributes ().get (InternalConfigSelector .KEY );
2149
2167
observer = startNewCall (TestMethodDescriptors .voidMethod (), configSelector ,
@@ -2156,7 +2174,7 @@ public void resolved_faultDelayInLdsUpdate() {
2156
2174
null ,
2157
2175
null );
2158
2176
xdsClient .deliverLdsUpdateWithFaultInjection (cluster1 , httpFilterFaultConfig , null , null , null );
2159
- verify (mockListener ).onResult2 (resolutionResultCaptor .capture ());
2177
+ verify (mockListener , times ( 5 ) ).onResult2 (resolutionResultCaptor .capture ());
2160
2178
result = resolutionResultCaptor .getValue ();
2161
2179
configSelector = result .getAttributes ().get (InternalConfigSelector .KEY );
2162
2180
observer = startNewCall (TestMethodDescriptors .voidMethod (), configSelector ,
@@ -2281,7 +2299,7 @@ public void resolved_faultConfigOverrideInLdsUpdate() {
2281
2299
null );
2282
2300
xdsClient .deliverLdsUpdateWithFaultInjection (
2283
2301
cluster1 , httpFilterFaultConfig , virtualHostFaultConfig , routeFaultConfig , null );
2284
- verify (mockListener ).onResult2 (resolutionResultCaptor .capture ());
2302
+ verify (mockListener , times ( 2 ) ).onResult2 (resolutionResultCaptor .capture ());
2285
2303
result = resolutionResultCaptor .getValue ();
2286
2304
configSelector = result .getAttributes ().get (InternalConfigSelector .KEY );
2287
2305
observer = startNewCall (TestMethodDescriptors .voidMethod (), configSelector ,
@@ -2298,7 +2316,7 @@ public void resolved_faultConfigOverrideInLdsUpdate() {
2298
2316
xdsClient .deliverLdsUpdateWithFaultInjection (
2299
2317
cluster1 , httpFilterFaultConfig , virtualHostFaultConfig , routeFaultConfig ,
2300
2318
weightedClusterFaultConfig );
2301
- verify (mockListener ).onResult2 (resolutionResultCaptor .capture ());
2319
+ verify (mockListener , times ( 3 ) ).onResult2 (resolutionResultCaptor .capture ());
2302
2320
result = resolutionResultCaptor .getValue ();
2303
2321
configSelector = result .getAttributes ().get (InternalConfigSelector .KEY );
2304
2322
observer = startNewCall (TestMethodDescriptors .voidMethod (), configSelector ,
0 commit comments