本文整理汇总了Golang中github.com/youtube/vitess/go/vt/topo.Impl.SaveVSchema方法的典型用法代码示例。如果您正苦于以下问题:Golang Impl.SaveVSchema方法的具体用法?Golang Impl.SaveVSchema怎么用?Golang Impl.SaveVSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/youtube/vitess/go/vt/topo.Impl
的用法示例。
在下文中一共展示了Impl.SaveVSchema方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CheckVSchema
// CheckVSchema runs the tests on the VSchema part of the API
func CheckVSchema(ctx context.Context, t *testing.T, ts topo.Impl) {
got, err := ts.GetVSchema(ctx)
if err != nil {
t.Error(err)
}
want := "{}"
if got != want {
t.Errorf("GetVSchema: %s, want %s", got, want)
}
err = ts.SaveVSchema(ctx, `{ "Keyspaces": {}}`)
if err != nil {
t.Error(err)
}
got, err = ts.GetVSchema(ctx)
if err != nil {
t.Error(err)
}
want = `{ "Keyspaces": {}}`
if got != want {
t.Errorf("GetVSchema: %s, want %s", got, want)
}
err = ts.SaveVSchema(ctx, `{ "Keyspaces": { "aa": { "Sharded": false}}}`)
if err != nil {
t.Error(err)
}
got, err = ts.GetVSchema(ctx)
if err != nil {
t.Error(err)
}
want = `{ "Keyspaces": { "aa": { "Sharded": false}}}`
if got != want {
t.Errorf("GetVSchema: %s, want %s", got, want)
}
err = ts.SaveVSchema(ctx, "invalid")
want = "Unmarshal failed:"
if err == nil || !strings.HasPrefix(err.Error(), want) {
t.Errorf("SaveVSchema: %v, must start with %s", err, want)
}
}
示例2: checkVSchema
// checkVSchema runs the tests on the VSchema part of the API
func checkVSchema(t *testing.T, ts topo.Impl) {
ctx := context.Background()
if err := ts.CreateKeyspace(ctx, "test_keyspace", &topodatapb.Keyspace{}); err != nil {
t.Fatalf("CreateKeyspace: %v", err)
}
shard := &topodatapb.Shard{
KeyRange: newKeyRange("b0-c0"),
}
if err := ts.CreateShard(ctx, "test_keyspace", "b0-c0", shard); err != nil {
t.Fatalf("CreateShard: %v", err)
}
got, err := ts.GetVSchema(ctx, "test_keyspace")
want := &vschemapb.Keyspace{}
if err != topo.ErrNoNode {
t.Error(err)
}
err = ts.SaveVSchema(ctx, "test_keyspace", &vschemapb.Keyspace{
Sharded: true,
Vindexes: map[string]*vschemapb.Vindex{
"stfu1": {
Type: "stfu",
Params: map[string]string{
"stfu1": "1",
},
Owner: "t1",
},
"stln1": {
Type: "stln",
Owner: "t1",
},
},
Tables: map[string]*vschemapb.Table{
"t1": {
ColumnVindexes: []*vschemapb.ColumnVindex{
{
Column: "c1",
Name: "stfu1",
}, {
Column: "c2",
Name: "stln1",
},
},
},
},
})
if err != nil {
t.Error(err)
}
got, err = ts.GetVSchema(ctx, "test_keyspace")
if err != nil {
t.Error(err)
}
want = &vschemapb.Keyspace{
Sharded: true,
Vindexes: map[string]*vschemapb.Vindex{
"stfu1": {
Type: "stfu",
Params: map[string]string{
"stfu1": "1",
},
Owner: "t1",
},
"stln1": {
Type: "stln",
Owner: "t1",
},
},
Tables: map[string]*vschemapb.Table{
"t1": {
ColumnVindexes: []*vschemapb.ColumnVindex{
{
Column: "c1",
Name: "stfu1",
}, {
Column: "c2",
Name: "stln1",
},
},
},
},
}
if !proto.Equal(got, want) {
t.Errorf("GetVSchema: %s, want %s", got, want)
}
err = ts.SaveVSchema(ctx, "test_keyspace", &vschemapb.Keyspace{})
if err != nil {
t.Error(err)
}
got, err = ts.GetVSchema(ctx, "test_keyspace")
if err != nil {
t.Error(err)
}
want = &vschemapb.Keyspace{}
//.........这里部分代码省略.........
示例3: CheckVSchema
// CheckVSchema runs the tests on the VSchema part of the API
func CheckVSchema(ctx context.Context, t *testing.T, ts topo.Impl) {
if err := ts.CreateKeyspace(ctx, "test_keyspace", &topodatapb.Keyspace{}); err != nil {
t.Fatalf("CreateKeyspace: %v", err)
}
shard := &topodatapb.Shard{
KeyRange: newKeyRange("b0-c0"),
}
if err := ts.CreateShard(ctx, "test_keyspace", "b0-c0", shard); err != nil {
t.Fatalf("CreateShard: %v", err)
}
got, err := ts.GetVSchema(ctx, "test_keyspace")
if err != nil {
t.Error(err)
}
want := "{}"
if got != want {
t.Errorf("GetVSchema: %s, want %s", got, want)
}
err = ts.SaveVSchema(ctx, "test_keyspace", `{ "Sharded": true }`)
if err != nil {
t.Error(err)
}
got, err = ts.GetVSchema(ctx, "test_keyspace")
if err != nil {
t.Error(err)
}
want = `{ "Sharded": true }`
if got != want {
t.Errorf("GetVSchema: %s, want %s", got, want)
}
err = ts.SaveVSchema(ctx, "test_keyspace", `{ "Sharded": false }`)
if err != nil {
t.Error(err)
}
got, err = ts.GetVSchema(ctx, "test_keyspace")
if err != nil {
t.Error(err)
}
want = `{ "Sharded": false }`
if got != want {
t.Errorf("GetVSchema: %s, want %s", got, want)
}
err = ts.SaveVSchema(ctx, "test_keyspace", "invalid")
want = "Unmarshal failed:"
if err == nil || !strings.HasPrefix(err.Error(), want) {
t.Errorf("SaveVSchema: %v, must start with %s", err, want)
}
// Make sure the vschema is not returned as a shard name,
// because they share the same directory location.
shards, err := ts.GetShardNames(ctx, "test_keyspace")
if err != nil {
t.Errorf("GetShardNames: %v", err)
}
if len(shards) != 1 || shards[0] != "b0-c0" {
t.Errorf(`GetShardNames: want [ "b0-c0" ], got %v`, shards)
}
}