etcdserver: apply config change on cluster store

This commit is contained in:
Yicheng Qin
2014-09-30 15:14:44 -07:00
parent 2e0fec7a84
commit d051af4d3d
5 changed files with 101 additions and 27 deletions

View File

@ -128,7 +128,7 @@ func TestDoBadLocalAction(t *testing.T) {
}
}
func TestApply(t *testing.T) {
func TestApplyRequest(t *testing.T) {
tests := []struct {
req pb.Request
@ -356,7 +356,7 @@ func TestApply(t *testing.T) {
for i, tt := range tests {
st := &storeRecorder{}
srv := &EtcdServer{store: st}
resp := srv.apply(tt.req)
resp := srv.applyRequest(tt.req)
if !reflect.DeepEqual(resp, tt.wresp) {
t.Errorf("#%d: resp = %+v, want %+v", i, resp, tt.wresp)
@ -786,17 +786,20 @@ func TestRecvSlowSnapshot(t *testing.T) {
}
}
// TestAddNode tests AddNode can propose and perform node addition.
func TestAddNode(t *testing.T) {
// TestAddMember tests AddMember can propose and perform node addition.
func TestAddMember(t *testing.T) {
n := newNodeConfChangeCommitterRecorder()
cs := &clusterStoreRecorder{}
s := &EtcdServer{
node: n,
store: &storeRecorder{},
send: func(_ []raftpb.Message) {},
storage: &storageRecorder{},
node: n,
store: &storeRecorder{},
send: func(_ []raftpb.Message) {},
storage: &storageRecorder{},
ClusterStore: cs,
}
s.start()
s.AddNode(context.TODO(), 1, []byte("foo"))
m := Member{ID: 1, PeerURLs: []string{"foo"}}
s.AddMember(context.TODO(), m)
gaction := n.Action()
s.Stop()
@ -804,19 +807,26 @@ func TestAddNode(t *testing.T) {
if !reflect.DeepEqual(gaction, wactions) {
t.Errorf("action = %v, want %v", gaction, wactions)
}
wcsactions := []action{{name: "Create", params: []interface{}{m}}}
if g := cs.Action(); !reflect.DeepEqual(g, wcsactions) {
t.Errorf("csaction = %v, want %v", g, wcsactions)
}
}
// TestRemoveNode tests RemoveNode can propose and perform node removal.
func TestRemoveNode(t *testing.T) {
// TestRemoveMember tests RemoveMember can propose and perform node removal.
func TestRemoveMember(t *testing.T) {
n := newNodeConfChangeCommitterRecorder()
cs := &clusterStoreRecorder{}
s := &EtcdServer{
node: n,
store: &storeRecorder{},
send: func(_ []raftpb.Message) {},
storage: &storageRecorder{},
node: n,
store: &storeRecorder{},
send: func(_ []raftpb.Message) {},
storage: &storageRecorder{},
ClusterStore: cs,
}
s.start()
s.RemoveNode(context.TODO(), 1)
id := int64(1)
s.RemoveMember(context.TODO(), id)
gaction := n.Action()
s.Stop()
@ -824,6 +834,10 @@ func TestRemoveNode(t *testing.T) {
if !reflect.DeepEqual(gaction, wactions) {
t.Errorf("action = %v, want %v", gaction, wactions)
}
wcsactions := []action{{name: "Delete", params: []interface{}{id}}}
if g := cs.Action(); !reflect.DeepEqual(g, wcsactions) {
t.Errorf("csaction = %v, want %v", g, wcsactions)
}
}
// TestServerStopItself tests that if node sends out Ready with ShouldStop,
@ -1230,6 +1244,21 @@ func (w *waitWithResponse) Register(id int64) <-chan interface{} {
}
func (w *waitWithResponse) Trigger(id int64, x interface{}) {}
type clusterStoreRecorder struct {
recorder
}
func (cs *clusterStoreRecorder) Create(m Member) {
cs.record(action{name: "Create", params: []interface{}{m}})
}
func (cs *clusterStoreRecorder) Get() Cluster {
cs.record(action{name: "Get"})
return nil
}
func (cs *clusterStoreRecorder) Delete(id int64) {
cs.record(action{name: "Delete", params: []interface{}{id}})
}
func mustClusterStore(t *testing.T, membs []Member) ClusterStore {
c := Cluster{}
if err := c.AddSlice(membs); err != nil {