diff --git a/etcdserver/sender.go b/etcdserver/sender.go index f81e9e7d3..cef098315 100644 --- a/etcdserver/sender.go +++ b/etcdserver/sender.go @@ -44,7 +44,7 @@ type sendHub struct { // newSendHub creates the default send hub used to transport raft messages // to other members. The returned sendHub will update the given ServerStats and // LeaderStats appropriately. -func newSendHub(t *http.Transport, cl *Cluster, ss *stats.ServerStats, ls *stats.LeaderStats) *sendHub { +func newSendHub(t *http.Transport, cl ClusterInfo, ss *stats.ServerStats, ls *stats.LeaderStats) *sendHub { h := &sendHub{ tr: t, cl: cl, diff --git a/etcdserver/sender_test.go b/etcdserver/sender_test.go new file mode 100644 index 000000000..3fb73b4ff --- /dev/null +++ b/etcdserver/sender_test.go @@ -0,0 +1,78 @@ +/* + Copyright 2014 CoreOS, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package etcdserver + +import ( + "testing" + + "github.com/coreos/etcd/etcdserver/stats" + "github.com/coreos/etcd/pkg/types" +) + +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), + } + cl := newTestCluster(membs) + ls := stats.NewLeaderStats("") + h := newSendHub(nil, cl, nil, ls) + + ids := cl.MemberIDs() + if len(h.senders) != len(ids) { + t.Errorf("len(ids) = %d, want %d", len(h.senders), len(ids)) + } + for _, id := range ids { + if _, ok := h.senders[id]; !ok { + t.Errorf("senders[%s] is nil, want exists", id) + } + } +} + +func TestSendHubAdd(t *testing.T) { + cl := newTestCluster(nil) + ls := stats.NewLeaderStats("") + h := newSendHub(nil, cl, nil, ls) + m := newTestMemberp(1, []string{"http://a"}, "", nil) + h.Add(m) + + if _, ok := ls.Followers["1"]; !ok { + t.Errorf("FollowerStats[1] is nil, want exists") + } + s, ok := h.senders[types.ID(1)] + if !ok { + t.Fatalf("senders[1] is nil, want exists") + } + if s.u != "http://a/raft" { + t.Errorf("url = %s, want %s", s.u, "http://a/raft") + } +} + +func TestSendHubRemove(t *testing.T) { + membs := []Member{ + newTestMember(1, []string{"http://a"}, "", nil), + } + cl := newTestCluster(membs) + ls := stats.NewLeaderStats("") + h := newSendHub(nil, cl, nil, ls) + h.Remove(types.ID(1)) + + if _, ok := h.senders[types.ID(1)]; ok { + t.Fatalf("senders[1] exists, want removed") + } +}