本文整理汇总了Golang中github.com/coreos/etcd-starter/Godeps/_workspace/src/github.com/coreos/etcd/pkg/types.ID函数的典型用法代码示例。如果您正苦于以下问题:Golang ID函数的具体用法?Golang ID怎么用?Golang ID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ID函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestTransportAdd
func TestTransportAdd(t *testing.T) {
ls := stats.NewLeaderStats("")
tr := &transport{
roundTripper: &roundTripperRecorder{},
leaderStats: ls,
peers: make(map[types.ID]Peer),
}
tr.AddPeer(1, []string{"http://localhost:7001"})
defer tr.Stop()
if _, ok := ls.Followers["1"]; !ok {
t.Errorf("FollowerStats[1] is nil, want exists")
}
s, ok := tr.peers[types.ID(1)]
if !ok {
t.Fatalf("senders[1] is nil, want exists")
}
// duplicate AddPeer is ignored
tr.AddPeer(1, []string{"http://localhost:7001"})
ns := tr.peers[types.ID(1)]
if s != ns {
t.Errorf("sender = %v, want %v", ns, s)
}
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:25,代码来源:transport_test.go
示例2: TestStreamReaderDialResult
// TestStreamReaderDialResult tests the result of the dial func call meets the
// HTTP response received.
func TestStreamReaderDialResult(t *testing.T) {
tests := []struct {
code int
err error
wok bool
}{
{0, errors.New("blah"), false},
{http.StatusOK, nil, true},
{http.StatusMethodNotAllowed, nil, false},
{http.StatusNotFound, nil, false},
{http.StatusPreconditionFailed, nil, false},
}
for i, tt := range tests {
tr := newRespRoundTripper(tt.code, tt.err)
sr := &streamReader{
tr: tr,
picker: mustNewURLPicker(t, []string{"http://localhost:7001"}),
t: streamTypeMessage,
from: types.ID(1),
to: types.ID(2),
cid: types.ID(1),
}
_, err := sr.dial()
if ok := err == nil; ok != tt.wok {
t.Errorf("#%d: ok = %v, want %v", i, ok, tt.wok)
}
}
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:31,代码来源:stream_test.go
示例3: TestPipelinePost
func TestPipelinePost(t *testing.T) {
tr := &roundTripperRecorder{}
picker := mustNewURLPicker(t, []string{"http://localhost:7001"})
p := newPipeline(tr, picker, types.ID(1), types.ID(1), nil, &fakeRaft{}, nil)
if err := p.post([]byte("some data")); err != nil {
t.Fatalf("unexpect post error: %v", err)
}
p.stop()
if g := tr.Request().Method; g != "POST" {
t.Errorf("method = %s, want %s", g, "POST")
}
if g := tr.Request().URL.String(); g != "http://localhost:7001/raft" {
t.Errorf("url = %s, want %s", g, "http://localhost:7001/raft")
}
if g := tr.Request().Header.Get("Content-Type"); g != "application/protobuf" {
t.Errorf("content type = %s, want %s", g, "application/protobuf")
}
if g := tr.Request().Header.Get("X-Etcd-Cluster-ID"); g != "1" {
t.Errorf("cluster id = %s, want %s", g, "1")
}
b, err := ioutil.ReadAll(tr.Request().Body)
if err != nil {
t.Fatalf("unexpected ReadAll error: %v", err)
}
if string(b) != "some data" {
t.Errorf("body = %s, want %s", b, "some data")
}
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:29,代码来源:pipeline_test.go
示例4: Process
func (s *EtcdServer) Process(ctx context.Context, m raftpb.Message) error {
if s.Cluster.IsIDRemoved(types.ID(m.From)) {
log.Printf("etcdserver: reject message from removed member %s", types.ID(m.From).String())
return httptypes.NewHTTPError(http.StatusForbidden, "cannot process message from removed member")
}
if m.Type == raftpb.MsgApp {
s.stats.RecvAppendReq(types.ID(m.From).String(), m.Size())
}
return s.r.Step(ctx, m)
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:10,代码来源:server.go
示例5: TestTransportUpdate
func TestTransportUpdate(t *testing.T) {
peer := newFakePeer()
tr := &transport{
peers: map[types.ID]Peer{types.ID(1): peer},
}
u := "http://localhost:7001"
tr.UpdatePeer(types.ID(1), []string{u})
wurls := types.URLs(testutil.MustNewURLs(t, []string{"http://localhost:7001"}))
if !reflect.DeepEqual(peer.urls, wurls) {
t.Errorf("urls = %+v, want %+v", peer.urls, wurls)
}
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:12,代码来源:transport_test.go
示例6: TestServeRaftStreamPrefix
func TestServeRaftStreamPrefix(t *testing.T) {
tests := []struct {
path string
wtype streamType
}{
{
RaftStreamPrefix + "/message/1",
streamTypeMessage,
},
{
RaftStreamPrefix + "/msgapp/1",
streamTypeMsgApp,
},
// backward compatibility
{
RaftStreamPrefix + "/1",
streamTypeMsgApp,
},
}
for i, tt := range tests {
req, err := http.NewRequest("GET", "http://localhost:7001"+tt.path, nil)
if err != nil {
t.Fatalf("#%d: could not create request: %#v", i, err)
}
req.Header.Set("X-Etcd-Cluster-ID", "1")
req.Header.Set("X-Raft-To", "2")
wterm := "1"
req.Header.Set("X-Raft-Term", wterm)
peer := newFakePeer()
peerGetter := &fakePeerGetter{peers: map[types.ID]Peer{types.ID(1): peer}}
h := newStreamHandler(peerGetter, types.ID(2), types.ID(1))
rw := httptest.NewRecorder()
go h.ServeHTTP(rw, req)
var conn *outgoingConn
select {
case conn = <-peer.connc:
case <-time.After(time.Second):
t.Fatalf("#%d: failed to attach outgoingConn", i)
}
if conn.t != tt.wtype {
t.Errorf("$%d: type = %s, want %s", i, conn.t, tt.wtype)
}
if conn.termStr != wterm {
t.Errorf("$%d: term = %s, want %s", i, conn.termStr, wterm)
}
conn.Close()
}
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:51,代码来源:http_test.go
示例7: TestPipelineSendFailed
// TestPipelineSendFailed tests that when send func meets the post error,
// it increases fail count in stats.
func TestPipelineSendFailed(t *testing.T) {
picker := mustNewURLPicker(t, []string{"http://localhost:7001"})
fs := &stats.FollowerStats{}
p := newPipeline(newRespRoundTripper(0, errors.New("blah")), picker, types.ID(1), types.ID(1), fs, &fakeRaft{}, nil)
p.msgc <- raftpb.Message{Type: raftpb.MsgApp}
p.stop()
fs.Lock()
defer fs.Unlock()
if fs.Counts.Fail != 1 {
t.Errorf("fail = %d, want 1", fs.Counts.Fail)
}
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:16,代码来源:pipeline_test.go
示例8: TestTransportRemove
func TestTransportRemove(t *testing.T) {
tr := &transport{
roundTripper: &roundTripperRecorder{},
leaderStats: stats.NewLeaderStats(""),
peers: make(map[types.ID]Peer),
}
tr.AddPeer(1, []string{"http://localhost:7001"})
tr.RemovePeer(types.ID(1))
defer tr.Stop()
if _, ok := tr.peers[types.ID(1)]; ok {
t.Fatalf("senders[1] exists, want removed")
}
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:14,代码来源:transport_test.go
示例9: GuessNodeID
func GuessNodeID(nodes map[string]uint64, snap4 *Snapshot4, cfg *Config4, name string) uint64 {
var snapNodes map[string]uint64
if snap4 != nil {
snapNodes = snap4.GetNodesFromStore()
}
// First, use the flag, if set.
if name != "" {
log.Printf("Using suggested name %s", name)
if val, ok := nodes[name]; ok {
log.Printf("Assigning %s the ID %s", name, types.ID(val))
return val
}
if snapNodes != nil {
if val, ok := snapNodes[name]; ok {
log.Printf("Assigning %s the ID %s", name, types.ID(val))
return val
}
}
log.Printf("Name not found, autodetecting...")
}
// Next, look at the snapshot peers, if that exists.
if snap4 != nil {
//snapNodes := make(map[string]uint64)
//for _, p := range snap4.Peers {
//m := generateNodeMember(p.Name, p.ConnectionString, "")
//snapNodes[p.Name] = uint64(m.ID)
//}
for _, p := range cfg.Peers {
delete(snapNodes, p.Name)
}
if len(snapNodes) == 1 {
for nodename, id := range nodes {
log.Printf("Autodetected from snapshot: name %s", nodename)
return id
}
}
}
// Then, try and deduce from the log.
for _, p := range cfg.Peers {
delete(nodes, p.Name)
}
if len(nodes) == 1 {
for nodename, id := range nodes {
log.Printf("Autodetected name %s", nodename)
return id
}
}
return 0
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:49,代码来源:etcd4.go
示例10: readWAL
func readWAL(waldir string, snap walpb.Snapshot) (w *wal.WAL, id, cid types.ID, st raftpb.HardState, ents []raftpb.Entry) {
var err error
if w, err = wal.Open(waldir, snap); err != nil {
log.Fatalf("etcdserver: open wal error: %v", err)
}
var wmetadata []byte
if wmetadata, st, ents, err = w.ReadAll(); err != nil {
log.Fatalf("etcdserver: read wal error: %v", err)
}
var metadata pb.Metadata
pbutil.MustUnmarshal(&metadata, wmetadata)
id = types.ID(metadata.NodeID)
cid = types.ID(metadata.ClusterID)
return
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:15,代码来源:storage.go
示例11: newTestMember
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},
}
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:7,代码来源:member_test.go
示例12: reportSentDuration
func reportSentDuration(channel string, m raftpb.Message, duration time.Duration) {
typ := m.Type.String()
if isLinkHeartbeatMessage(m) {
typ = "MsgLinkHeartbeat"
}
msgSentDuration.WithLabelValues(channel, types.ID(m.To).String(), typ).Observe(float64(duration.Nanoseconds() / int64(time.Microsecond)))
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:7,代码来源:metrics.go
示例13: reportSentFailure
func reportSentFailure(channel string, m raftpb.Message) {
typ := m.Type.String()
if isLinkHeartbeatMessage(m) {
typ = "MsgLinkHeartbeat"
}
msgSentFailed.WithLabelValues(channel, types.ID(m.To).String(), typ).Inc()
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:7,代码来源:metrics.go
示例14: send
func (s *EtcdServer) send(ms []raftpb.Message) {
for _, m := range ms {
if !s.Cluster.IsIDRemoved(types.ID(m.To)) {
m.To = 0
}
}
s.r.transport.Send(ms)
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:8,代码来源:server.go
示例15: TestPipelineSend
// TestPipelineSend tests that pipeline could send data using roundtripper
// and increase success count in stats.
func TestPipelineSend(t *testing.T) {
tr := &roundTripperRecorder{}
picker := mustNewURLPicker(t, []string{"http://localhost:7001"})
fs := &stats.FollowerStats{}
p := newPipeline(tr, picker, types.ID(1), types.ID(1), fs, &fakeRaft{}, nil)
p.msgc <- raftpb.Message{Type: raftpb.MsgApp}
p.stop()
if tr.Request() == nil {
t.Errorf("sender fails to post the data")
}
fs.Lock()
defer fs.Unlock()
if fs.Counts.Success != 1 {
t.Errorf("success = %d, want 1", fs.Counts.Success)
}
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:20,代码来源:pipeline_test.go
示例16: genID
func (c *Cluster) genID() {
mIDs := c.MemberIDs()
b := make([]byte, 8*len(mIDs))
for i, id := range mIDs {
binary.BigEndian.PutUint64(b[8*i:], uint64(id))
}
hash := sha1.Sum(b)
c.id = types.ID(binary.BigEndian.Uint64(hash[:8]))
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:9,代码来源:cluster.go
示例17: ValidateConfigurationChange
// ValidateConfigurationChange takes a proposed ConfChange and
// ensures that it is still valid.
func (c *Cluster) ValidateConfigurationChange(cc raftpb.ConfChange) error {
members, removed := membersFromStore(c.store)
id := types.ID(cc.NodeID)
if removed[id] {
return ErrIDRemoved
}
switch cc.Type {
case raftpb.ConfChangeAddNode:
if members[id] != nil {
return ErrIDExists
}
urls := make(map[string]bool)
for _, m := range members {
for _, u := range m.PeerURLs {
urls[u] = true
}
}
m := new(Member)
if err := json.Unmarshal(cc.Context, m); err != nil {
log.Panicf("unmarshal member should never fail: %v", err)
}
for _, u := range m.PeerURLs {
if urls[u] {
return ErrPeerURLexists
}
}
case raftpb.ConfChangeRemoveNode:
if members[id] == nil {
return ErrIDNotFound
}
case raftpb.ConfChangeUpdateNode:
if members[id] == nil {
return ErrIDNotFound
}
urls := make(map[string]bool)
for _, m := range members {
if m.ID == id {
continue
}
for _, u := range m.PeerURLs {
urls[u] = true
}
}
m := new(Member)
if err := json.Unmarshal(cc.Context, m); err != nil {
log.Panicf("unmarshal member should never fail: %v", err)
}
for _, u := range m.PeerURLs {
if urls[u] {
return ErrPeerURLexists
}
}
default:
log.Panicf("ConfChange type should be either AddNode, RemoveNode or UpdateNode")
}
return nil
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:59,代码来源:cluster.go
示例18: TestMsgApp
func TestMsgApp(t *testing.T) {
tests := []raftpb.Message{
{
Type: raftpb.MsgApp,
From: 1,
To: 2,
Term: 1,
LogTerm: 1,
Index: 3,
Entries: []raftpb.Entry{{Term: 1, Index: 4}},
},
{
Type: raftpb.MsgApp,
From: 1,
To: 2,
Term: 1,
LogTerm: 1,
Index: 0,
Entries: []raftpb.Entry{
{Term: 1, Index: 1, Data: []byte("some data")},
{Term: 1, Index: 2, Data: []byte("some data")},
{Term: 1, Index: 3, Data: []byte("some data")},
},
},
linkHeartbeatMessage,
}
for i, tt := range tests {
b := &bytes.Buffer{}
enc := &msgAppEncoder{w: b, fs: &stats.FollowerStats{}}
if err := enc.encode(tt); err != nil {
t.Errorf("#%d: unexpected encode message error: %v", i, err)
continue
}
dec := &msgAppDecoder{r: b, local: types.ID(tt.To), remote: types.ID(tt.From), term: tt.Term}
m, err := dec.decode()
if err != nil {
t.Errorf("#%d: unexpected decode message error: %v", i, err)
continue
}
if !reflect.DeepEqual(m, tt) {
t.Errorf("#%d: message = %+v, want %+v", i, m, tt)
}
}
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:44,代码来源:msgapp_test.go
示例19: TestStreamReaderDialRequest
func TestStreamReaderDialRequest(t *testing.T) {
for i, tt := range []streamType{streamTypeMsgApp, streamTypeMessage} {
tr := &roundTripperRecorder{}
sr := &streamReader{
tr: tr,
picker: mustNewURLPicker(t, []string{"http://localhost:7001"}),
t: tt,
from: types.ID(1),
to: types.ID(2),
cid: types.ID(1),
msgAppTerm: 1,
}
sr.dial()
req := tr.Request()
var wurl string
switch tt {
case streamTypeMsgApp:
wurl = "http://localhost:7001/raft/stream/1"
case streamTypeMessage:
wurl = "http://localhost:7001/raft/stream/message/1"
}
if req.URL.String() != wurl {
t.Errorf("#%d: url = %s, want %s", i, req.URL.String(), wurl)
}
if w := "GET"; req.Method != w {
t.Errorf("#%d: method = %s, want %s", i, req.Method, w)
}
if g := req.Header.Get("X-Etcd-Cluster-ID"); g != "1" {
t.Errorf("#%d: header X-Etcd-Cluster-ID = %s, want 1", i, g)
}
if g := req.Header.Get("X-Raft-To"); g != "2" {
t.Errorf("#%d: header X-Raft-To = %s, want 2", i, g)
}
if g := req.Header.Get("X-Raft-Term"); tt == streamTypeMsgApp && g != "1" {
t.Errorf("#%d: header X-Raft-Term = %s, want 1", i, g)
}
}
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:39,代码来源:stream_test.go
示例20: TestPipelinePostErrorc
func TestPipelinePostErrorc(t *testing.T) {
tests := []struct {
u string
code int
err error
}{
{"http://localhost:7001", http.StatusForbidden, nil},
{"http://localhost:7001", http.StatusPreconditionFailed, nil},
}
for i, tt := range tests {
picker := mustNewURLPicker(t, []string{tt.u})
errorc := make(chan error, 1)
p := newPipeline(newRespRoundTripper(tt.code, tt.err), picker, types.ID(1), types.ID(1), nil, &fakeRaft{}, errorc)
p.post([]byte("some data"))
p.stop()
select {
case <-errorc:
default:
t.Fatalf("#%d: cannot receive from errorc", i)
}
}
}
开发者ID:rfrangio,项目名称:etcd-starter,代码行数:22,代码来源:pipeline_test.go
注:本文中的github.com/coreos/etcd-starter/Godeps/_workspace/src/github.com/coreos/etcd/pkg/types.ID函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论