本文整理汇总了Golang中github.com/youtube/vitess/go/vt/topo.Impl.Update方法的典型用法代码示例。如果您正苦于以下问题:Golang Impl.Update方法的具体用法?Golang Impl.Update怎么用?Golang Impl.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/youtube/vitess/go/vt/topo.Impl
的用法示例。
在下文中一共展示了Impl.Update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: checkFileInCell
func checkFileInCell(t *testing.T, ts topo.Impl, cell string) {
t.Logf("=== checkFileInCell %v", cell)
ctx := context.Background()
// ListDir root: nothing.
checkListDir(ctx, t, ts, cell, "/", nil)
// Get with no file -> ErrNoNode.
contents, version, err := ts.Get(ctx, cell, "/myfile")
if err != topo.ErrNoNode {
t.Errorf("Get(non-existent) didn't return ErrNoNode but: %v", err)
}
// Create a file.
version, err = ts.Create(ctx, cell, "/myfile", []byte{'a'})
if err != nil {
t.Fatalf("Create('/myfile') failed: %v", err)
}
// See it in the listing now.
checkListDir(ctx, t, ts, cell, "/", []string{"myfile"})
// Get should work, get the right contents and version.
contents, getVersion, err := ts.Get(ctx, cell, "/myfile")
if err != nil {
t.Errorf("Get('/myfile') returned an error: %v", err)
} else {
if len(contents) != 1 || contents[0] != 'a' {
t.Errorf("Get('/myfile') returned bad content: %v", contents)
}
if !reflect.DeepEqual(getVersion, version) {
t.Errorf("Get('/myfile') returned bad version: got %v expected %v", getVersion, version)
}
}
// Update it, make sure version changes.
newVersion, err := ts.Update(ctx, cell, "/myfile", []byte{'b'}, version)
if err != nil {
t.Fatalf("Update('/myfile') failed: %v", err)
}
if reflect.DeepEqual(version, newVersion) {
t.Errorf("Version didn't change, stayed %v", newVersion)
}
// Get should work, get the right contents and version.
contents, getVersion, err = ts.Get(ctx, cell, "/myfile")
if err != nil {
t.Errorf("Get('/myfile') returned an error: %v", err)
} else {
if len(contents) != 1 || contents[0] != 'b' {
t.Errorf("Get('/myfile') returned bad content: %v", contents)
}
if !reflect.DeepEqual(getVersion, newVersion) {
t.Errorf("Get('/myfile') returned bad version: got %v expected %v", getVersion, newVersion)
}
}
// Try to update again with wrong version, should fail.
if _, err = ts.Update(ctx, cell, "/myfile", []byte{'b'}, version); err != topo.ErrBadVersion {
t.Errorf("Update(bad version) didn't return ErrBadVersion but: %v", err)
}
// Try to update again with nil version, should work.
newVersion, err = ts.Update(ctx, cell, "/myfile", []byte{'c'}, nil)
if err != nil {
t.Errorf("Update(nil version) should have worked but got: %v", err)
}
// Get should work, get the right contents and version.
contents, getVersion, err = ts.Get(ctx, cell, "/myfile")
if err != nil {
t.Errorf("Get('/myfile') returned an error: %v", err)
} else {
if len(contents) != 1 || contents[0] != 'c' {
t.Errorf("Get('/myfile') returned bad content: %v", contents)
}
if !reflect.DeepEqual(getVersion, newVersion) {
t.Errorf("Get('/myfile') returned bad version: got %v expected %v", getVersion, newVersion)
}
}
// Try to delete with wrong version, should fail.
if err = ts.Delete(ctx, cell, "/myfile", version); err != topo.ErrBadVersion {
t.Errorf("Delete('/myfile', wrong version) returned bad error: %v", err)
}
// Now delete it.
if err = ts.Delete(ctx, cell, "/myfile", newVersion); err != nil {
t.Fatalf("Delete('/myfile') failed: %v", err)
}
// Try to delete again, should fail.
if err = ts.Delete(ctx, cell, "/myfile", newVersion); err != topo.ErrNoNode {
t.Errorf("Delete(already gone) returned bad error: %v", err)
}
// Create again, with unconditional update.
version, err = ts.Update(ctx, cell, "/myfile", []byte{'d'}, nil)
if err != nil {
t.Fatalf("Update('/myfile', nil) failed: %v", err)
//.........这里部分代码省略.........