36
36
import io .envoyproxy .envoy .config .cluster .v3 .LoadBalancingPolicy ;
37
37
import io .envoyproxy .envoy .config .cluster .v3 .LoadBalancingPolicy .Policy ;
38
38
import io .envoyproxy .envoy .config .core .v3 .TypedExtensionConfig ;
39
+ import io .envoyproxy .envoy .extensions .load_balancing_policies .least_request .v3 .LeastRequest ;
39
40
import io .envoyproxy .envoy .extensions .load_balancing_policies .ring_hash .v3 .RingHash ;
40
41
import io .envoyproxy .envoy .extensions .load_balancing_policies .round_robin .v3 .RoundRobin ;
41
42
import io .envoyproxy .envoy .extensions .load_balancing_policies .wrr_locality .v3 .WrrLocality ;
@@ -71,6 +72,12 @@ public class LoadBalancerConfigFactoryTest {
71
72
.setMaximumRingSize (UInt64Value .of (RING_HASH_MAX_RING_SIZE ))
72
73
.setHashFunction (RingHash .HashFunction .XX_HASH ).build ()))).build ();
73
74
75
+ private static final int LEAST_REQUEST_CHOICE_COUNT = 10 ;
76
+ private static final Policy LEAST_REQUEST_POLICY = Policy .newBuilder ().setTypedExtensionConfig (
77
+ TypedExtensionConfig .newBuilder ().setTypedConfig (Any .pack (
78
+ LeastRequest .newBuilder ().setChoiceCount (UInt32Value .of (LEAST_REQUEST_CHOICE_COUNT ))
79
+ .build ()))).build ();
80
+
74
81
private static final String CUSTOM_POLICY_NAME = "myorg.MyCustomLeastRequestPolicy" ;
75
82
private static final String CUSTOM_POLICY_FIELD_KEY = "choiceCount" ;
76
83
private static final double CUSTOM_POLICY_FIELD_VALUE = 2 ;
@@ -103,6 +110,9 @@ public class LoadBalancerConfigFactoryTest {
103
110
"wrr_locality_experimental" , ImmutableMap .of ("childPolicy" , ImmutableList .of (
104
111
ImmutableMap .of (VALID_CUSTOM_CONFIG .getPolicyName (),
105
112
VALID_CUSTOM_CONFIG .getRawConfigValue ()))));
113
+ private static final LbConfig VALID_LEAST_REQUEST_CONFIG = new LbConfig (
114
+ "least_request_experimental" ,
115
+ ImmutableMap .of ("choiceCount" , (double ) LEAST_REQUEST_CHOICE_COUNT ));
106
116
107
117
@ After
108
118
public void deregisterCustomProvider () {
@@ -162,13 +172,23 @@ public void ringHash_invalidHash_legacy() {
162
172
assertResourceInvalidExceptionThrown (cluster , true , true , "invalid ring hash function" );
163
173
}
164
174
175
+ @ Test
176
+ public void leastRequest () throws ResourceInvalidException {
177
+ Cluster cluster = Cluster .newBuilder ()
178
+ .setLoadBalancingPolicy (LoadBalancingPolicy .newBuilder ().addPolicies (LEAST_REQUEST_POLICY ))
179
+ .build ();
180
+
181
+ assertThat (newLbConfig (cluster , true , true )).isEqualTo (VALID_LEAST_REQUEST_CONFIG );
182
+ }
183
+
165
184
@ Test
166
185
public void leastRequest_legacy () throws ResourceInvalidException {
167
186
System .setProperty ("io.grpc.xds.experimentalEnableLeastRequest" , "true" );
168
187
169
188
Cluster cluster = Cluster .newBuilder ().setLbPolicy (LbPolicy .LEAST_REQUEST )
170
189
.setLeastRequestLbConfig (
171
- LeastRequestLbConfig .newBuilder ().setChoiceCount (UInt32Value .of (10 ))).build ();
190
+ LeastRequestLbConfig .newBuilder ()
191
+ .setChoiceCount (UInt32Value .of (LEAST_REQUEST_CHOICE_COUNT ))).build ();
172
192
173
193
LbConfig lbConfig = newLbConfig (cluster , true , true );
174
194
assertThat (lbConfig .getPolicyName ()).isEqualTo ("wrr_locality_experimental" );
@@ -178,7 +198,7 @@ public void leastRequest_legacy() throws ResourceInvalidException {
178
198
assertThat (childConfigs .get (0 ).getPolicyName ()).isEqualTo ("least_request_experimental" );
179
199
assertThat (
180
200
JsonUtil .getNumberAsLong (childConfigs .get (0 ).getRawConfigValue (), "choiceCount" )).isEqualTo (
181
- 10 );
201
+ LEAST_REQUEST_CHOICE_COUNT );
182
202
}
183
203
184
204
@ Test
0 commit comments