本文整理汇总了Golang中github.com/youtube/vitess/go/vt/vtctl/vtctlclient.VtctlClient类的典型用法代码示例。如果您正苦于以下问题:Golang VtctlClient类的具体用法?Golang VtctlClient怎么用?Golang VtctlClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VtctlClient类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestSuite
// TestSuite runs the test suite on the given topo server and client
func TestSuite(t *testing.T, ts topo.Server, client vtctlclient.VtctlClient) {
ctx := context.Background()
// Create a fake tablet
tablet := &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{Cell: "cell1", Uid: 1},
Hostname: "localhost",
Ip: "10.11.12.13",
PortMap: map[string]int32{
"vt": 3333,
"mysql": 3334,
},
Tags: map[string]string{"tag": "value"},
Keyspace: "test_keyspace",
Type: topodatapb.TabletType_MASTER,
}
if err := ts.CreateTablet(ctx, tablet); err != nil {
t.Errorf("CreateTablet: %v", err)
}
// run a command that's gonna return something on the log channel
stream, err := client.ExecuteVtctlCommand(ctx, []string{"ListAllTablets", "cell1"}, 30*time.Second)
if err != nil {
t.Fatalf("Remote error: %v", err)
}
got, err := stream.Recv()
if err != nil {
t.Fatalf("failed to get first line: %v", err)
}
expected := "cell1-0000000001 test_keyspace <null> master localhost:3333 localhost:3334 [tag: \"value\"]\n"
if logutil.EventString(got) != expected {
t.Errorf("Got unexpected log line '%v' expected '%v'", got.String(), expected)
}
got, err = stream.Recv()
if err != io.EOF {
t.Errorf("Didn't get end of log stream: %v %v", got, err)
}
// run a command that's gonna fail
stream, err = client.ExecuteVtctlCommand(ctx, []string{"ListAllTablets", "cell2"}, 30*time.Second)
if err != nil {
t.Fatalf("Remote error: %v", err)
}
got, err = stream.Recv()
expected = "node doesn't exist"
if err == nil || !strings.Contains(err.Error(), expected) {
t.Fatalf("Unexpected remote error, got: '%v' was expecting to find '%v'", err, expected)
}
// run a command that's gonna panic
stream, err = client.ExecuteVtctlCommand(ctx, []string{"Panic"}, 30*time.Second)
if err != nil {
t.Fatalf("Remote error: %v", err)
}
got, err = stream.Recv()
expected1 := "this command panics on purpose"
expected2 := "uncaught vtctl panic"
if err == nil || !strings.Contains(err.Error(), expected1) || !strings.Contains(err.Error(), expected2) {
t.Fatalf("Unexpected remote error, got: '%v' was expecting to find '%v' and '%v'", err, expected1, expected2)
}
// and clean up the tablet
if err := ts.DeleteTablet(ctx, tablet.Alias); err != nil {
t.Errorf("DeleteTablet: %v", err)
}
}
开发者ID:aaijazi,项目名称:vitess,代码行数:72,代码来源:client.go
示例2: TestSuite
// TestSuite runs the test suite on the given topo server and client
func TestSuite(t *testing.T, ts topo.Server, client vtctlclient.VtctlClient) {
ctx := context.Background()
// Create a fake tablet
tablet := &topo.Tablet{
Alias: topo.TabletAlias{Cell: "cell1", Uid: 1},
Hostname: "localhost",
IPAddr: "10.11.12.13",
Portmap: map[string]int{
"vt": 3333,
"mysql": 3334,
},
Tags: map[string]string{"tag": "value"},
Keyspace: "test_keyspace",
Type: topo.TYPE_MASTER,
}
if err := ts.CreateTablet(ctx, tablet); err != nil {
t.Errorf("CreateTablet: %v", err)
}
// run a command that's gonna return something on the log channel
logs, errFunc, err := client.ExecuteVtctlCommand(ctx, []string{"ListAllTablets", "cell1"}, 30*time.Second, 10*time.Second)
if err != nil {
t.Fatalf("Remote error: %v", err)
}
count := 0
for e := range logs {
expected := "cell1-0000000001 test_keyspace <null> master localhost:3333 localhost:3334 [tag: \"value\"]\n"
if e.String() != expected {
t.Errorf("Got unexpected log line '%v' expected '%v'", e.String(), expected)
}
count++
}
if count != 1 {
t.Errorf("Didn't get expected log line only, got %v lines", count)
}
if err := errFunc(); err != nil {
t.Fatalf("Remote error: %v", err)
}
// run a command that's gonna fail
logs, errFunc, err = client.ExecuteVtctlCommand(ctx, []string{"ListAllTablets", "cell2"}, 30*time.Second, 10*time.Second)
if err != nil {
t.Fatalf("Remote error: %v", err)
}
if e, ok := <-logs; ok {
t.Errorf("Got unexpected line for logs: %v", e.String())
}
expected := "node doesn't exist"
if err := errFunc(); err == nil || !strings.Contains(err.Error(), expected) {
t.Fatalf("Unexpected remote error, got: '%v' was expecting to find '%v'", err, expected)
}
// run a command that's gonna panic
logs, errFunc, err = client.ExecuteVtctlCommand(ctx, []string{"Panic"}, 30*time.Second, 10*time.Second)
if err != nil {
t.Fatalf("Remote error: %v", err)
}
if e, ok := <-logs; ok {
t.Errorf("Got unexpected line for logs: %v", e.String())
}
expected1 := "this command panics on purpose"
expected2 := "uncaught vtctl panic"
if err := errFunc(); err == nil || !strings.Contains(err.Error(), expected1) || !strings.Contains(err.Error(), expected2) {
t.Fatalf("Unexpected remote error, got: '%v' was expecting to find '%v' and '%v'", err, expected1, expected2)
}
}
开发者ID:haoqoo,项目名称:vitess,代码行数:71,代码来源:client.go
注:本文中的github.com/youtube/vitess/go/vt/vtctl/vtctlclient.VtctlClient类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论