Skip to content

Commit

Permalink
rename to XXXUpdateErrTuple
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Sep 10, 2021
1 parent 3f82900 commit e7c14e4
Show file tree
Hide file tree
Showing 18 changed files with 245 additions and 237 deletions.
8 changes: 4 additions & 4 deletions xds/internal/xdsclient/callback.go
Expand Up @@ -76,7 +76,7 @@ func (c *clientImpl) callCallback(wiu *watcherInfoWithUpdate) {
//
// A response can contain multiple resources. They will be parsed and put in a
// map from resource name to the resource content.
func (c *clientImpl) NewListeners(updates map[string]ListenerUpdateErr, metadata UpdateMetadata) {
func (c *clientImpl) NewListeners(updates map[string]ListenerUpdateErrTuple, metadata UpdateMetadata) {
c.mu.Lock()
defer c.mu.Unlock()

Expand Down Expand Up @@ -141,7 +141,7 @@ func (c *clientImpl) NewListeners(updates map[string]ListenerUpdateErr, metadata
//
// A response can contain multiple resources. They will be parsed and put in a
// map from resource name to the resource content.
func (c *clientImpl) NewRouteConfigs(updates map[string]RouteConfigUpdateErr, metadata UpdateMetadata) {
func (c *clientImpl) NewRouteConfigs(updates map[string]RouteConfigUpdateErrTuple, metadata UpdateMetadata) {
c.mu.Lock()
defer c.mu.Unlock()

Expand Down Expand Up @@ -190,7 +190,7 @@ func (c *clientImpl) NewRouteConfigs(updates map[string]RouteConfigUpdateErr, me
//
// A response can contain multiple resources. They will be parsed and put in a
// map from resource name to the resource content.
func (c *clientImpl) NewClusters(updates map[string]ClusterUpdateErr, metadata UpdateMetadata) {
func (c *clientImpl) NewClusters(updates map[string]ClusterUpdateErrTuple, metadata UpdateMetadata) {
c.mu.Lock()
defer c.mu.Unlock()

Expand Down Expand Up @@ -257,7 +257,7 @@ func (c *clientImpl) NewClusters(updates map[string]ClusterUpdateErr, metadata U
//
// A response can contain multiple resources. They will be parsed and put in a
// map from resource name to the resource content.
func (c *clientImpl) NewEndpoints(updates map[string]EndpointsUpdateErr, metadata UpdateMetadata) {
func (c *clientImpl) NewEndpoints(updates map[string]EndpointsUpdateErrTuple, metadata UpdateMetadata) {
c.mu.Lock()
defer c.mu.Unlock()

Expand Down
12 changes: 6 additions & 6 deletions xds/internal/xdsclient/cds_test.go
Expand Up @@ -945,7 +945,7 @@ func (s) TestUnmarshalCluster(t *testing.T) {
tests := []struct {
name string
resources []*anypb.Any
wantUpdate map[string]ClusterUpdateErr
wantUpdate map[string]ClusterUpdateErrTuple
wantMD UpdateMetadata
wantErr bool
}{
Expand Down Expand Up @@ -988,7 +988,7 @@ func (s) TestUnmarshalCluster(t *testing.T) {
ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_STATIC},
}),
},
wantUpdate: map[string]ClusterUpdateErr{
wantUpdate: map[string]ClusterUpdateErrTuple{
"test": {Err: cmpopts.AnyError},
},
wantMD: UpdateMetadata{
Expand All @@ -1004,7 +1004,7 @@ func (s) TestUnmarshalCluster(t *testing.T) {
{
name: "v2 cluster",
resources: []*anypb.Any{v2ClusterAny},
wantUpdate: map[string]ClusterUpdateErr{
wantUpdate: map[string]ClusterUpdateErrTuple{
v2ClusterName: {Update: ClusterUpdate{
ClusterName: v2ClusterName,
EDSServiceName: v2Service, EnableLRS: true,
Expand All @@ -1019,7 +1019,7 @@ func (s) TestUnmarshalCluster(t *testing.T) {
{
name: "v3 cluster",
resources: []*anypb.Any{v3ClusterAny},
wantUpdate: map[string]ClusterUpdateErr{
wantUpdate: map[string]ClusterUpdateErrTuple{
v3ClusterName: {Update: ClusterUpdate{
ClusterName: v3ClusterName,
EDSServiceName: v3Service, EnableLRS: true,
Expand All @@ -1034,7 +1034,7 @@ func (s) TestUnmarshalCluster(t *testing.T) {
{
name: "multiple clusters",
resources: []*anypb.Any{v2ClusterAny, v3ClusterAny},
wantUpdate: map[string]ClusterUpdateErr{
wantUpdate: map[string]ClusterUpdateErrTuple{
v2ClusterName: {Update: ClusterUpdate{
ClusterName: v2ClusterName,
EDSServiceName: v2Service, EnableLRS: true,
Expand Down Expand Up @@ -1063,7 +1063,7 @@ func (s) TestUnmarshalCluster(t *testing.T) {
}),
v3ClusterAny,
},
wantUpdate: map[string]ClusterUpdateErr{
wantUpdate: map[string]ClusterUpdateErrTuple{
v2ClusterName: {Update: ClusterUpdate{
ClusterName: v2ClusterName,
EDSServiceName: v2Service, EnableLRS: true,
Expand Down
8 changes: 4 additions & 4 deletions xds/internal/xdsclient/client.go
Expand Up @@ -134,14 +134,14 @@ type loadReportingOptions struct {
// resource updates from an APIClient for a specific version.
type UpdateHandler interface {
// NewListeners handles updates to xDS listener resources.
NewListeners(map[string]ListenerUpdateErr, UpdateMetadata)
NewListeners(map[string]ListenerUpdateErrTuple, UpdateMetadata)
// NewRouteConfigs handles updates to xDS RouteConfiguration resources.
NewRouteConfigs(map[string]RouteConfigUpdateErr, UpdateMetadata)
NewRouteConfigs(map[string]RouteConfigUpdateErrTuple, UpdateMetadata)
// NewClusters handles updates to xDS Cluster resources.
NewClusters(map[string]ClusterUpdateErr, UpdateMetadata)
NewClusters(map[string]ClusterUpdateErrTuple, UpdateMetadata)
// NewEndpoints handles updates to xDS ClusterLoadAssignment (or tersely
// referred to as Endpoints) resources.
NewEndpoints(map[string]EndpointsUpdateErr, UpdateMetadata)
NewEndpoints(map[string]EndpointsUpdateErrTuple, UpdateMetadata)
// NewConnectionError handles connection errors from the xDS stream. The
// error will be reported to all the resource watchers.
NewConnectionError(err error)
Expand Down
14 changes: 7 additions & 7 deletions xds/internal/xdsclient/client_test.go
Expand Up @@ -162,7 +162,7 @@ func (s) TestWatchCallAnotherWatch(t *testing.T) {
clusterUpdateCh := testutils.NewChannel()
firstTime := true
client.WatchCluster(testCDSName, func(update ClusterUpdate, err error) {
clusterUpdateCh.Send(ClusterUpdateErr{Update: update, Err: err})
clusterUpdateCh.Send(ClusterUpdateErrTuple{Update: update, Err: err})
// Calls another watch inline, to ensure there's deadlock.
client.WatchCluster("another-random-name", func(ClusterUpdate, error) {})

Expand All @@ -176,13 +176,13 @@ func (s) TestWatchCallAnotherWatch(t *testing.T) {
}

wantUpdate := ClusterUpdate{ClusterName: testEDSName}
client.NewClusters(map[string]ClusterUpdateErr{testCDSName: {Update: wantUpdate}}, UpdateMetadata{})
client.NewClusters(map[string]ClusterUpdateErrTuple{testCDSName: {Update: wantUpdate}}, UpdateMetadata{})
if err := verifyClusterUpdate(ctx, clusterUpdateCh, wantUpdate, nil); err != nil {
t.Fatal(err)
}

wantUpdate2 := ClusterUpdate{ClusterName: testEDSName + "2"}
client.NewClusters(map[string]ClusterUpdateErr{testCDSName: {Update: wantUpdate2}}, UpdateMetadata{})
client.NewClusters(map[string]ClusterUpdateErrTuple{testCDSName: {Update: wantUpdate2}}, UpdateMetadata{})
if err := verifyClusterUpdate(ctx, clusterUpdateCh, wantUpdate2, nil); err != nil {
t.Fatal(err)
}
Expand All @@ -193,7 +193,7 @@ func verifyListenerUpdate(ctx context.Context, updateCh *testutils.Channel, want
if err != nil {
return fmt.Errorf("timeout when waiting for listener update: %v", err)
}
gotUpdate := u.(ListenerUpdateErr)
gotUpdate := u.(ListenerUpdateErrTuple)
if wantErr != nil {
if gotUpdate.Err != wantErr {
return fmt.Errorf("unexpected error: %v, want %v", gotUpdate.Err, wantErr)
Expand All @@ -211,7 +211,7 @@ func verifyRouteConfigUpdate(ctx context.Context, updateCh *testutils.Channel, w
if err != nil {
return fmt.Errorf("timeout when waiting for route configuration update: %v", err)
}
gotUpdate := u.(RouteConfigUpdateErr)
gotUpdate := u.(RouteConfigUpdateErrTuple)
if wantErr != nil {
if gotUpdate.Err != wantErr {
return fmt.Errorf("unexpected error: %v, want %v", gotUpdate.Err, wantErr)
Expand All @@ -229,7 +229,7 @@ func verifyClusterUpdate(ctx context.Context, updateCh *testutils.Channel, wantU
if err != nil {
return fmt.Errorf("timeout when waiting for cluster update: %v", err)
}
gotUpdate := u.(ClusterUpdateErr)
gotUpdate := u.(ClusterUpdateErrTuple)
if wantErr != nil {
if gotUpdate.Err != wantErr {
return fmt.Errorf("unexpected error: %v, want %v", gotUpdate.Err, wantErr)
Expand All @@ -247,7 +247,7 @@ func verifyEndpointsUpdate(ctx context.Context, updateCh *testutils.Channel, wan
if err != nil {
return fmt.Errorf("timeout when waiting for endpoints update: %v", err)
}
gotUpdate := u.(EndpointsUpdateErr)
gotUpdate := u.(EndpointsUpdateErrTuple)
if wantErr != nil {
if gotUpdate.Err != wantErr {
return fmt.Errorf("unexpected error: %v, want %v", gotUpdate.Err, wantErr)
Expand Down
24 changes: 12 additions & 12 deletions xds/internal/xdsclient/dump_test.go
Expand Up @@ -101,10 +101,10 @@ func (s) TestLDSConfigDump(t *testing.T) {
t.Fatalf(err.Error())
}

update0 := make(map[string]xdsclient.ListenerUpdateErr)
update0 := make(map[string]xdsclient.ListenerUpdateErrTuple)
want0 := make(map[string]xdsclient.UpdateWithMD)
for n, r := range listenerRaws {
update0[n] = xdsclient.ListenerUpdateErr{Update: xdsclient.ListenerUpdate{Raw: r}}
update0[n] = xdsclient.ListenerUpdateErrTuple{Update: xdsclient.ListenerUpdate{Raw: r}}
want0[n] = xdsclient.UpdateWithMD{
MD: xdsclient.UpdateMetadata{Status: xdsclient.ServiceStatusACKed, Version: testVersion},
Raw: r,
Expand All @@ -120,7 +120,7 @@ func (s) TestLDSConfigDump(t *testing.T) {
const nackVersion = "lds-version-nack"
var nackErr = fmt.Errorf("lds nack error")
updateHandler.NewListeners(
map[string]xdsclient.ListenerUpdateErr{
map[string]xdsclient.ListenerUpdateErrTuple{
ldsTargets[0]: {Err: nackErr},
ldsTargets[1]: {Update: xdsclient.ListenerUpdate{Raw: listenerRaws[ldsTargets[1]]}},
},
Expand Down Expand Up @@ -215,10 +215,10 @@ func (s) TestRDSConfigDump(t *testing.T) {
t.Fatalf(err.Error())
}

update0 := make(map[string]xdsclient.RouteConfigUpdateErr)
update0 := make(map[string]xdsclient.RouteConfigUpdateErrTuple)
want0 := make(map[string]xdsclient.UpdateWithMD)
for n, r := range routeRaws {
update0[n] = xdsclient.RouteConfigUpdateErr{Update: xdsclient.RouteConfigUpdate{Raw: r}}
update0[n] = xdsclient.RouteConfigUpdateErrTuple{Update: xdsclient.RouteConfigUpdate{Raw: r}}
want0[n] = xdsclient.UpdateWithMD{
MD: xdsclient.UpdateMetadata{Status: xdsclient.ServiceStatusACKed, Version: testVersion},
Raw: r,
Expand All @@ -234,7 +234,7 @@ func (s) TestRDSConfigDump(t *testing.T) {
const nackVersion = "rds-version-nack"
var nackErr = fmt.Errorf("rds nack error")
updateHandler.NewRouteConfigs(
map[string]xdsclient.RouteConfigUpdateErr{
map[string]xdsclient.RouteConfigUpdateErrTuple{
rdsTargets[0]: {Err: nackErr},
rdsTargets[1]: {Update: xdsclient.RouteConfigUpdate{Raw: routeRaws[rdsTargets[1]]}},
},
Expand Down Expand Up @@ -329,10 +329,10 @@ func (s) TestCDSConfigDump(t *testing.T) {
t.Fatalf(err.Error())
}

update0 := make(map[string]xdsclient.ClusterUpdateErr)
update0 := make(map[string]xdsclient.ClusterUpdateErrTuple)
want0 := make(map[string]xdsclient.UpdateWithMD)
for n, r := range clusterRaws {
update0[n] = xdsclient.ClusterUpdateErr{Update: xdsclient.ClusterUpdate{Raw: r}}
update0[n] = xdsclient.ClusterUpdateErrTuple{Update: xdsclient.ClusterUpdate{Raw: r}}
want0[n] = xdsclient.UpdateWithMD{
MD: xdsclient.UpdateMetadata{Status: xdsclient.ServiceStatusACKed, Version: testVersion},
Raw: r,
Expand All @@ -348,7 +348,7 @@ func (s) TestCDSConfigDump(t *testing.T) {
const nackVersion = "cds-version-nack"
var nackErr = fmt.Errorf("cds nack error")
updateHandler.NewClusters(
map[string]xdsclient.ClusterUpdateErr{
map[string]xdsclient.ClusterUpdateErrTuple{
cdsTargets[0]: {Err: nackErr},
cdsTargets[1]: {Update: xdsclient.ClusterUpdate{Raw: clusterRaws[cdsTargets[1]]}},
},
Expand Down Expand Up @@ -429,10 +429,10 @@ func (s) TestEDSConfigDump(t *testing.T) {
t.Fatalf(err.Error())
}

update0 := make(map[string]xdsclient.EndpointsUpdateErr)
update0 := make(map[string]xdsclient.EndpointsUpdateErrTuple)
want0 := make(map[string]xdsclient.UpdateWithMD)
for n, r := range endpointRaws {
update0[n] = xdsclient.EndpointsUpdateErr{Update: xdsclient.EndpointsUpdate{Raw: r}}
update0[n] = xdsclient.EndpointsUpdateErrTuple{Update: xdsclient.EndpointsUpdate{Raw: r}}
want0[n] = xdsclient.UpdateWithMD{
MD: xdsclient.UpdateMetadata{Status: xdsclient.ServiceStatusACKed, Version: testVersion},
Raw: r,
Expand All @@ -448,7 +448,7 @@ func (s) TestEDSConfigDump(t *testing.T) {
const nackVersion = "eds-version-nack"
var nackErr = fmt.Errorf("eds nack error")
updateHandler.NewEndpoints(
map[string]xdsclient.EndpointsUpdateErr{
map[string]xdsclient.EndpointsUpdateErrTuple{
edsTargets[0]: {Err: nackErr},
edsTargets[1]: {Update: xdsclient.EndpointsUpdate{Raw: endpointRaws[edsTargets[1]]}},
},
Expand Down
8 changes: 4 additions & 4 deletions xds/internal/xdsclient/eds_test.go
Expand Up @@ -138,7 +138,7 @@ func (s) TestUnmarshalEndpoints(t *testing.T) {
tests := []struct {
name string
resources []*anypb.Any
wantUpdate map[string]EndpointsUpdateErr
wantUpdate map[string]EndpointsUpdateErrTuple
wantMD UpdateMetadata
wantErr bool
}{
Expand Down Expand Up @@ -181,7 +181,7 @@ func (s) TestUnmarshalEndpoints(t *testing.T) {
clab0.addLocality("locality-2", 1, 2, []string{"addr2:159"}, nil)
return clab0.Build()
}())},
wantUpdate: map[string]EndpointsUpdateErr{"test": {Err: cmpopts.AnyError}},
wantUpdate: map[string]EndpointsUpdateErrTuple{"test": {Err: cmpopts.AnyError}},
wantMD: UpdateMetadata{
Status: ServiceStatusNACKed,
Version: testVersion,
Expand All @@ -195,7 +195,7 @@ func (s) TestUnmarshalEndpoints(t *testing.T) {
{
name: "v3 endpoints",
resources: []*anypb.Any{v3EndpointsAny},
wantUpdate: map[string]EndpointsUpdateErr{
wantUpdate: map[string]EndpointsUpdateErrTuple{
"test": {Update: EndpointsUpdate{
Drops: nil,
Localities: []Locality{
Expand Down Expand Up @@ -240,7 +240,7 @@ func (s) TestUnmarshalEndpoints(t *testing.T) {
return clab0.Build()
}()),
},
wantUpdate: map[string]EndpointsUpdateErr{
wantUpdate: map[string]EndpointsUpdateErrTuple{
"test": {Update: EndpointsUpdate{
Drops: nil,
Localities: []Locality{
Expand Down

0 comments on commit e7c14e4

Please sign in to comment.