本文整理汇总了Golang中github.com/youtube/vitess/go/vt/topo.Impl.UpdateSrvVSchema方法的典型用法代码示例。如果您正苦于以下问题:Golang Impl.UpdateSrvVSchema方法的具体用法?Golang Impl.UpdateSrvVSchema怎么用?Golang Impl.UpdateSrvVSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/youtube/vitess/go/vt/topo.Impl
的用法示例。
在下文中一共展示了Impl.UpdateSrvVSchema方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: checkSrvVSchema
// checkSrvVSchema tests the SrvVSchema methods (other than watch).
func checkSrvVSchema(t *testing.T, ts topo.Impl) {
ctx := context.Background()
cell := getLocalCell(ctx, t, ts)
// check GetSrvVSchema returns topo.ErrNoNode if no SrvVSchema
if _, err := ts.GetSrvVSchema(ctx, cell); err != topo.ErrNoNode {
t.Errorf("GetSrvVSchema(not set): %v", err)
}
srvVSchema := &vschemapb.SrvVSchema{
Keyspaces: map[string]*vschemapb.Keyspace{
"test_keyspace": {
Sharded: true,
},
},
}
if err := ts.UpdateSrvVSchema(ctx, cell, srvVSchema); err != nil {
t.Errorf("UpdateSrvVSchema(1): %v", err)
}
if v, err := ts.GetSrvVSchema(ctx, cell); err != nil || !proto.Equal(srvVSchema, v) {
t.Errorf("GetSrvVSchema(valid): %v %v", err, v)
}
}
示例2: checkWatchSrvVSchema
func checkWatchSrvVSchema(t *testing.T, ts topo.Impl) {
ctx := context.Background()
cell := getLocalCell(ctx, t, ts)
emptySrvVSchema := &vschemapb.SrvVSchema{}
// start watching, should get nil first
ctx, cancel := context.WithCancel(ctx)
notifications, err := ts.WatchSrvVSchema(ctx, cell)
if err != nil {
t.Fatalf("WatchSrvVSchema failed: %v", err)
}
v, ok := <-notifications
if !ok || v != nil {
t.Fatalf("first value is wrong: %v %v", v, ok)
}
// update the SrvVSchema, should get a notification
srvVSchema := &vschemapb.SrvVSchema{
Keyspaces: map[string]*vschemapb.Keyspace{
"test_keyspace": {
Sharded: true,
},
},
}
if err := ts.UpdateSrvVSchema(ctx, cell, srvVSchema); err != nil {
t.Fatalf("UpdateSrvVSchema 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, srvVSchema) {
t.Fatalf("first value is wrong: got %v expected %v", sk, srvVSchema)
}
break
}
// update with an empty value, should get a notification
if err := ts.UpdateSrvVSchema(ctx, cell, emptySrvVSchema); err != nil {
t.Fatalf("UpdateSrvVSchema failed: %v", err)
}
for {
v, ok := <-notifications
if !ok {
t.Fatalf("watch channel is closed???")
}
if v == nil || proto.Equal(v, emptySrvVSchema) {
break
}
// duplicate notification of the first value, that's OK,
// but value better be good.
if !reflect.DeepEqual(v, srvVSchema) {
t.Fatalf("duplicate notification value is bad: %v", v)
}
}
// re-create the value, a bit different, should get a notification
srvVSchema.Keyspaces["test_keyspace"].Sharded = false
if err := ts.UpdateSrvVSchema(ctx, cell, srvVSchema); err != nil {
t.Fatalf("UpdateSrvVSchema failed: %v", err)
}
for {
v, ok := <-notifications
if !ok {
t.Fatalf("watch channel is closed???")
}
if v == nil || proto.Equal(v, emptySrvVSchema) {
// duplicate notification of the closed value, that's OK
continue
}
// non-empty value, that one should be ours
if !reflect.DeepEqual(v, srvVSchema) {
t.Fatalf("value after delete / re-create is wrong: %v %v", v, ok)
}
break
}
// close the context, should eventually get a closed
// notifications channel too
cancel()
for {
v, ok := <-notifications
if !ok {
break
}
if !reflect.DeepEqual(v, srvVSchema) {
t.Fatalf("duplicate notification value is bad: %v", v)
}
}
}