当前位置: 首页>>代码示例>>Golang>>正文


Golang Impl.WatchSrvVSchema方法代码示例

本文整理汇总了Golang中github.com/youtube/vitess/go/vt/topo.Impl.WatchSrvVSchema方法的典型用法代码示例。如果您正苦于以下问题:Golang Impl.WatchSrvVSchema方法的具体用法?Golang Impl.WatchSrvVSchema怎么用?Golang Impl.WatchSrvVSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/youtube/vitess/go/vt/topo.Impl的用法示例。


在下文中一共展示了Impl.WatchSrvVSchema方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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)
		}
	}
}
开发者ID:CowLeo,项目名称:vitess,代码行数:96,代码来源:serving.go


注:本文中的github.com/youtube/vitess/go/vt/topo.Impl.WatchSrvVSchema方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。