...
1
18
19
20 package fakeclient
21
22 import (
23 "context"
24
25 "google.golang.org/grpc/internal/testutils"
26 "google.golang.org/grpc/internal/xds/bootstrap"
27 "google.golang.org/grpc/xds/internal/xdsclient"
28 "google.golang.org/grpc/xds/internal/xdsclient/load"
29 )
30
31
32
33 type Client struct {
34
35
36
37 xdsclient.XDSClient
38
39 name string
40 loadReportCh *testutils.Channel
41 lrsCancelCh *testutils.Channel
42 loadStore *load.Store
43 bootstrapCfg *bootstrap.Config
44 }
45
46
47 type ReportLoadArgs struct {
48
49 Server *bootstrap.ServerConfig
50 }
51
52
53 func (xdsC *Client) ReportLoad(server *bootstrap.ServerConfig) (loadStore *load.Store, cancel func()) {
54 xdsC.loadReportCh.Send(ReportLoadArgs{Server: server})
55 return xdsC.loadStore, func() {
56 xdsC.lrsCancelCh.Send(nil)
57 }
58 }
59
60
61
62 func (xdsC *Client) WaitForCancelReportLoad(ctx context.Context) error {
63 _, err := xdsC.lrsCancelCh.Receive(ctx)
64 return err
65 }
66
67
68 func (xdsC *Client) LoadStore() *load.Store {
69 return xdsC.loadStore
70 }
71
72
73
74 func (xdsC *Client) WaitForReportLoad(ctx context.Context) (ReportLoadArgs, error) {
75 val, err := xdsC.loadReportCh.Receive(ctx)
76 if err != nil {
77 return ReportLoadArgs{}, err
78 }
79 return val.(ReportLoadArgs), nil
80 }
81
82
83 func (xdsC *Client) BootstrapConfig() *bootstrap.Config {
84 return xdsC.bootstrapCfg
85 }
86
87
88 func (xdsC *Client) SetBootstrapConfig(cfg *bootstrap.Config) {
89 xdsC.bootstrapCfg = cfg
90 }
91
92
93 func (xdsC *Client) Name() string {
94 return xdsC.name
95 }
96
97
98 func NewClient() *Client {
99 return NewClientWithName("")
100 }
101
102
103
104
105 func NewClientWithName(name string) *Client {
106 return &Client{
107 name: name,
108 loadReportCh: testutils.NewChannel(),
109 lrsCancelCh: testutils.NewChannel(),
110 loadStore: load.NewStore(),
111 bootstrapCfg: &bootstrap.Config{ClientDefaultListenerResourceNameTemplate: "%s"},
112 }
113 }
114
View as plain text