xds: unexport edsBalancerImplInterface's function (#3550)
Signed-off-by: Zou Nengren <zouyee1989@gmail.com>
This commit is contained in:
@ -91,19 +91,17 @@ func (b *edsBalancerBuilder) ParseConfig(c json.RawMessage) (serviceconfig.LoadB
|
||||
// implement to communicate with edsBalancer.
|
||||
//
|
||||
// It's implemented by the real eds balancer and a fake testing eds balancer.
|
||||
//
|
||||
// TODO: none of the methods in this interface needs to be exported.
|
||||
type edsBalancerImplInterface interface {
|
||||
// HandleEDSResponse passes the received EDS message from traffic director to eds balancer.
|
||||
HandleEDSResponse(edsResp xdsclient.EndpointsUpdate)
|
||||
// HandleChildPolicy updates the eds balancer the intra-cluster load balancing policy to use.
|
||||
HandleChildPolicy(name string, config json.RawMessage)
|
||||
// HandleSubConnStateChange handles state change for SubConn.
|
||||
HandleSubConnStateChange(sc balancer.SubConn, state connectivity.State)
|
||||
// handleEDSResponse passes the received EDS message from traffic director to eds balancer.
|
||||
handleEDSResponse(edsResp xdsclient.EndpointsUpdate)
|
||||
// handleChildPolicy updates the eds balancer the intra-cluster load balancing policy to use.
|
||||
handleChildPolicy(name string, config json.RawMessage)
|
||||
// handleSubConnStateChange handles state change for SubConn.
|
||||
handleSubConnStateChange(sc balancer.SubConn, state connectivity.State)
|
||||
// updateState handle a balancer state update from the priority.
|
||||
updateState(priority priorityType, s balancer.State)
|
||||
// Close closes the eds balancer.
|
||||
Close()
|
||||
// close closes the eds balancer.
|
||||
close()
|
||||
}
|
||||
|
||||
var _ balancer.V2Balancer = (*edsBalancer)(nil) // Assert that we implement V2Balancer
|
||||
@ -149,7 +147,7 @@ func (x *edsBalancer) run() {
|
||||
x.client.close()
|
||||
}
|
||||
if x.edsImpl != nil {
|
||||
x.edsImpl.Close()
|
||||
x.edsImpl.close()
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -160,7 +158,7 @@ func (x *edsBalancer) handleGRPCUpdate(update interface{}) {
|
||||
switch u := update.(type) {
|
||||
case *subConnStateUpdate:
|
||||
if x.edsImpl != nil {
|
||||
x.edsImpl.HandleSubConnStateChange(u.sc, u.state.ConnectivityState)
|
||||
x.edsImpl.handleSubConnStateChange(u.sc, u.state.ConnectivityState)
|
||||
}
|
||||
case *balancer.ClientConnState:
|
||||
x.logger.Infof("Receive update from resolver, balancer config: %+v", u.BalancerConfig)
|
||||
@ -181,9 +179,9 @@ func (x *edsBalancer) handleGRPCUpdate(update interface{}) {
|
||||
// different one.
|
||||
if x.edsImpl != nil && !cmp.Equal(cfg.ChildPolicy, x.config.ChildPolicy) {
|
||||
if cfg.ChildPolicy != nil {
|
||||
x.edsImpl.HandleChildPolicy(cfg.ChildPolicy.Name, cfg.ChildPolicy.Config)
|
||||
x.edsImpl.handleChildPolicy(cfg.ChildPolicy.Name, cfg.ChildPolicy.Config)
|
||||
} else {
|
||||
x.edsImpl.HandleChildPolicy(roundrobin.Name, nil)
|
||||
x.edsImpl.handleChildPolicy(roundrobin.Name, nil)
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,7 +197,7 @@ func (x *edsBalancer) handleXDSClientUpdate(update interface{}) {
|
||||
// TODO: this func should accept (xdsclient.EndpointsUpdate, error), and process
|
||||
// the error, instead of having a separate loseContact signal.
|
||||
case xdsclient.EndpointsUpdate:
|
||||
x.edsImpl.HandleEDSResponse(u)
|
||||
x.edsImpl.handleEDSResponse(u)
|
||||
case *loseContact:
|
||||
// loseContact can be useful for going into fallback.
|
||||
default:
|
||||
|
@ -114,12 +114,12 @@ func newEDSBalancerImpl(cc balancer.ClientConn, enqueueState func(priorityType,
|
||||
return edsImpl
|
||||
}
|
||||
|
||||
// HandleChildPolicy updates the child balancers handling endpoints. Child
|
||||
// handleChildPolicy updates the child balancers handling endpoints. Child
|
||||
// policy is roundrobin by default. If the specified balancer is not installed,
|
||||
// the old child balancer will be used.
|
||||
//
|
||||
// HandleChildPolicy and HandleEDSResponse must be called by the same goroutine.
|
||||
func (edsImpl *edsBalancerImpl) HandleChildPolicy(name string, config json.RawMessage) {
|
||||
func (edsImpl *edsBalancerImpl) handleChildPolicy(name string, config json.RawMessage) {
|
||||
if edsImpl.subBalancerBuilder.Name() == name {
|
||||
return
|
||||
}
|
||||
@ -169,11 +169,11 @@ func (edsImpl *edsBalancerImpl) updateDrops(dropConfig []xdsclient.OverloadDropC
|
||||
edsImpl.pickerMu.Unlock()
|
||||
}
|
||||
|
||||
// HandleEDSResponse handles the EDS response and creates/deletes localities and
|
||||
// handleEDSResponse handles the EDS response and creates/deletes localities and
|
||||
// SubConns. It also handles drops.
|
||||
//
|
||||
// HandleChildPolicy and HandleEDSResponse must be called by the same goroutine.
|
||||
func (edsImpl *edsBalancerImpl) HandleEDSResponse(edsResp xdsclient.EndpointsUpdate) {
|
||||
func (edsImpl *edsBalancerImpl) handleEDSResponse(edsResp xdsclient.EndpointsUpdate) {
|
||||
// TODO: Unhandled fields from EDS response:
|
||||
// - edsResp.GetPolicy().GetOverprovisioningFactor()
|
||||
// - locality.GetPriority()
|
||||
@ -331,8 +331,8 @@ func (edsImpl *edsBalancerImpl) handleEDSResponsePerPriority(bgwc *balancerGroup
|
||||
}
|
||||
}
|
||||
|
||||
// HandleSubConnStateChange handles the state change and update pickers accordingly.
|
||||
func (edsImpl *edsBalancerImpl) HandleSubConnStateChange(sc balancer.SubConn, s connectivity.State) {
|
||||
// handleSubConnStateChange handles the state change and update pickers accordingly.
|
||||
func (edsImpl *edsBalancerImpl) handleSubConnStateChange(sc balancer.SubConn, s connectivity.State) {
|
||||
edsImpl.subConnMu.Lock()
|
||||
var bgwc *balancerGroupWithConfig
|
||||
if p, ok := edsImpl.subConnToPriority[sc]; ok {
|
||||
@ -408,8 +408,8 @@ func (edsImpl *edsBalancerImpl) newSubConn(priority priorityType, addrs []resolv
|
||||
return sc, nil
|
||||
}
|
||||
|
||||
// Close closes the balancer.
|
||||
func (edsImpl *edsBalancerImpl) Close() {
|
||||
// close closes the balancer.
|
||||
func (edsImpl *edsBalancerImpl) close() {
|
||||
for _, bgwc := range edsImpl.priorityToLocalities {
|
||||
if bg := bgwc.bg; bg != nil {
|
||||
bg.Close()
|
||||
|
@ -42,7 +42,7 @@ func (s) TestEDSPriority_HighPriorityReady(t *testing.T) {
|
||||
clab1 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab1.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
clab1.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[1:2], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
|
||||
addrs1 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs1[0].Addr, testEndpointAddrs[0]; got != want {
|
||||
@ -51,8 +51,8 @@ func (s) TestEDSPriority_HighPriorityReady(t *testing.T) {
|
||||
sc1 := <-cc.NewSubConnCh
|
||||
|
||||
// p0 is ready.
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Ready)
|
||||
|
||||
// Test roundrobin with only p0 subconns.
|
||||
p1 := <-cc.NewPickerCh
|
||||
@ -66,7 +66,7 @@ func (s) TestEDSPriority_HighPriorityReady(t *testing.T) {
|
||||
clab2.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
clab2.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[1:2], nil)
|
||||
clab2.AddLocality(testSubZones[2], 1, 2, testEndpointAddrs[2:3], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab2.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab2.Build()))
|
||||
|
||||
select {
|
||||
case <-cc.NewPickerCh:
|
||||
@ -82,7 +82,7 @@ func (s) TestEDSPriority_HighPriorityReady(t *testing.T) {
|
||||
clab3 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab3.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
clab3.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[1:2], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab3.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab3.Build()))
|
||||
|
||||
select {
|
||||
case <-cc.NewPickerCh:
|
||||
@ -108,7 +108,7 @@ func (s) TestEDSPriority_SwitchPriority(t *testing.T) {
|
||||
clab1 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab1.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
clab1.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[1:2], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
|
||||
addrs0 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs0[0].Addr, testEndpointAddrs[0]; got != want {
|
||||
@ -117,8 +117,8 @@ func (s) TestEDSPriority_SwitchPriority(t *testing.T) {
|
||||
sc0 := <-cc.NewSubConnCh
|
||||
|
||||
// p0 is ready.
|
||||
edsb.HandleSubConnStateChange(sc0, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc0, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc0, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc0, connectivity.Ready)
|
||||
|
||||
// Test roundrobin with only p0 subconns.
|
||||
p0 := <-cc.NewPickerCh
|
||||
@ -128,14 +128,14 @@ func (s) TestEDSPriority_SwitchPriority(t *testing.T) {
|
||||
}
|
||||
|
||||
// Turn down 0, 1 is used.
|
||||
edsb.HandleSubConnStateChange(sc0, connectivity.TransientFailure)
|
||||
edsb.handleSubConnStateChange(sc0, connectivity.TransientFailure)
|
||||
addrs1 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs1[0].Addr, testEndpointAddrs[1]; got != want {
|
||||
t.Fatalf("sc is created with addr %v, want %v", got, want)
|
||||
}
|
||||
sc1 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Ready)
|
||||
|
||||
// Test pick with 1.
|
||||
p1 := <-cc.NewPickerCh
|
||||
@ -151,7 +151,7 @@ func (s) TestEDSPriority_SwitchPriority(t *testing.T) {
|
||||
clab2.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
clab2.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[1:2], nil)
|
||||
clab2.AddLocality(testSubZones[2], 1, 2, testEndpointAddrs[2:3], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab2.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab2.Build()))
|
||||
|
||||
select {
|
||||
case <-cc.NewPickerCh:
|
||||
@ -164,14 +164,14 @@ func (s) TestEDSPriority_SwitchPriority(t *testing.T) {
|
||||
}
|
||||
|
||||
// Turn down 1, use 2
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.TransientFailure)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.TransientFailure)
|
||||
addrs2 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs2[0].Addr, testEndpointAddrs[2]; got != want {
|
||||
t.Fatalf("sc is created with addr %v, want %v", got, want)
|
||||
}
|
||||
sc2 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Ready)
|
||||
|
||||
// Test pick with 2.
|
||||
p2 := <-cc.NewPickerCh
|
||||
@ -186,7 +186,7 @@ func (s) TestEDSPriority_SwitchPriority(t *testing.T) {
|
||||
clab3 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab3.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
clab3.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[1:2], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab3.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab3.Build()))
|
||||
|
||||
// p2 SubConns are removed.
|
||||
scToRemove := <-cc.RemoveSubConnCh
|
||||
@ -215,7 +215,7 @@ func (s) TestEDSPriority_HigherDownWhileAddingLower(t *testing.T) {
|
||||
clab1 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab1.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
clab1.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[1:2], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
|
||||
addrs0 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs0[0].Addr, testEndpointAddrs[0]; got != want {
|
||||
@ -224,14 +224,14 @@ func (s) TestEDSPriority_HigherDownWhileAddingLower(t *testing.T) {
|
||||
sc0 := <-cc.NewSubConnCh
|
||||
|
||||
// Turn down 0, 1 is used.
|
||||
edsb.HandleSubConnStateChange(sc0, connectivity.TransientFailure)
|
||||
edsb.handleSubConnStateChange(sc0, connectivity.TransientFailure)
|
||||
addrs1 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs1[0].Addr, testEndpointAddrs[1]; got != want {
|
||||
t.Fatalf("sc is created with addr %v, want %v", got, want)
|
||||
}
|
||||
sc1 := <-cc.NewSubConnCh
|
||||
// Turn down 1, pick should error.
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.TransientFailure)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.TransientFailure)
|
||||
|
||||
// Test pick failure.
|
||||
pFail := <-cc.NewPickerCh
|
||||
@ -246,15 +246,15 @@ func (s) TestEDSPriority_HigherDownWhileAddingLower(t *testing.T) {
|
||||
clab2.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
clab2.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[1:2], nil)
|
||||
clab2.AddLocality(testSubZones[2], 1, 2, testEndpointAddrs[2:3], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab2.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab2.Build()))
|
||||
|
||||
addrs2 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs2[0].Addr, testEndpointAddrs[2]; got != want {
|
||||
t.Fatalf("sc is created with addr %v, want %v", got, want)
|
||||
}
|
||||
sc2 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Ready)
|
||||
|
||||
// Test pick with 2.
|
||||
p2 := <-cc.NewPickerCh
|
||||
@ -281,7 +281,7 @@ func (s) TestEDSPriority_HigherReadyCloseAllLower(t *testing.T) {
|
||||
clab1.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
clab1.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[1:2], nil)
|
||||
clab1.AddLocality(testSubZones[2], 1, 2, testEndpointAddrs[2:3], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
|
||||
addrs0 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs0[0].Addr, testEndpointAddrs[0]; got != want {
|
||||
@ -290,21 +290,21 @@ func (s) TestEDSPriority_HigherReadyCloseAllLower(t *testing.T) {
|
||||
sc0 := <-cc.NewSubConnCh
|
||||
|
||||
// Turn down 0, 1 is used.
|
||||
edsb.HandleSubConnStateChange(sc0, connectivity.TransientFailure)
|
||||
edsb.handleSubConnStateChange(sc0, connectivity.TransientFailure)
|
||||
addrs1 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs1[0].Addr, testEndpointAddrs[1]; got != want {
|
||||
t.Fatalf("sc is created with addr %v, want %v", got, want)
|
||||
}
|
||||
sc1 := <-cc.NewSubConnCh
|
||||
// Turn down 1, 2 is used.
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.TransientFailure)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.TransientFailure)
|
||||
addrs2 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs2[0].Addr, testEndpointAddrs[2]; got != want {
|
||||
t.Fatalf("sc is created with addr %v, want %v", got, want)
|
||||
}
|
||||
sc2 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Ready)
|
||||
|
||||
// Test pick with 2.
|
||||
p2 := <-cc.NewPickerCh
|
||||
@ -316,7 +316,7 @@ func (s) TestEDSPriority_HigherReadyCloseAllLower(t *testing.T) {
|
||||
}
|
||||
|
||||
// When 0 becomes ready, 0 should be used, 1 and 2 should all be closed.
|
||||
edsb.HandleSubConnStateChange(sc0, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc0, connectivity.Ready)
|
||||
|
||||
// sc1 and sc2 should be removed.
|
||||
//
|
||||
@ -362,7 +362,7 @@ func (s) TestEDSPriority_InitTimeout(t *testing.T) {
|
||||
clab1 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab1.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
clab1.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[1:2], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
|
||||
addrs0 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs0[0].Addr, testEndpointAddrs[0]; got != want {
|
||||
@ -371,7 +371,7 @@ func (s) TestEDSPriority_InitTimeout(t *testing.T) {
|
||||
sc0 := <-cc.NewSubConnCh
|
||||
|
||||
// Keep 0 in connecting, 1 will be used after init timeout.
|
||||
edsb.HandleSubConnStateChange(sc0, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc0, connectivity.Connecting)
|
||||
|
||||
// Make sure new SubConn is created before timeout.
|
||||
select {
|
||||
@ -386,8 +386,8 @@ func (s) TestEDSPriority_InitTimeout(t *testing.T) {
|
||||
}
|
||||
sc1 := <-cc.NewSubConnCh
|
||||
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Ready)
|
||||
|
||||
// Test pick with 1.
|
||||
p1 := <-cc.NewPickerCh
|
||||
@ -412,15 +412,15 @@ func (s) TestEDSPriority_MultipleLocalities(t *testing.T) {
|
||||
clab0 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab0.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
clab0.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[1:2], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab0.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab0.Build()))
|
||||
|
||||
addrs0 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs0[0].Addr, testEndpointAddrs[0]; got != want {
|
||||
t.Fatalf("sc is created with addr %v, want %v", got, want)
|
||||
}
|
||||
sc0 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc0, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc0, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc0, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc0, connectivity.Ready)
|
||||
|
||||
// Test roundrobin with only p0 subconns.
|
||||
p0 := <-cc.NewPickerCh
|
||||
@ -430,15 +430,15 @@ func (s) TestEDSPriority_MultipleLocalities(t *testing.T) {
|
||||
}
|
||||
|
||||
// Turn down p0 subconns, p1 subconns will be created.
|
||||
edsb.HandleSubConnStateChange(sc0, connectivity.TransientFailure)
|
||||
edsb.handleSubConnStateChange(sc0, connectivity.TransientFailure)
|
||||
|
||||
addrs1 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs1[0].Addr, testEndpointAddrs[1]; got != want {
|
||||
t.Fatalf("sc is created with addr %v, want %v", got, want)
|
||||
}
|
||||
sc1 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Ready)
|
||||
|
||||
// Test roundrobin with only p1 subconns.
|
||||
p1 := <-cc.NewPickerCh
|
||||
@ -448,7 +448,7 @@ func (s) TestEDSPriority_MultipleLocalities(t *testing.T) {
|
||||
}
|
||||
|
||||
// Reconnect p0 subconns, p1 subconn will be closed.
|
||||
edsb.HandleSubConnStateChange(sc0, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc0, connectivity.Ready)
|
||||
|
||||
scToRemove := <-cc.RemoveSubConnCh
|
||||
if !cmp.Equal(scToRemove, sc1, cmp.AllowUnexported(testutils.TestSubConn{})) {
|
||||
@ -468,15 +468,15 @@ func (s) TestEDSPriority_MultipleLocalities(t *testing.T) {
|
||||
clab1.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[1:2], nil)
|
||||
clab1.AddLocality(testSubZones[2], 1, 0, testEndpointAddrs[2:3], nil)
|
||||
clab1.AddLocality(testSubZones[3], 1, 1, testEndpointAddrs[3:4], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
|
||||
addrs2 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs2[0].Addr, testEndpointAddrs[2]; got != want {
|
||||
t.Fatalf("sc is created with addr %v, want %v", got, want)
|
||||
}
|
||||
sc2 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Ready)
|
||||
|
||||
// Test roundrobin with only two p0 subconns.
|
||||
p3 := <-cc.NewPickerCh
|
||||
@ -486,15 +486,15 @@ func (s) TestEDSPriority_MultipleLocalities(t *testing.T) {
|
||||
}
|
||||
|
||||
// Turn down p0 subconns, p1 subconns will be created.
|
||||
edsb.HandleSubConnStateChange(sc0, connectivity.TransientFailure)
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.TransientFailure)
|
||||
edsb.handleSubConnStateChange(sc0, connectivity.TransientFailure)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.TransientFailure)
|
||||
|
||||
sc3 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc3, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc3, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc3, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc3, connectivity.Ready)
|
||||
sc4 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc4, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc4, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc4, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc4, connectivity.Ready)
|
||||
|
||||
// Test roundrobin with only p1 subconns.
|
||||
p4 := <-cc.NewPickerCh
|
||||
@ -523,15 +523,15 @@ func (s) TestEDSPriority_RemovesAllLocalities(t *testing.T) {
|
||||
clab0 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab0.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
clab0.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[1:2], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab0.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab0.Build()))
|
||||
|
||||
addrs0 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs0[0].Addr, testEndpointAddrs[0]; got != want {
|
||||
t.Fatalf("sc is created with addr %v, want %v", got, want)
|
||||
}
|
||||
sc0 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc0, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc0, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc0, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc0, connectivity.Ready)
|
||||
|
||||
// Test roundrobin with only p0 subconns.
|
||||
p0 := <-cc.NewPickerCh
|
||||
@ -542,7 +542,7 @@ func (s) TestEDSPriority_RemovesAllLocalities(t *testing.T) {
|
||||
|
||||
// Remove all priorities.
|
||||
clab1 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
|
||||
// p0 subconn should be removed.
|
||||
scToRemove := <-cc.RemoveSubConnCh
|
||||
@ -562,7 +562,7 @@ func (s) TestEDSPriority_RemovesAllLocalities(t *testing.T) {
|
||||
clab2 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab2.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[2:3], nil)
|
||||
clab2.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[3:4], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab2.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab2.Build()))
|
||||
|
||||
addrs01 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs01[0].Addr, testEndpointAddrs[2]; got != want {
|
||||
@ -580,8 +580,8 @@ func (s) TestEDSPriority_RemovesAllLocalities(t *testing.T) {
|
||||
t.Fatalf("sc is created with addr %v, want %v", got, want)
|
||||
}
|
||||
sc11 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc11, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc11, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc11, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc11, connectivity.Ready)
|
||||
|
||||
// Test roundrobin with only p1 subconns.
|
||||
p1 := <-cc.NewPickerCh
|
||||
@ -593,7 +593,7 @@ func (s) TestEDSPriority_RemovesAllLocalities(t *testing.T) {
|
||||
// Remove p1 from EDS, to fallback to p0.
|
||||
clab3 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab3.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[2:3], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab3.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab3.Build()))
|
||||
|
||||
// p1 subconn should be removed.
|
||||
scToRemove1 := <-cc.RemoveSubConnCh
|
||||
@ -611,8 +611,8 @@ func (s) TestEDSPriority_RemovesAllLocalities(t *testing.T) {
|
||||
|
||||
// Send an ready update for the p0 sc that was received when re-adding
|
||||
// localities to EDS.
|
||||
edsb.HandleSubConnStateChange(sc01, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc01, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc01, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc01, connectivity.Ready)
|
||||
|
||||
// Test roundrobin with only p0 subconns.
|
||||
p2 := <-cc.NewPickerCh
|
||||
@ -667,7 +667,7 @@ func (s) TestEDSPriority_HighPriorityNoEndpoints(t *testing.T) {
|
||||
clab1 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab1.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
clab1.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[1:2], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
|
||||
addrs1 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs1[0].Addr, testEndpointAddrs[0]; got != want {
|
||||
@ -676,8 +676,8 @@ func (s) TestEDSPriority_HighPriorityNoEndpoints(t *testing.T) {
|
||||
sc1 := <-cc.NewSubConnCh
|
||||
|
||||
// p0 is ready.
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Ready)
|
||||
|
||||
// Test roundrobin with only p0 subconns.
|
||||
p1 := <-cc.NewPickerCh
|
||||
@ -690,12 +690,12 @@ func (s) TestEDSPriority_HighPriorityNoEndpoints(t *testing.T) {
|
||||
clab2 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab2.AddLocality(testSubZones[0], 1, 0, nil, nil)
|
||||
clab2.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[1:2], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab2.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab2.Build()))
|
||||
|
||||
// p0 will remove the subconn, and ClientConn will send a sc update to
|
||||
// shutdown.
|
||||
scToRemove := <-cc.RemoveSubConnCh
|
||||
edsb.HandleSubConnStateChange(scToRemove, connectivity.Shutdown)
|
||||
edsb.handleSubConnStateChange(scToRemove, connectivity.Shutdown)
|
||||
|
||||
addrs2 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs2[0].Addr, testEndpointAddrs[1]; got != want {
|
||||
@ -704,8 +704,8 @@ func (s) TestEDSPriority_HighPriorityNoEndpoints(t *testing.T) {
|
||||
sc2 := <-cc.NewSubConnCh
|
||||
|
||||
// p1 is ready.
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Ready)
|
||||
|
||||
// Test roundrobin with only p1 subconns.
|
||||
p2 := <-cc.NewPickerCh
|
||||
@ -726,7 +726,7 @@ func (s) TestEDSPriority_HighPriorityAllUnhealthy(t *testing.T) {
|
||||
clab1 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab1.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
clab1.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[1:2], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
|
||||
addrs1 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs1[0].Addr, testEndpointAddrs[0]; got != want {
|
||||
@ -735,8 +735,8 @@ func (s) TestEDSPriority_HighPriorityAllUnhealthy(t *testing.T) {
|
||||
sc1 := <-cc.NewSubConnCh
|
||||
|
||||
// p0 is ready.
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Ready)
|
||||
|
||||
// Test roundrobin with only p0 subconns.
|
||||
p1 := <-cc.NewPickerCh
|
||||
@ -751,12 +751,12 @@ func (s) TestEDSPriority_HighPriorityAllUnhealthy(t *testing.T) {
|
||||
Health: []corepb.HealthStatus{corepb.HealthStatus_UNHEALTHY},
|
||||
})
|
||||
clab2.AddLocality(testSubZones[1], 1, 1, testEndpointAddrs[1:2], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab2.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab2.Build()))
|
||||
|
||||
// p0 will remove the subconn, and ClientConn will send a sc update to
|
||||
// transient failure.
|
||||
scToRemove := <-cc.RemoveSubConnCh
|
||||
edsb.HandleSubConnStateChange(scToRemove, connectivity.Shutdown)
|
||||
edsb.handleSubConnStateChange(scToRemove, connectivity.Shutdown)
|
||||
|
||||
addrs2 := <-cc.NewSubConnAddrsCh
|
||||
if got, want := addrs2[0].Addr, testEndpointAddrs[1]; got != want {
|
||||
@ -765,8 +765,8 @@ func (s) TestEDSPriority_HighPriorityAllUnhealthy(t *testing.T) {
|
||||
sc2 := <-cc.NewSubConnCh
|
||||
|
||||
// p1 is ready.
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Ready)
|
||||
|
||||
// Test roundrobin with only p1 subconns.
|
||||
p2 := <-cc.NewPickerCh
|
||||
|
@ -63,11 +63,11 @@ func (s) TestEDS_OneLocality(t *testing.T) {
|
||||
// One locality with one backend.
|
||||
clab1 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab1.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
|
||||
sc1 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Ready)
|
||||
|
||||
// Pick with only the first backend.
|
||||
p1 := <-cc.NewPickerCh
|
||||
@ -81,11 +81,11 @@ func (s) TestEDS_OneLocality(t *testing.T) {
|
||||
// The same locality, add one more backend.
|
||||
clab2 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab2.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:2], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab2.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab2.Build()))
|
||||
|
||||
sc2 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Ready)
|
||||
|
||||
// Test roundrobin with two subconns.
|
||||
p2 := <-cc.NewPickerCh
|
||||
@ -97,13 +97,13 @@ func (s) TestEDS_OneLocality(t *testing.T) {
|
||||
// The same locality, delete first backend.
|
||||
clab3 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab3.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[1:2], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab3.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab3.Build()))
|
||||
|
||||
scToRemove := <-cc.RemoveSubConnCh
|
||||
if !cmp.Equal(scToRemove, sc1, cmp.AllowUnexported(testutils.TestSubConn{})) {
|
||||
t.Fatalf("RemoveSubConn, want %v, got %v", sc1, scToRemove)
|
||||
}
|
||||
edsb.HandleSubConnStateChange(scToRemove, connectivity.Shutdown)
|
||||
edsb.handleSubConnStateChange(scToRemove, connectivity.Shutdown)
|
||||
|
||||
// Test pick with only the second subconn.
|
||||
p3 := <-cc.NewPickerCh
|
||||
@ -117,16 +117,16 @@ func (s) TestEDS_OneLocality(t *testing.T) {
|
||||
// The same locality, replace backend.
|
||||
clab4 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab4.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[2:3], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab4.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab4.Build()))
|
||||
|
||||
sc3 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc3, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc3, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc3, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc3, connectivity.Ready)
|
||||
scToRemove = <-cc.RemoveSubConnCh
|
||||
if !cmp.Equal(scToRemove, sc2, cmp.AllowUnexported(testutils.TestSubConn{})) {
|
||||
t.Fatalf("RemoveSubConn, want %v, got %v", sc2, scToRemove)
|
||||
}
|
||||
edsb.HandleSubConnStateChange(scToRemove, connectivity.Shutdown)
|
||||
edsb.handleSubConnStateChange(scToRemove, connectivity.Shutdown)
|
||||
|
||||
// Test pick with only the third subconn.
|
||||
p4 := <-cc.NewPickerCh
|
||||
@ -140,7 +140,7 @@ func (s) TestEDS_OneLocality(t *testing.T) {
|
||||
// The same locality, different drop rate, dropping 50%.
|
||||
clab5 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], []uint32{50})
|
||||
clab5.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[2:3], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab5.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab5.Build()))
|
||||
|
||||
// Picks with drops.
|
||||
p5 := <-cc.NewPickerCh
|
||||
@ -158,7 +158,7 @@ func (s) TestEDS_OneLocality(t *testing.T) {
|
||||
// The same locality, remove drops.
|
||||
clab6 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab6.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[2:3], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab6.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab6.Build()))
|
||||
|
||||
// Pick without drops.
|
||||
p6 := <-cc.NewPickerCh
|
||||
@ -184,19 +184,19 @@ func (s) TestEDS_TwoLocalities(t *testing.T) {
|
||||
// Two localities, each with one backend.
|
||||
clab1 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab1.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
sc1 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Ready)
|
||||
|
||||
// Add the second locality later to make sure sc2 belongs to the second
|
||||
// locality. Otherwise the test is flaky because of a map is used in EDS to
|
||||
// keep localities.
|
||||
clab1.AddLocality(testSubZones[1], 1, 0, testEndpointAddrs[1:2], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
sc2 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Ready)
|
||||
|
||||
// Test roundrobin with two subconns.
|
||||
p1 := <-cc.NewPickerCh
|
||||
@ -210,11 +210,11 @@ func (s) TestEDS_TwoLocalities(t *testing.T) {
|
||||
clab2.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
clab2.AddLocality(testSubZones[1], 1, 0, testEndpointAddrs[1:2], nil)
|
||||
clab2.AddLocality(testSubZones[2], 1, 0, testEndpointAddrs[2:3], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab2.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab2.Build()))
|
||||
|
||||
sc3 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc3, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc3, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc3, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc3, connectivity.Ready)
|
||||
|
||||
// Test roundrobin with three subconns.
|
||||
p2 := <-cc.NewPickerCh
|
||||
@ -227,13 +227,13 @@ func (s) TestEDS_TwoLocalities(t *testing.T) {
|
||||
clab3 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab3.AddLocality(testSubZones[1], 1, 0, testEndpointAddrs[1:2], nil)
|
||||
clab3.AddLocality(testSubZones[2], 1, 0, testEndpointAddrs[2:3], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab3.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab3.Build()))
|
||||
|
||||
scToRemove := <-cc.RemoveSubConnCh
|
||||
if !cmp.Equal(scToRemove, sc1, cmp.AllowUnexported(testutils.TestSubConn{})) {
|
||||
t.Fatalf("RemoveSubConn, want %v, got %v", sc1, scToRemove)
|
||||
}
|
||||
edsb.HandleSubConnStateChange(scToRemove, connectivity.Shutdown)
|
||||
edsb.handleSubConnStateChange(scToRemove, connectivity.Shutdown)
|
||||
|
||||
// Test pick with two subconns (without the first one).
|
||||
p3 := <-cc.NewPickerCh
|
||||
@ -246,11 +246,11 @@ func (s) TestEDS_TwoLocalities(t *testing.T) {
|
||||
clab4 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab4.AddLocality(testSubZones[1], 1, 0, testEndpointAddrs[1:2], nil)
|
||||
clab4.AddLocality(testSubZones[2], 1, 0, testEndpointAddrs[2:4], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab4.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab4.Build()))
|
||||
|
||||
sc4 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc4, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc4, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc4, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc4, connectivity.Ready)
|
||||
|
||||
// Test pick with two subconns (without the first one).
|
||||
p4 := <-cc.NewPickerCh
|
||||
@ -266,7 +266,7 @@ func (s) TestEDS_TwoLocalities(t *testing.T) {
|
||||
clab5 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab5.AddLocality(testSubZones[1], 2, 0, testEndpointAddrs[1:2], nil)
|
||||
clab5.AddLocality(testSubZones[2], 1, 0, testEndpointAddrs[2:4], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab5.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab5.Build()))
|
||||
|
||||
// Test pick with two subconns different locality weight.
|
||||
p5 := <-cc.NewPickerCh
|
||||
@ -282,7 +282,7 @@ func (s) TestEDS_TwoLocalities(t *testing.T) {
|
||||
clab6 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab6.AddLocality(testSubZones[1], 0, 0, testEndpointAddrs[1:2], nil)
|
||||
clab6.AddLocality(testSubZones[2], 1, 0, testEndpointAddrs[2:4], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab6.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab6.Build()))
|
||||
|
||||
// Changing weight of locality[1] to 0 caused it to be removed. It's subconn
|
||||
// should also be removed.
|
||||
@ -334,7 +334,7 @@ func (s) TestEDS_EndpointsHealth(t *testing.T) {
|
||||
corepb.HealthStatus_DEGRADED,
|
||||
},
|
||||
})
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
|
||||
var (
|
||||
readySCs []balancer.SubConn
|
||||
@ -344,8 +344,8 @@ func (s) TestEDS_EndpointsHealth(t *testing.T) {
|
||||
addr := <-cc.NewSubConnAddrsCh
|
||||
newSubConnAddrStrs = append(newSubConnAddrStrs, addr[0].Addr)
|
||||
sc := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc, connectivity.Ready)
|
||||
readySCs = append(readySCs, sc)
|
||||
}
|
||||
|
||||
@ -384,7 +384,7 @@ func (s) TestClose(t *testing.T) {
|
||||
edsb := newEDSBalancerImpl(nil, nil, nil, nil)
|
||||
// This is what could happen when switching between fallback and eds. This
|
||||
// make sure it doesn't panic.
|
||||
edsb.Close()
|
||||
edsb.close()
|
||||
}
|
||||
|
||||
// Create XDS balancer, and update sub-balancer before handling eds responses.
|
||||
@ -396,17 +396,17 @@ func (s) TestEDS_UpdateSubBalancerName(t *testing.T) {
|
||||
edsb.enqueueChildBalancerStateUpdate = edsb.updateState
|
||||
|
||||
t.Logf("update sub-balancer to test-const-balancer")
|
||||
edsb.HandleChildPolicy("test-const-balancer", nil)
|
||||
edsb.handleChildPolicy("test-const-balancer", nil)
|
||||
|
||||
// Two localities, each with one backend.
|
||||
clab1 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab1.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
clab1.AddLocality(testSubZones[1], 1, 0, testEndpointAddrs[1:2], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
sc := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc, connectivity.Ready)
|
||||
}
|
||||
|
||||
p0 := <-cc.NewPickerCh
|
||||
@ -418,18 +418,18 @@ func (s) TestEDS_UpdateSubBalancerName(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Logf("update sub-balancer to round-robin")
|
||||
edsb.HandleChildPolicy(roundrobin.Name, nil)
|
||||
edsb.handleChildPolicy(roundrobin.Name, nil)
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
<-cc.RemoveSubConnCh
|
||||
}
|
||||
|
||||
sc1 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Ready)
|
||||
sc2 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Ready)
|
||||
|
||||
// Test roundrobin with two subconns.
|
||||
p1 := <-cc.NewPickerCh
|
||||
@ -439,7 +439,7 @@ func (s) TestEDS_UpdateSubBalancerName(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Logf("update sub-balancer to test-const-balancer")
|
||||
edsb.HandleChildPolicy("test-const-balancer", nil)
|
||||
edsb.handleChildPolicy("test-const-balancer", nil)
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
scToRemove := <-cc.RemoveSubConnCh
|
||||
@ -447,12 +447,12 @@ func (s) TestEDS_UpdateSubBalancerName(t *testing.T) {
|
||||
!cmp.Equal(scToRemove, sc2, cmp.AllowUnexported(testutils.TestSubConn{})) {
|
||||
t.Fatalf("RemoveSubConn, want (%v or %v), got %v", sc1, sc2, scToRemove)
|
||||
}
|
||||
edsb.HandleSubConnStateChange(scToRemove, connectivity.Shutdown)
|
||||
edsb.handleSubConnStateChange(scToRemove, connectivity.Shutdown)
|
||||
}
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
sc := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc, connectivity.Ready)
|
||||
}
|
||||
|
||||
p2 := <-cc.NewPickerCh
|
||||
@ -464,18 +464,18 @@ func (s) TestEDS_UpdateSubBalancerName(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Logf("update sub-balancer to round-robin")
|
||||
edsb.HandleChildPolicy(roundrobin.Name, nil)
|
||||
edsb.handleChildPolicy(roundrobin.Name, nil)
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
<-cc.RemoveSubConnCh
|
||||
}
|
||||
|
||||
sc3 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc3, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc3, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc3, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc3, connectivity.Ready)
|
||||
sc4 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc4, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc4, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc4, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc4, connectivity.Ready)
|
||||
|
||||
p3 := <-cc.NewPickerCh
|
||||
want = []balancer.SubConn{sc3, sc4}
|
||||
@ -531,11 +531,11 @@ func (s) TestEDS_ChildPolicyUpdatePickerInline(t *testing.T) {
|
||||
go edsb.updateState(p, state)
|
||||
}
|
||||
|
||||
edsb.HandleChildPolicy("test-inline-update-balancer", nil)
|
||||
edsb.handleChildPolicy("test-inline-update-balancer", nil)
|
||||
|
||||
clab1 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab1.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
|
||||
p0 := <-cc.NewPickerCh
|
||||
for i := 0; i < 5; i++ {
|
||||
@ -623,10 +623,10 @@ func (s) TestEDS_LoadReport(t *testing.T) {
|
||||
// Two localities, each with one backend.
|
||||
clab1 := xdsclient.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
|
||||
clab1.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
sc1 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc1, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc1, connectivity.Ready)
|
||||
backendToBalancerID[sc1] = internal.LocalityID{
|
||||
SubZone: testSubZones[0],
|
||||
}
|
||||
@ -635,10 +635,10 @@ func (s) TestEDS_LoadReport(t *testing.T) {
|
||||
// locality. Otherwise the test is flaky because of a map is used in EDS to
|
||||
// keep localities.
|
||||
clab1.AddLocality(testSubZones[1], 1, 0, testEndpointAddrs[1:2], nil)
|
||||
edsb.HandleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
edsb.handleEDSResponse(xdsclient.ParseEDSRespProtoForTesting(clab1.Build()))
|
||||
sc2 := <-cc.NewSubConnCh
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.HandleSubConnStateChange(sc2, connectivity.Ready)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Connecting)
|
||||
edsb.handleSubConnStateChange(sc2, connectivity.Ready)
|
||||
backendToBalancerID[sc2] = internal.LocalityID{
|
||||
SubZone: testSubZones[1],
|
||||
}
|
||||
|
@ -100,16 +100,16 @@ type fakeEDSBalancer struct {
|
||||
loadStore lrs.Store
|
||||
}
|
||||
|
||||
func (f *fakeEDSBalancer) HandleSubConnStateChange(sc balancer.SubConn, state connectivity.State) {
|
||||
func (f *fakeEDSBalancer) handleSubConnStateChange(sc balancer.SubConn, state connectivity.State) {
|
||||
f.subconnStateChange.Send(&scStateChange{sc: sc, state: state})
|
||||
}
|
||||
|
||||
func (f *fakeEDSBalancer) HandleChildPolicy(name string, config json.RawMessage) {
|
||||
func (f *fakeEDSBalancer) handleChildPolicy(name string, config json.RawMessage) {
|
||||
f.childPolicy.Send(&loadBalancingConfig{Name: name, Config: config})
|
||||
}
|
||||
|
||||
func (f *fakeEDSBalancer) Close() {}
|
||||
func (f *fakeEDSBalancer) HandleEDSResponse(edsResp xdsclient.EndpointsUpdate) {}
|
||||
func (f *fakeEDSBalancer) close() {}
|
||||
func (f *fakeEDSBalancer) handleEDSResponse(edsResp xdsclient.EndpointsUpdate) {}
|
||||
func (f *fakeEDSBalancer) updateState(priority priorityType, s balancer.State) {}
|
||||
|
||||
func (f *fakeEDSBalancer) waitForChildPolicy(wantPolicy *loadBalancingConfig) error {
|
||||
|
Reference in New Issue
Block a user