@@ -26,7 +26,6 @@ import (
2626 "google.golang.org/grpc/xds/internal/xdsclient"
2727 "google.golang.org/grpc/xds/internal/xdsclient/bootstrap"
2828 "google.golang.org/grpc/xds/internal/xdsclient/load"
29- "google.golang.org/grpc/xds/internal/xdsclient/xdsresource"
3029)
3130
3231// Client is a fake implementation of an xds client. It exposes a bunch of
@@ -38,151 +37,10 @@ type Client struct {
3837 xdsclient.XDSClient
3938
4039 name string
41- ldsWatchCh * testutils.Channel
42- rdsWatchCh * testutils.Channel
43- cdsWatchCh * testutils.Channel
44- edsWatchCh * testutils.Channel
45- ldsCancelCh * testutils.Channel
46- rdsCancelCh * testutils.Channel
47- cdsCancelCh * testutils.Channel
48- edsCancelCh * testutils.Channel
4940 loadReportCh * testutils.Channel
5041 lrsCancelCh * testutils.Channel
5142 loadStore * load.Store
5243 bootstrapCfg * bootstrap.Config
53-
54- ldsCb func (xdsresource.ListenerUpdate , error )
55- rdsCbs map [string ]func (xdsresource.RouteConfigUpdate , error )
56- cdsCbs map [string ]func (xdsresource.ClusterUpdate , error )
57- edsCbs map [string ]func (xdsresource.EndpointsUpdate , error )
58- }
59-
60- // WatchListener registers a LDS watch.
61- func (xdsC * Client ) WatchListener (serviceName string , callback func (xdsresource.ListenerUpdate , error )) func () {
62- xdsC .ldsCb = callback
63- xdsC .ldsWatchCh .Send (serviceName )
64- return func () {
65- xdsC .ldsCancelCh .Send (nil )
66- }
67- }
68-
69- // WaitForWatchListener waits for WatchCluster to be invoked on this client and
70- // returns the serviceName being watched.
71- func (xdsC * Client ) WaitForWatchListener (ctx context.Context ) (string , error ) {
72- val , err := xdsC .ldsWatchCh .Receive (ctx )
73- if err != nil {
74- return "" , err
75- }
76- return val .(string ), err
77- }
78-
79- // InvokeWatchListenerCallback invokes the registered ldsWatch callback.
80- //
81- // Not thread safe with WatchListener. Only call this after
82- // WaitForWatchListener.
83- func (xdsC * Client ) InvokeWatchListenerCallback (update xdsresource.ListenerUpdate , err error ) {
84- xdsC .ldsCb (update , err )
85- }
86-
87- // WaitForCancelListenerWatch waits for a LDS watch to be cancelled and returns
88- // context.DeadlineExceeded otherwise.
89- func (xdsC * Client ) WaitForCancelListenerWatch (ctx context.Context ) error {
90- _ , err := xdsC .ldsCancelCh .Receive (ctx )
91- return err
92- }
93-
94- // WatchRouteConfig registers a RDS watch.
95- func (xdsC * Client ) WatchRouteConfig (routeName string , callback func (xdsresource.RouteConfigUpdate , error )) func () {
96- xdsC .rdsCbs [routeName ] = callback
97- xdsC .rdsWatchCh .Send (routeName )
98- return func () {
99- xdsC .rdsCancelCh .Send (routeName )
100- }
101- }
102-
103- // WaitForWatchRouteConfig waits for WatchCluster to be invoked on this client and
104- // returns the routeName being watched.
105- func (xdsC * Client ) WaitForWatchRouteConfig (ctx context.Context ) (string , error ) {
106- val , err := xdsC .rdsWatchCh .Receive (ctx )
107- if err != nil {
108- return "" , err
109- }
110- return val .(string ), err
111- }
112-
113- // InvokeWatchRouteConfigCallback invokes the registered rdsWatch callback.
114- //
115- // Not thread safe with WatchRouteConfig. Only call this after
116- // WaitForWatchRouteConfig.
117- func (xdsC * Client ) InvokeWatchRouteConfigCallback (name string , update xdsresource.RouteConfigUpdate , err error ) {
118- if len (xdsC .rdsCbs ) != 1 {
119- xdsC .rdsCbs [name ](update , err )
120- return
121- }
122- // Keeps functionality with previous usage of this on client side, if single
123- // callback call that callback.
124- var routeName string
125- for route := range xdsC .rdsCbs {
126- routeName = route
127- }
128- xdsC .rdsCbs [routeName ](update , err )
129- }
130-
131- // WaitForCancelRouteConfigWatch waits for a RDS watch to be cancelled and returns
132- // context.DeadlineExceeded otherwise.
133- func (xdsC * Client ) WaitForCancelRouteConfigWatch (ctx context.Context ) (string , error ) {
134- val , err := xdsC .rdsCancelCh .Receive (ctx )
135- if err != nil {
136- return "" , err
137- }
138- return val .(string ), err
139- }
140-
141- // WatchEndpoints registers an EDS watch for provided clusterName.
142- func (xdsC * Client ) WatchEndpoints (clusterName string , callback func (xdsresource.EndpointsUpdate , error )) (cancel func ()) {
143- xdsC .edsCbs [clusterName ] = callback
144- xdsC .edsWatchCh .Send (clusterName )
145- return func () {
146- xdsC .edsCancelCh .Send (clusterName )
147- }
148- }
149-
150- // WaitForWatchEDS waits for WatchEndpoints to be invoked on this client and
151- // returns the clusterName being watched.
152- func (xdsC * Client ) WaitForWatchEDS (ctx context.Context ) (string , error ) {
153- val , err := xdsC .edsWatchCh .Receive (ctx )
154- if err != nil {
155- return "" , err
156- }
157- return val .(string ), err
158- }
159-
160- // InvokeWatchEDSCallback invokes the registered edsWatch callback.
161- //
162- // Not thread safe with WatchEndpoints. Only call this after
163- // WaitForWatchEDS.
164- func (xdsC * Client ) InvokeWatchEDSCallback (name string , update xdsresource.EndpointsUpdate , err error ) {
165- if len (xdsC .edsCbs ) != 1 {
166- // This may panic if name isn't found. But it's fine for tests.
167- xdsC .edsCbs [name ](update , err )
168- return
169- }
170- // Keeps functionality with previous usage of this, if single callback call
171- // that callback.
172- for n := range xdsC .edsCbs {
173- name = n
174- }
175- xdsC .edsCbs [name ](update , err )
176- }
177-
178- // WaitForCancelEDSWatch waits for a EDS watch to be cancelled and returns
179- // context.DeadlineExceeded otherwise.
180- func (xdsC * Client ) WaitForCancelEDSWatch (ctx context.Context ) (string , error ) {
181- edsNameReceived , err := xdsC .edsCancelCh .Receive (ctx )
182- if err != nil {
183- return "" , err
184- }
185- return edsNameReceived .(string ), err
18644}
18745
18846// ReportLoadArgs wraps the arguments passed to ReportLoad.
@@ -247,20 +105,9 @@ func NewClient() *Client {
247105func NewClientWithName (name string ) * Client {
248106 return & Client {
249107 name : name ,
250- ldsWatchCh : testutils .NewChannelWithSize (10 ),
251- rdsWatchCh : testutils .NewChannelWithSize (10 ),
252- cdsWatchCh : testutils .NewChannelWithSize (10 ),
253- edsWatchCh : testutils .NewChannelWithSize (10 ),
254- ldsCancelCh : testutils .NewChannelWithSize (10 ),
255- rdsCancelCh : testutils .NewChannelWithSize (10 ),
256- cdsCancelCh : testutils .NewChannelWithSize (10 ),
257- edsCancelCh : testutils .NewChannelWithSize (10 ),
258108 loadReportCh : testutils .NewChannel (),
259109 lrsCancelCh : testutils .NewChannel (),
260110 loadStore : load .NewStore (),
261111 bootstrapCfg : & bootstrap.Config {ClientDefaultListenerResourceNameTemplate : "%s" },
262- rdsCbs : make (map [string ]func (xdsresource.RouteConfigUpdate , error )),
263- cdsCbs : make (map [string ]func (xdsresource.ClusterUpdate , error )),
264- edsCbs : make (map [string ]func (xdsresource.EndpointsUpdate , error )),
265112 }
266113}
0 commit comments