本文整理汇总了Golang中github.com/youtube/vitess/go/vt/topo.Impl.WatchSrvKeyspace方法的典型用法代码示例。如果您正苦于以下问题:Golang Impl.WatchSrvKeyspace方法的具体用法?Golang Impl.WatchSrvKeyspace怎么用?Golang Impl.WatchSrvKeyspace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/youtube/vitess/go/vt/topo.Impl
的用法示例。
在下文中一共展示了Impl.WatchSrvKeyspace方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CheckWatchSrvKeyspace
// CheckWatchSrvKeyspace makes sure WatchSrvKeyspace works as expected
func CheckWatchSrvKeyspace(ctx context.Context, t *testing.T, ts topo.Impl) {
cell := getLocalCell(ctx, t, ts)
keyspace := "test_keyspace"
// start watching, should get nil first
notifications, stopWatching, err := ts.WatchSrvKeyspace(ctx, cell, keyspace)
if err != nil {
t.Fatalf("WatchSrvKeyspace failed: %v", err)
}
sk, ok := <-notifications
if !ok || sk != nil {
t.Fatalf("first value is wrong: %v %v", sk, ok)
}
// update the SrvKeyspace, should get a notification
srvKeyspace := &topodatapb.SrvKeyspace{
ShardingColumnName: "test_column",
Partitions: []*topodatapb.SrvKeyspace_KeyspacePartition{
&topodatapb.SrvKeyspace_KeyspacePartition{
ServedType: topodatapb.TabletType_RDONLY,
ShardReferences: []*topodatapb.ShardReference{
&topodatapb.ShardReference{
Name: "0",
},
},
},
},
ServedFrom: []*topodatapb.SrvKeyspace_ServedFrom{
&topodatapb.SrvKeyspace_ServedFrom{
TabletType: topodatapb.TabletType_MASTER,
Keyspace: "other_keyspace",
},
},
}
if err := ts.UpdateSrvKeyspace(ctx, cell, keyspace, srvKeyspace); err != nil {
t.Fatalf("UpdateSrvKeyspace failed: %v", err)
}
for {
sk, ok := <-notifications
if !ok {
t.Fatalf("watch channel is closed???")
}
if sk == nil {
// duplicate notification of the first value, that's OK
continue
}
// non-empty value, that one should be ours
if !reflect.DeepEqual(sk, srvKeyspace) {
t.Fatalf("first value is wrong: got %v expected %v", sk, srvKeyspace)
}
break
}
// delete the SrvKeyspace, should get a notification
if err := ts.DeleteSrvKeyspace(ctx, cell, keyspace); err != nil {
t.Fatalf("DeleteSrvKeyspace failed: %v", err)
}
for {
sk, ok := <-notifications
if !ok {
t.Fatalf("watch channel is closed???")
}
if sk == nil {
break
}
// duplicate notification of the first value, that's OK,
// but value better be good.
if !reflect.DeepEqual(srvKeyspace, sk) {
t.Fatalf("duplicate notification value is bad: %v", sk)
}
}
// re-create the value, a bit different, should get a notification
srvKeyspace.SplitShardCount = 2
if err := ts.UpdateSrvKeyspace(ctx, cell, keyspace, srvKeyspace); err != nil {
t.Fatalf("UpdateSrvKeyspace failed: %v", err)
}
for {
sk, ok := <-notifications
if !ok {
t.Fatalf("watch channel is closed???")
}
if sk == nil {
// duplicate notification of the closed value, that's OK
continue
}
// non-empty value, that one should be ours
if !reflect.DeepEqual(srvKeyspace, sk) {
t.Fatalf("value after delete / re-create is wrong: %v %v", sk, ok)
}
break
}
// close the stopWatching channel, should eventually get a closed
// notifications channel too
close(stopWatching)
for {
sk, ok := <-notifications
//.........这里部分代码省略.........