|
|
@@ -27,17 +27,17 @@ import (
|
|
|
"github.com/coreos/etcd/raft/raftpb"
|
|
|
)
|
|
|
|
|
|
-// TestSenderSend tests that send func could post data using roundtripper
|
|
|
+// TestPipelineSend tests that pipeline could send data using roundtripper
|
|
|
// and increase success count in stats.
|
|
|
-func TestSenderSend(t *testing.T) {
|
|
|
+func TestPipelineSend(t *testing.T) {
|
|
|
tr := &roundTripperRecorder{}
|
|
|
fs := &stats.FollowerStats{}
|
|
|
- p := NewPeer(tr, "http://10.0.0.1", types.ID(1), types.ID(1), &nopProcessor{}, fs, nil)
|
|
|
+ p := newPipeline(tr, "http://10.0.0.1", types.ID(1), types.ID(1), fs, nil)
|
|
|
|
|
|
- if err := p.Send(raftpb.Message{Type: raftpb.MsgApp}); err != nil {
|
|
|
+ if err := p.send(raftpb.Message{Type: raftpb.MsgApp}); err != nil {
|
|
|
t.Fatalf("unexpect send error: %v", err)
|
|
|
}
|
|
|
- p.Stop()
|
|
|
+ p.stop()
|
|
|
|
|
|
if tr.Request() == nil {
|
|
|
t.Errorf("sender fails to post the data")
|
|
|
@@ -49,15 +49,15 @@ func TestSenderSend(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func TestSenderExceedMaximalServing(t *testing.T) {
|
|
|
+func TestPipelineExceedMaximalServing(t *testing.T) {
|
|
|
tr := newRoundTripperBlocker()
|
|
|
fs := &stats.FollowerStats{}
|
|
|
- p := NewPeer(tr, "http://10.0.0.1", types.ID(1), types.ID(1), &nopProcessor{}, fs, nil)
|
|
|
+ p := newPipeline(tr, "http://10.0.0.1", types.ID(1), types.ID(1), fs, nil)
|
|
|
|
|
|
// keep the sender busy and make the buffer full
|
|
|
// nothing can go out as we block the sender
|
|
|
- for i := 0; i < connPerSender+senderBufSize; i++ {
|
|
|
- if err := p.Send(raftpb.Message{}); err != nil {
|
|
|
+ for i := 0; i < connPerPipeline+pipelineBufSize; i++ {
|
|
|
+ if err := p.send(raftpb.Message{}); err != nil {
|
|
|
t.Errorf("send err = %v, want nil", err)
|
|
|
}
|
|
|
// force the sender to grab data
|
|
|
@@ -65,7 +65,7 @@ func TestSenderExceedMaximalServing(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
// try to send a data when we are sure the buffer is full
|
|
|
- if err := p.Send(raftpb.Message{}); err == nil {
|
|
|
+ if err := p.send(raftpb.Message{}); err == nil {
|
|
|
t.Errorf("unexpect send success")
|
|
|
}
|
|
|
|
|
|
@@ -74,22 +74,22 @@ func TestSenderExceedMaximalServing(t *testing.T) {
|
|
|
testutil.ForceGosched()
|
|
|
|
|
|
// It could send new data after previous ones succeed
|
|
|
- if err := p.Send(raftpb.Message{}); err != nil {
|
|
|
+ if err := p.send(raftpb.Message{}); err != nil {
|
|
|
t.Errorf("send err = %v, want nil", err)
|
|
|
}
|
|
|
- p.Stop()
|
|
|
+ p.stop()
|
|
|
}
|
|
|
|
|
|
-// TestSenderSendFailed tests that when send func meets the post error,
|
|
|
+// TestPipelineSendFailed tests that when send func meets the post error,
|
|
|
// it increases fail count in stats.
|
|
|
-func TestSenderSendFailed(t *testing.T) {
|
|
|
+func TestPipelineSendFailed(t *testing.T) {
|
|
|
fs := &stats.FollowerStats{}
|
|
|
- p := NewPeer(newRespRoundTripper(0, errors.New("blah")), "http://10.0.0.1", types.ID(1), types.ID(1), &nopProcessor{}, fs, nil)
|
|
|
+ p := newPipeline(newRespRoundTripper(0, errors.New("blah")), "http://10.0.0.1", types.ID(1), types.ID(1), fs, nil)
|
|
|
|
|
|
- if err := p.Send(raftpb.Message{Type: raftpb.MsgApp}); err != nil {
|
|
|
+ if err := p.send(raftpb.Message{Type: raftpb.MsgApp}); err != nil {
|
|
|
t.Fatalf("unexpect Send error: %v", err)
|
|
|
}
|
|
|
- p.Stop()
|
|
|
+ p.stop()
|
|
|
|
|
|
fs.Lock()
|
|
|
defer fs.Unlock()
|
|
|
@@ -98,13 +98,13 @@ func TestSenderSendFailed(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func TestSenderPost(t *testing.T) {
|
|
|
+func TestPipelinePost(t *testing.T) {
|
|
|
tr := &roundTripperRecorder{}
|
|
|
- p := NewPeer(tr, "http://10.0.0.1", types.ID(1), types.ID(1), &nopProcessor{}, nil, nil)
|
|
|
- if err := p.post([]byte("some data")); err != nil {
|
|
|
+ p := newPipeline(tr, "http://10.0.0.1", types.ID(1), types.ID(1), nil, nil)
|
|
|
+ if err := p.pipeline([]byte("some data")); err != nil {
|
|
|
t.Fatalf("unexpect post error: %v", err)
|
|
|
}
|
|
|
- p.Stop()
|
|
|
+ p.stop()
|
|
|
|
|
|
if g := tr.Request().Method; g != "POST" {
|
|
|
t.Errorf("method = %s, want %s", g, "POST")
|
|
|
@@ -127,7 +127,7 @@ func TestSenderPost(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func TestSenderPostBad(t *testing.T) {
|
|
|
+func TestPipelinePostBad(t *testing.T) {
|
|
|
tests := []struct {
|
|
|
u string
|
|
|
code int
|
|
|
@@ -142,9 +142,9 @@ func TestSenderPostBad(t *testing.T) {
|
|
|
{"http://10.0.0.1", http.StatusCreated, nil},
|
|
|
}
|
|
|
for i, tt := range tests {
|
|
|
- p := NewPeer(newRespRoundTripper(tt.code, tt.err), tt.u, types.ID(1), types.ID(1), &nopProcessor{}, nil, make(chan error))
|
|
|
- err := p.post([]byte("some data"))
|
|
|
- p.Stop()
|
|
|
+ p := newPipeline(newRespRoundTripper(tt.code, tt.err), tt.u, types.ID(1), types.ID(1), nil, make(chan error))
|
|
|
+ err := p.pipeline([]byte("some data"))
|
|
|
+ p.stop()
|
|
|
|
|
|
if err == nil {
|
|
|
t.Errorf("#%d: err = nil, want not nil", i)
|
|
|
@@ -152,7 +152,7 @@ func TestSenderPostBad(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func TestPeerPostErrorc(t *testing.T) {
|
|
|
+func TestPipelinePostErrorc(t *testing.T) {
|
|
|
tests := []struct {
|
|
|
u string
|
|
|
code int
|
|
|
@@ -163,9 +163,9 @@ func TestPeerPostErrorc(t *testing.T) {
|
|
|
}
|
|
|
for i, tt := range tests {
|
|
|
errorc := make(chan error, 1)
|
|
|
- p := NewPeer(newRespRoundTripper(tt.code, tt.err), tt.u, types.ID(1), types.ID(1), &nopProcessor{}, nil, errorc)
|
|
|
- p.post([]byte("some data"))
|
|
|
- p.Stop()
|
|
|
+ p := newPipeline(newRespRoundTripper(tt.code, tt.err), tt.u, types.ID(1), types.ID(1), nil, errorc)
|
|
|
+ p.pipeline([]byte("some data"))
|
|
|
+ p.stop()
|
|
|
select {
|
|
|
case <-errorc:
|
|
|
default:
|