本文整理汇总了Golang中github.com/coreos/etcd/clientv3.NewCluster函数的典型用法代码示例。如果您正苦于以下问题:Golang NewCluster函数的具体用法?Golang NewCluster怎么用?Golang NewCluster使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewCluster函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestMemberRemove
func TestMemberRemove(t *testing.T) {
defer testutil.AfterTest(t)
clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 3})
defer clus.Terminate(t)
capi := clientv3.NewCluster(clus.Client(1))
resp, err := capi.MemberList(context.Background())
if err != nil {
t.Fatalf("failed to list member %v", err)
}
_, err = capi.MemberRemove(context.Background(), resp.Members[0].ID)
if err != nil {
t.Fatalf("failed to remove member %v", err)
}
resp, err = capi.MemberList(context.Background())
if err != nil {
t.Fatalf("failed to list member %v", err)
}
if len(resp.Members) != 2 {
t.Errorf("number of members = %d, want %d", len(resp.Members), 2)
}
}
开发者ID:QuentinPerez,项目名称:etcd,代码行数:26,代码来源:cluster_test.go
示例2: TestMemberUpdate
func TestMemberUpdate(t *testing.T) {
defer testutil.AfterTest(t)
clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 3})
defer clus.Terminate(t)
capi := clientv3.NewCluster(clus.RandClient())
resp, err := capi.MemberList(context.Background())
if err != nil {
t.Fatalf("failed to list member %v", err)
}
urls := []string{"http://127.0.0.1:1234"}
_, err = capi.MemberUpdate(context.Background(), resp.Members[0].ID, urls)
if err != nil {
t.Fatalf("failed to update member %v", err)
}
resp, err = capi.MemberList(context.Background())
if err != nil {
t.Fatalf("failed to list member %v", err)
}
if !reflect.DeepEqual(resp.Members[0].PeerURLs, urls) {
t.Errorf("urls = %v, want %v", urls, resp.Members[0].PeerURLs)
}
}
开发者ID:XiangrongFan,项目名称:etcd,代码行数:27,代码来源:cluster_test.go
示例3: ExampleCluster_memberLeader
func ExampleCluster_memberLeader() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: endpoints,
DialTimeout: dialTimeout,
})
if err != nil {
log.Fatal(err)
}
defer cli.Close()
capi := clientv3.NewCluster(cli)
resp, err := capi.MemberLeader(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Println("leader:", resp.Name)
// leader: infra1
}
开发者ID:vsayer,项目名称:etcd,代码行数:19,代码来源:example_cluster_test.go
示例4: ExampleCluster_memberList
func ExampleCluster_memberList() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: endpoints,
DialTimeout: dialTimeout,
})
if err != nil {
log.Fatal(err)
}
defer cli.Close()
capi := clientv3.NewCluster(cli)
resp, err := capi.MemberList(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Println("members:", len(resp.Members))
// members: 3
}
开发者ID:vsayer,项目名称:etcd,代码行数:19,代码来源:example_cluster_test.go
示例5: ExampleCluster_memberAdd
func ExampleCluster_memberAdd() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: endpoints[:2],
DialTimeout: dialTimeout,
})
if err != nil {
log.Fatal(err)
}
defer cli.Close()
capi := clientv3.NewCluster(cli)
peerURLs := endpoints[2:]
mresp, err := capi.MemberAdd(context.Background(), peerURLs)
if err != nil {
log.Fatal(err)
}
fmt.Println("added member.PeerURLs:", mresp.Member.PeerURLs)
// added member.PeerURLs: [http://localhost:32380]
}
开发者ID:vsayer,项目名称:etcd,代码行数:20,代码来源:example_cluster_test.go
示例6: ExampleCluster_memberRemove
func ExampleCluster_memberRemove() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: endpoints[1:],
DialTimeout: dialTimeout,
})
if err != nil {
log.Fatal(err)
}
defer cli.Close()
capi := clientv3.NewCluster(cli)
resp, err := capi.MemberList(context.Background())
if err != nil {
log.Fatal(err)
}
_, err = capi.MemberRemove(context.Background(), resp.Members[0].ID)
if err != nil {
log.Fatal(err)
}
}
开发者ID:vsayer,项目名称:etcd,代码行数:22,代码来源:example_cluster_test.go
示例7: ExampleCluster_memberUpdate
func ExampleCluster_memberUpdate() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: endpoints,
DialTimeout: dialTimeout,
})
if err != nil {
log.Fatal(err)
}
defer cli.Close()
capi := clientv3.NewCluster(cli)
resp, err := capi.MemberList(context.Background())
if err != nil {
log.Fatal(err)
}
peerURLs := []string{"http://localhost:12378"}
_, err = capi.MemberUpdate(context.Background(), resp.Members[0].ID, peerURLs)
if err != nil {
log.Fatal(err)
}
}
开发者ID:vsayer,项目名称:etcd,代码行数:23,代码来源:example_cluster_test.go
示例8: TestMemberRemove
func TestMemberRemove(t *testing.T) {
defer testutil.AfterTest(t)
clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 3})
defer clus.Terminate(t)
capi := clientv3.NewCluster(clus.Client(1))
resp, err := capi.MemberList(context.Background())
if err != nil {
t.Fatalf("failed to list member %v", err)
}
rmvID := resp.Members[0].ID
// indexes in capi member list don't necessarily match cluster member list;
// find member that is not the client to remove
for _, m := range resp.Members {
mURLs, _ := types.NewURLs(m.PeerURLs)
if !reflect.DeepEqual(mURLs, clus.Members[1].ServerConfig.PeerURLs) {
rmvID = m.ID
break
}
}
_, err = capi.MemberRemove(context.Background(), rmvID)
if err != nil {
t.Fatalf("failed to remove member %v", err)
}
resp, err = capi.MemberList(context.Background())
if err != nil {
t.Fatalf("failed to list member %v", err)
}
if len(resp.Members) != 2 {
t.Errorf("number of members = %d, want %d", len(resp.Members), 2)
}
}
开发者ID:XiangrongFan,项目名称:etcd,代码行数:37,代码来源:cluster_test.go
示例9: GetLeader
// GetLeader returns the index of leader and error if any.
func (c *cluster) GetLeader() (int, error) {
if c.v2Only {
return 0, nil
}
cli, err := clientv3.New(clientv3.Config{
Endpoints: c.GRPCURLs,
DialTimeout: 5 * time.Second,
})
if err != nil {
return 0, err
}
defer cli.Close()
clus := clientv3.NewCluster(cli)
mem, err := clus.MemberLeader(context.Background())
if err != nil {
return 0, err
}
for i, name := range c.Names {
if name == mem.Name {
return i, nil
}
}
return 0, fmt.Errorf("no leader found")
}
开发者ID:lrita,项目名称:etcd,代码行数:25,代码来源:cluster.go
注:本文中的github.com/coreos/etcd/clientv3.NewCluster函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论