mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #7703 from gyuho/rafthttp
rafthttp: move test-only functions to '_test.go'
This commit is contained in:
commit
7da79de74b
@ -16,7 +16,6 @@ package rafthttp
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
@ -27,7 +26,6 @@ import (
|
||||
|
||||
"github.com/coreos/etcd/pkg/transport"
|
||||
"github.com/coreos/etcd/pkg/types"
|
||||
"github.com/coreos/etcd/raft/raftpb"
|
||||
"github.com/coreos/etcd/version"
|
||||
"github.com/coreos/go-semver/semver"
|
||||
)
|
||||
@ -61,31 +59,6 @@ func newStreamRoundTripper(tlsInfo transport.TLSInfo, dialTimeout time.Duration)
|
||||
return transport.NewTimeoutTransport(tlsInfo, dialTimeout, ConnReadTimeout, ConnWriteTimeout)
|
||||
}
|
||||
|
||||
func writeEntryTo(w io.Writer, ent *raftpb.Entry) error {
|
||||
size := ent.Size()
|
||||
if err := binary.Write(w, binary.BigEndian, uint64(size)); err != nil {
|
||||
return err
|
||||
}
|
||||
b, err := ent.Marshal()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = w.Write(b)
|
||||
return err
|
||||
}
|
||||
|
||||
func readEntryFrom(r io.Reader, ent *raftpb.Entry) error {
|
||||
var l uint64
|
||||
if err := binary.Read(r, binary.BigEndian, &l); err != nil {
|
||||
return err
|
||||
}
|
||||
buf := make([]byte, int(l))
|
||||
if _, err := io.ReadFull(r, buf); err != nil {
|
||||
return err
|
||||
}
|
||||
return ent.Unmarshal(buf)
|
||||
}
|
||||
|
||||
// createPostRequest creates a HTTP POST request that sends raft message.
|
||||
func createPostRequest(u url.URL, path string, body io.Reader, ct string, urls types.URLs, from, cid types.ID) *http.Request {
|
||||
uu := u
|
||||
|
@ -16,6 +16,8 @@ package rafthttp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"testing"
|
||||
@ -191,3 +193,28 @@ func TestCheckVersionCompatibility(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func writeEntryTo(w io.Writer, ent *raftpb.Entry) error {
|
||||
size := ent.Size()
|
||||
if err := binary.Write(w, binary.BigEndian, uint64(size)); err != nil {
|
||||
return err
|
||||
}
|
||||
b, err := ent.Marshal()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = w.Write(b)
|
||||
return err
|
||||
}
|
||||
|
||||
func readEntryFrom(r io.Reader, ent *raftpb.Entry) error {
|
||||
var l uint64
|
||||
if err := binary.Read(r, binary.BigEndian, &l); err != nil {
|
||||
return err
|
||||
}
|
||||
buf := make([]byte, int(l))
|
||||
if _, err := io.ReadFull(r, buf); err != nil {
|
||||
return err
|
||||
}
|
||||
return ent.Unmarshal(buf)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user