etcdserver: remove unnecessary newTestMemberp

This commit is contained in:
Xiang Li
2014-11-11 11:09:33 -08:00
parent 077e144e8a
commit e4931e0c47
4 changed files with 65 additions and 70 deletions

View File

@ -36,9 +36,9 @@ func TestClusterFromString(t *testing.T) {
{
"mem1=http://10.0.0.1:2379,mem1=http://128.193.4.20:2379,mem2=http://10.0.0.2:2379,default=http://127.0.0.1:2379",
[]Member{
newTestMember(4322322643958477905, []string{"http://10.0.0.1:2379", "http://128.193.4.20:2379"}, "mem1", nil),
newTestMember(3141198903430435750, []string{"http://10.0.0.2:2379"}, "mem2", nil),
newTestMember(12762790032478827328, []string{"http://127.0.0.1:2379"}, "default", nil),
*newTestMember(4322322643958477905, []string{"http://10.0.0.1:2379", "http://128.193.4.20:2379"}, "mem1", nil),
*newTestMember(3141198903430435750, []string{"http://10.0.0.2:2379"}, "mem2", nil),
*newTestMember(12762790032478827328, []string{"http://127.0.0.1:2379"}, "default", nil),
},
},
}
@ -83,15 +83,15 @@ func TestClusterFromStore(t *testing.T) {
mems []Member
}{
{
[]Member{newTestMember(1, nil, "node1", nil)},
[]Member{*newTestMember(1, nil, "node1", nil)},
},
{
[]Member{},
},
{
[]Member{
newTestMember(1, nil, "node1", nil),
newTestMember(2, nil, "node2", nil),
*newTestMember(1, nil, "node1", nil),
*newTestMember(2, nil, "node2", nil),
},
},
}
@ -113,8 +113,8 @@ func TestClusterFromStore(t *testing.T) {
func TestClusterMember(t *testing.T) {
membs := []Member{
newTestMember(1, nil, "node1", nil),
newTestMember(2, nil, "node2", nil),
*newTestMember(1, nil, "node1", nil),
*newTestMember(2, nil, "node2", nil),
}
tests := []struct {
id types.ID
@ -138,8 +138,8 @@ func TestClusterMember(t *testing.T) {
func TestClusterMemberByName(t *testing.T) {
membs := []Member{
newTestMember(1, nil, "node1", nil),
newTestMember(2, nil, "node2", nil),
*newTestMember(1, nil, "node1", nil),
*newTestMember(2, nil, "node2", nil),
}
tests := []struct {
name string
@ -163,9 +163,9 @@ func TestClusterMemberByName(t *testing.T) {
func TestClusterMemberIDs(t *testing.T) {
c := newTestCluster([]Member{
newTestMember(1, nil, "", nil),
newTestMember(4, nil, "", nil),
newTestMember(100, nil, "", nil),
*newTestMember(1, nil, "", nil),
*newTestMember(4, nil, "", nil),
*newTestMember(100, nil, "", nil),
})
w := []types.ID{1, 4, 100}
g := c.MemberIDs()
@ -182,7 +182,7 @@ func TestClusterPeerURLs(t *testing.T) {
// single peer with a single address
{
mems: []Member{
newTestMember(1, []string{"http://192.0.2.1"}, "", nil),
*newTestMember(1, []string{"http://192.0.2.1"}, "", nil),
},
wurls: []string{"http://192.0.2.1"},
},
@ -190,7 +190,7 @@ func TestClusterPeerURLs(t *testing.T) {
// single peer with a single address with a port
{
mems: []Member{
newTestMember(1, []string{"http://192.0.2.1:8001"}, "", nil),
*newTestMember(1, []string{"http://192.0.2.1:8001"}, "", nil),
},
wurls: []string{"http://192.0.2.1:8001"},
},
@ -198,9 +198,9 @@ func TestClusterPeerURLs(t *testing.T) {
// several members explicitly unsorted
{
mems: []Member{
newTestMember(2, []string{"http://192.0.2.3", "http://192.0.2.4"}, "", nil),
newTestMember(3, []string{"http://192.0.2.5", "http://192.0.2.6"}, "", nil),
newTestMember(1, []string{"http://192.0.2.1", "http://192.0.2.2"}, "", nil),
*newTestMember(2, []string{"http://192.0.2.3", "http://192.0.2.4"}, "", nil),
*newTestMember(3, []string{"http://192.0.2.5", "http://192.0.2.6"}, "", nil),
*newTestMember(1, []string{"http://192.0.2.1", "http://192.0.2.2"}, "", nil),
},
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"},
},
@ -214,7 +214,7 @@ func TestClusterPeerURLs(t *testing.T) {
// peer with no peer urls
{
mems: []Member{
newTestMember(3, []string{}, "", nil),
*newTestMember(3, []string{}, "", nil),
},
wurls: []string{},
},
@ -237,7 +237,7 @@ func TestClusterClientURLs(t *testing.T) {
// single peer with a single address
{
mems: []Member{
newTestMember(1, nil, "", []string{"http://192.0.2.1"}),
*newTestMember(1, nil, "", []string{"http://192.0.2.1"}),
},
wurls: []string{"http://192.0.2.1"},
},
@ -245,7 +245,7 @@ func TestClusterClientURLs(t *testing.T) {
// single peer with a single address with a port
{
mems: []Member{
newTestMember(1, nil, "", []string{"http://192.0.2.1:8001"}),
*newTestMember(1, nil, "", []string{"http://192.0.2.1:8001"}),
},
wurls: []string{"http://192.0.2.1:8001"},
},
@ -253,9 +253,9 @@ func TestClusterClientURLs(t *testing.T) {
// several members explicitly unsorted
{
mems: []Member{
newTestMember(2, nil, "", []string{"http://192.0.2.3", "http://192.0.2.4"}),
newTestMember(3, nil, "", []string{"http://192.0.2.5", "http://192.0.2.6"}),
newTestMember(1, nil, "", []string{"http://192.0.2.1", "http://192.0.2.2"}),
*newTestMember(2, nil, "", []string{"http://192.0.2.3", "http://192.0.2.4"}),
*newTestMember(3, nil, "", []string{"http://192.0.2.5", "http://192.0.2.6"}),
*newTestMember(1, nil, "", []string{"http://192.0.2.1", "http://192.0.2.2"}),
},
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"},
},
@ -269,7 +269,7 @@ func TestClusterClientURLs(t *testing.T) {
// peer with no client urls
{
mems: []Member{
newTestMember(3, nil, "", []string{}),
*newTestMember(3, nil, "", []string{}),
},
wurls: []string{},
},
@ -292,28 +292,28 @@ func TestClusterValidateAndAssignIDsBad(t *testing.T) {
{
// unmatched length
[]Member{
newTestMember(1, []string{"http://127.0.0.1:2379"}, "", nil),
*newTestMember(1, []string{"http://127.0.0.1:2379"}, "", nil),
},
[]*Member{},
},
{
// unmatched peer urls
[]Member{
newTestMember(1, []string{"http://127.0.0.1:2379"}, "", nil),
*newTestMember(1, []string{"http://127.0.0.1:2379"}, "", nil),
},
[]*Member{
newTestMemberp(1, []string{"http://127.0.0.1:4001"}, "", nil),
newTestMember(1, []string{"http://127.0.0.1:4001"}, "", nil),
},
},
{
// unmatched peer urls
[]Member{
newTestMember(1, []string{"http://127.0.0.1:2379"}, "", nil),
newTestMember(2, []string{"http://127.0.0.2:2379"}, "", nil),
*newTestMember(1, []string{"http://127.0.0.1:2379"}, "", nil),
*newTestMember(2, []string{"http://127.0.0.2:2379"}, "", nil),
},
[]*Member{
newTestMemberp(1, []string{"http://127.0.0.1:2379"}, "", nil),
newTestMemberp(2, []string{"http://127.0.0.2:4001"}, "", nil),
newTestMember(1, []string{"http://127.0.0.1:2379"}, "", nil),
newTestMember(2, []string{"http://127.0.0.2:4001"}, "", nil),
},
},
}
@ -333,12 +333,12 @@ func TestClusterValidateAndAssignIDs(t *testing.T) {
}{
{
[]Member{
newTestMember(1, []string{"http://127.0.0.1:2379"}, "", nil),
newTestMember(2, []string{"http://127.0.0.2:2379"}, "", nil),
*newTestMember(1, []string{"http://127.0.0.1:2379"}, "", nil),
*newTestMember(2, []string{"http://127.0.0.2:2379"}, "", nil),
},
[]*Member{
newTestMemberp(3, []string{"http://127.0.0.1:2379"}, "", nil),
newTestMemberp(4, []string{"http://127.0.0.2:2379"}, "", nil),
newTestMember(3, []string{"http://127.0.0.1:2379"}, "", nil),
newTestMember(4, []string{"http://127.0.0.2:2379"}, "", nil),
},
[]types.ID{3, 4},
},
@ -427,8 +427,8 @@ func TestClusterValidateConfigurationChange(t *testing.T) {
func TestClusterGenID(t *testing.T) {
cs := newTestCluster([]Member{
newTestMember(1, nil, "", nil),
newTestMember(2, nil, "", nil),
*newTestMember(1, nil, "", nil),
*newTestMember(2, nil, "", nil),
})
cs.genID()
@ -438,7 +438,7 @@ func TestClusterGenID(t *testing.T) {
previd := cs.ID()
cs.SetStore(&storeRecorder{})
cs.AddMember(newTestMemberp(3, nil, "", nil))
cs.AddMember(newTestMember(3, nil, "", nil))
cs.genID()
if cs.ID() == previd {
t.Fatalf("cluster.ID = %v, want not %v", cs.ID(), previd)
@ -481,7 +481,7 @@ func TestClusterAddMember(t *testing.T) {
st := &storeRecorder{}
c := newTestCluster(nil)
c.SetStore(st)
c.AddMember(newTestMemberp(1, nil, "node1", nil))
c.AddMember(newTestMember(1, nil, "node1", nil))
wactions := []action{
{
@ -535,32 +535,32 @@ func TestClusterMembers(t *testing.T) {
func TestClusterString(t *testing.T) {
cls := &Cluster{
members: map[types.ID]*Member{
1: newTestMemberp(
1: newTestMember(
1,
[]string{"http://1.1.1.1:1111", "http://0.0.0.0:0000"},
"abc",
nil,
),
2: newTestMemberp(
2: newTestMember(
2,
[]string{"http://2.2.2.2:2222"},
"def",
nil,
),
3: newTestMemberp(
3: newTestMember(
3,
[]string{"http://3.3.3.3:1234", "http://127.0.0.1:7001"},
"ghi",
nil,
),
// no PeerURLs = not included
4: newTestMemberp(
4: newTestMember(
4,
[]string{},
"four",
nil,
),
5: newTestMemberp(
5: newTestMember(
5,
nil,
"five",

View File

@ -63,7 +63,7 @@ func TestMemberPick(t *testing.T) {
urls map[string]bool
}{
{
newTestMemberp(1, []string{"abc", "def", "ghi", "jkl", "mno", "pqr", "stu"}, "", nil),
newTestMember(1, []string{"abc", "def", "ghi", "jkl", "mno", "pqr", "stu"}, "", nil),
map[string]bool{
"abc": true,
"def": true,
@ -75,7 +75,7 @@ func TestMemberPick(t *testing.T) {
},
},
{
newTestMemberp(2, []string{"xyz"}, "", nil),
newTestMember(2, []string{"xyz"}, "", nil),
map[string]bool{"xyz": true},
},
}
@ -92,10 +92,10 @@ func TestMemberPick(t *testing.T) {
func TestMemberClone(t *testing.T) {
tests := []*Member{
newTestMemberp(1, nil, "abc", nil),
newTestMemberp(1, []string{"http://a"}, "abc", nil),
newTestMemberp(1, nil, "abc", []string{"http://b"}),
newTestMemberp(1, []string{"http://a"}, "abc", []string{"http://b"}),
newTestMember(1, nil, "abc", nil),
newTestMember(1, []string{"http://a"}, "abc", nil),
newTestMember(1, nil, "abc", []string{"http://b"}),
newTestMember(1, []string{"http://a"}, "abc", []string{"http://b"}),
}
for i, tt := range tests {
nm := tt.Clone()
@ -108,15 +108,10 @@ func TestMemberClone(t *testing.T) {
}
}
func newTestMember(id uint64, peerURLs []string, name string, clientURLs []string) Member {
return Member{
func newTestMember(id uint64, peerURLs []string, name string, clientURLs []string) *Member {
return &Member{
ID: types.ID(id),
RaftAttributes: RaftAttributes{PeerURLs: peerURLs},
Attributes: Attributes{Name: name, ClientURLs: clientURLs},
}
}
func newTestMemberp(id uint64, peerURLs []string, name string, clientURLs []string) *Member {
m := newTestMember(id, peerURLs, name, clientURLs)
return &m
}

View File

@ -25,9 +25,9 @@ import (
func TestSendHubInitSenders(t *testing.T) {
membs := []Member{
newTestMember(1, []string{"http://a"}, "", nil),
newTestMember(2, []string{"http://b"}, "", nil),
newTestMember(3, []string{"http://c"}, "", nil),
*newTestMember(1, []string{"http://a"}, "", nil),
*newTestMember(2, []string{"http://b"}, "", nil),
*newTestMember(3, []string{"http://c"}, "", nil),
}
cl := newTestCluster(membs)
ls := stats.NewLeaderStats("")
@ -48,7 +48,7 @@ func TestSendHubAdd(t *testing.T) {
cl := newTestCluster(nil)
ls := stats.NewLeaderStats("")
h := newSendHub(nil, cl, nil, ls)
m := newTestMemberp(1, []string{"http://a"}, "", nil)
m := newTestMember(1, []string{"http://a"}, "", nil)
h.Add(m)
if _, ok := ls.Followers["1"]; !ok {
@ -71,7 +71,7 @@ func TestSendHubAdd(t *testing.T) {
func TestSendHubRemove(t *testing.T) {
membs := []Member{
newTestMember(1, []string{"http://a"}, "", nil),
*newTestMember(1, []string{"http://a"}, "", nil),
}
cl := newTestCluster(membs)
ls := stats.NewLeaderStats("")

View File

@ -1101,25 +1101,25 @@ func TestGetOtherPeerURLs(t *testing.T) {
}{
{
[]*Member{
newTestMemberp(1, []string{"http://10.0.0.1"}, "a", nil),
newTestMember(1, []string{"http://10.0.0.1"}, "a", nil),
},
"a",
[]string{},
},
{
[]*Member{
newTestMemberp(1, []string{"http://10.0.0.1"}, "a", nil),
newTestMemberp(2, []string{"http://10.0.0.2"}, "b", nil),
newTestMemberp(3, []string{"http://10.0.0.3"}, "c", nil),
newTestMember(1, []string{"http://10.0.0.1"}, "a", nil),
newTestMember(2, []string{"http://10.0.0.2"}, "b", nil),
newTestMember(3, []string{"http://10.0.0.3"}, "c", nil),
},
"a",
[]string{"http://10.0.0.2", "http://10.0.0.3"},
},
{
[]*Member{
newTestMemberp(1, []string{"http://10.0.0.1"}, "a", nil),
newTestMemberp(3, []string{"http://10.0.0.3"}, "c", nil),
newTestMemberp(2, []string{"http://10.0.0.2"}, "b", nil),
newTestMember(1, []string{"http://10.0.0.1"}, "a", nil),
newTestMember(3, []string{"http://10.0.0.3"}, "c", nil),
newTestMember(2, []string{"http://10.0.0.2"}, "b", nil),
},
"a",
[]string{"http://10.0.0.2", "http://10.0.0.3"},