etcdserver: Cluster.Endpoints() -> Cluster.PeerURLs()

This commit is contained in:
Yicheng Qin 2014-09-28 14:38:40 -07:00
parent e83f851995
commit 5784693a39
3 changed files with 18 additions and 18 deletions

View File

@ -99,10 +99,10 @@ func (c Cluster) IDs() []int64 {
return ids return ids
} }
// Endpoints returns a list of all peer addresses. Each address is prefixed // PeerURLs returns a list of all peer addresses. Each address is prefixed
// with the scheme (currently "http://"). The returned list is sorted in // with the scheme (currently "http://"). The returned list is sorted in
// ascending lexicographical order. // ascending lexicographical order.
func (c Cluster) Endpoints() []string { func (c Cluster) PeerURLs() []string {
endpoints := make([]string, 0) endpoints := make([]string, 0)
for _, p := range c { for _, p := range c {
for _, addr := range p.PeerURLs { for _, addr := range p.PeerURLs {

View File

@ -143,17 +143,17 @@ func TestClusterAddBad(t *testing.T) {
} }
} }
func TestClusterGetEndpoints(t *testing.T) { func TestClusterPeerURLs(t *testing.T) {
tests := []struct { tests := []struct {
mems []Member mems []Member
endpoints []string wurls []string
}{ }{
// single peer with a single address // single peer with a single address
{ {
mems: []Member{ mems: []Member{
{ID: 1, PeerURLs: []string{"192.0.2.1"}}, {ID: 1, PeerURLs: []string{"192.0.2.1"}},
}, },
endpoints: []string{"http://192.0.2.1"}, wurls: []string{"http://192.0.2.1"},
}, },
// single peer with a single address with a port // single peer with a single address with a port
@ -161,7 +161,7 @@ func TestClusterGetEndpoints(t *testing.T) {
mems: []Member{ mems: []Member{
{ID: 1, PeerURLs: []string{"192.0.2.1:8001"}}, {ID: 1, PeerURLs: []string{"192.0.2.1:8001"}},
}, },
endpoints: []string{"http://192.0.2.1:8001"}, wurls: []string{"http://192.0.2.1:8001"},
}, },
// several members explicitly unsorted // several members explicitly unsorted
@ -171,21 +171,21 @@ func TestClusterGetEndpoints(t *testing.T) {
{ID: 3, PeerURLs: []string{"192.0.2.5", "192.0.2.6"}}, {ID: 3, PeerURLs: []string{"192.0.2.5", "192.0.2.6"}},
{ID: 1, PeerURLs: []string{"192.0.2.1", "192.0.2.2"}}, {ID: 1, PeerURLs: []string{"192.0.2.1", "192.0.2.2"}},
}, },
endpoints: []string{"http://192.0.2.1", "http://192.0.2.2", "http://192.0.2.3", "http://192.0.2.4", "http://192.0.2.5", "http://192.0.2.6"}, wurls: []string{"http://192.0.2.1", "http://192.0.2.2", "http://192.0.2.3", "http://192.0.2.4", "http://192.0.2.5", "http://192.0.2.6"},
}, },
// no members // no members
{ {
mems: []Member{}, mems: []Member{},
endpoints: []string{}, wurls: []string{},
}, },
// peer with no endpoints // peer with no peer urls
{ {
mems: []Member{ mems: []Member{
{ID: 3, PeerURLs: []string{}}, {ID: 3, PeerURLs: []string{}},
}, },
endpoints: []string{}, wurls: []string{},
}, },
} }
@ -195,9 +195,9 @@ func TestClusterGetEndpoints(t *testing.T) {
t.Errorf("AddSlice error: %v", err) t.Errorf("AddSlice error: %v", err)
continue continue
} }
endpoints := c.Endpoints() urls := c.PeerURLs()
if !reflect.DeepEqual(tt.endpoints, endpoints) { if !reflect.DeepEqual(urls, tt.wurls) {
t.Errorf("#%d: members.Endpoints() incorrect: want=%#v got=%#v", i, tt.endpoints, endpoints) t.Errorf("#%d: PeerURLs = %v, want %v", i, urls, tt.wurls)
} }
} }
} }
@ -239,7 +239,7 @@ func TestClusterClientURLs(t *testing.T) {
wurls: []string{}, wurls: []string{},
}, },
// peer with no endpoints // peer with no client urls
{ {
mems: []Member{ mems: []Member{
{ID: 3, ClientURLs: []string{}}, {ID: 3, ClientURLs: []string{}},
@ -256,7 +256,7 @@ func TestClusterClientURLs(t *testing.T) {
} }
urls := c.ClientURLs() urls := c.ClientURLs()
if !reflect.DeepEqual(urls, tt.wurls) { if !reflect.DeepEqual(urls, tt.wurls) {
t.Errorf("#%d: ClientURLs = %v, want %v", i, tt.wurls, urls) t.Errorf("#%d: ClientURLs = %v, want %v", i, urls, tt.wurls)
} }
} }
} }

View File

@ -247,7 +247,7 @@ func startProxy() {
log.Fatal(err) log.Fatal(err)
} }
ph, err := proxy.NewHandler(pt, (*cluster).Endpoints()) ph, err := proxy.NewHandler(pt, (*cluster).PeerURLs())
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }