@@ -26,18 +26,20 @@ import (
26
26
"github.com/google/go-cmp/cmp"
27
27
"github.com/google/go-cmp/cmp/cmpopts"
28
28
"google.golang.org/grpc/balancer/leastrequest"
29
- _ "google.golang.org/grpc/balancer/roundrobin" // To register round_robin load balancer.
30
29
"google.golang.org/grpc/internal/balancer/stub"
31
30
"google.golang.org/grpc/internal/envconfig"
32
31
"google.golang.org/grpc/internal/grpctest"
33
32
iserviceconfig "google.golang.org/grpc/internal/serviceconfig"
34
33
"google.golang.org/grpc/internal/testutils"
35
34
"google.golang.org/grpc/internal/testutils/xds/e2e"
35
+ "google.golang.org/grpc/internal/xds/bootstrap"
36
36
"google.golang.org/grpc/serviceconfig"
37
- _ "google.golang.org/grpc/xds" // Register the xDS LB Registry Converters.
38
37
"google.golang.org/grpc/xds/internal/balancer/ringhash"
39
38
"google.golang.org/grpc/xds/internal/balancer/wrrlocality"
40
39
"google.golang.org/grpc/xds/internal/xdsclient/xdsresource"
40
+ "google.golang.org/protobuf/proto"
41
+ "google.golang.org/protobuf/types/known/anypb"
42
+ "google.golang.org/protobuf/types/known/structpb"
41
43
"google.golang.org/protobuf/types/known/wrapperspb"
42
44
43
45
v3xdsxdstypepb "github.com/cncf/xds/go/xds/type/v3"
@@ -48,9 +50,9 @@ import (
48
50
v3ringhashpb "github.com/envoyproxy/go-control-plane/envoy/extensions/load_balancing_policies/ring_hash/v3"
49
51
v3roundrobinpb "github.com/envoyproxy/go-control-plane/envoy/extensions/load_balancing_policies/round_robin/v3"
50
52
v3wrrlocalitypb "github.com/envoyproxy/go-control-plane/envoy/extensions/load_balancing_policies/wrr_locality/v3"
51
- "google.golang.org/protobuf/proto"
52
- "google.golang.org/protobuf/types/known/anypb"
53
- "google.golang.org/protobuf/types/known/structpb"
53
+
54
+ _ "google.golang.org/grpc/balancer/roundrobin" // To register round_robin load balancer.
55
+ _ "google.golang.org/grpc/xds" // Register the xDS LB Registry Converters.
54
56
)
55
57
56
58
type s struct {
@@ -66,8 +68,6 @@ const (
66
68
serviceName = "service"
67
69
)
68
70
69
- var emptyUpdate = xdsresource.ClusterUpdate {ClusterName : clusterName , LRSServerConfig : xdsresource .ClusterLRSOff }
70
-
71
71
func wrrLocality (t * testing.T , m proto.Message ) * v3wrrlocalitypb.WrrLocality {
72
72
return & v3wrrlocalitypb.WrrLocality {
73
73
EndpointPickingPolicy : & v3clusterpb.LoadBalancingPolicy {
@@ -105,6 +105,7 @@ func (s) TestValidateCluster_Success(t *testing.T) {
105
105
tests := []struct {
106
106
name string
107
107
cluster * v3clusterpb.Cluster
108
+ serverCfg * bootstrap.ServerConfig
108
109
wantUpdate xdsresource.ClusterUpdate
109
110
wantLBConfig * iserviceconfig.BalancerConfig
110
111
}{
@@ -164,7 +165,8 @@ func (s) TestValidateCluster_Success(t *testing.T) {
164
165
LbPolicy : v3clusterpb .Cluster_ROUND_ROBIN ,
165
166
},
166
167
wantUpdate : xdsresource.ClusterUpdate {
167
- ClusterName : clusterName , LRSServerConfig : xdsresource .ClusterLRSOff , ClusterType : xdsresource .ClusterTypeAggregate ,
168
+ ClusterName : clusterName ,
169
+ ClusterType : xdsresource .ClusterTypeAggregate ,
168
170
PrioritizedClusterNames : []string {"a" , "b" , "c" },
169
171
},
170
172
wantLBConfig : & iserviceconfig.BalancerConfig {
@@ -179,7 +181,7 @@ func (s) TestValidateCluster_Success(t *testing.T) {
179
181
{
180
182
name : "happy-case-no-service-name-no-lrs" ,
181
183
cluster : e2e .DefaultCluster (clusterName , "" , e2e .SecurityLevelNone ),
182
- wantUpdate : emptyUpdate ,
184
+ wantUpdate : xdsresource. ClusterUpdate { ClusterName : clusterName } ,
183
185
wantLBConfig : & iserviceconfig.BalancerConfig {
184
186
Name : wrrlocality .Name ,
185
187
Config : & wrrlocality.LBConfig {
@@ -206,16 +208,17 @@ func (s) TestValidateCluster_Success(t *testing.T) {
206
208
},
207
209
},
208
210
{
209
- name : "happiest-case" ,
211
+ name : "happiest-case-with-lrs " ,
210
212
cluster : e2e .ClusterResourceWithOptions (e2e.ClusterOptions {
211
213
ClusterName : clusterName ,
212
214
ServiceName : serviceName ,
213
215
EnableLRS : true ,
214
216
}),
217
+ serverCfg : & bootstrap.ServerConfig {ServerURI : "test-server-uri" },
215
218
wantUpdate : xdsresource.ClusterUpdate {
216
219
ClusterName : clusterName ,
217
220
EDSServiceName : serviceName ,
218
- LRSServerConfig : xdsresource . ClusterLRSServerSelf ,
221
+ LRSServerConfig : & bootstrap. ServerConfig { ServerURI : "test-server-uri" } ,
219
222
},
220
223
wantLBConfig : & iserviceconfig.BalancerConfig {
221
224
Name : wrrlocality .Name ,
@@ -248,10 +251,11 @@ func (s) TestValidateCluster_Success(t *testing.T) {
248
251
}
249
252
return c
250
253
}(),
254
+ serverCfg : & bootstrap.ServerConfig {ServerURI : "test-server-uri" },
251
255
wantUpdate : xdsresource.ClusterUpdate {
252
256
ClusterName : clusterName ,
253
257
EDSServiceName : serviceName ,
254
- LRSServerConfig : xdsresource . ClusterLRSServerSelf ,
258
+ LRSServerConfig : & bootstrap. ServerConfig { ServerURI : "test-server-uri" } ,
255
259
MaxRequests : func () * uint32 { i := uint32 (512 ); return & i }(),
256
260
},
257
261
wantLBConfig : & iserviceconfig.BalancerConfig {
@@ -298,7 +302,8 @@ func (s) TestValidateCluster_Success(t *testing.T) {
298
302
LbPolicy : v3clusterpb .Cluster_LEAST_REQUEST ,
299
303
},
300
304
wantUpdate : xdsresource.ClusterUpdate {
301
- ClusterName : clusterName , EDSServiceName : serviceName ,
305
+ ClusterName : clusterName ,
306
+ EDSServiceName : serviceName ,
302
307
},
303
308
wantLBConfig : & iserviceconfig.BalancerConfig {
304
309
Name : "least_request_experimental" ,
@@ -353,7 +358,8 @@ func (s) TestValidateCluster_Success(t *testing.T) {
353
358
},
354
359
},
355
360
wantUpdate : xdsresource.ClusterUpdate {
356
- ClusterName : clusterName , EDSServiceName : serviceName ,
361
+ ClusterName : clusterName ,
362
+ EDSServiceName : serviceName ,
357
363
},
358
364
wantLBConfig : & iserviceconfig.BalancerConfig {
359
365
Name : "least_request_experimental" ,
@@ -527,7 +533,7 @@ func (s) TestValidateCluster_Success(t *testing.T) {
527
533
528
534
for _ , test := range tests {
529
535
t .Run (test .name , func (t * testing.T ) {
530
- update , err := xdsresource .ValidateClusterAndConstructClusterUpdateForTesting (test .cluster )
536
+ update , err := xdsresource .ValidateClusterAndConstructClusterUpdateForTesting (test .cluster , test . serverCfg )
531
537
if err != nil {
532
538
t .Errorf ("validateClusterAndConstructClusterUpdate(%+v) failed: %v" , test .cluster , err )
533
539
}
0 commit comments