本文整理匯總了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)
}
}
}