本文整理匯總了Golang中github.com/diffeo/go-coordinate/coordinate.Worker.SetParent方法的典型用法代碼示例。如果您正苦於以下問題:Golang Worker.SetParent方法的具體用法?Golang Worker.SetParent怎麽用?Golang Worker.SetParent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/diffeo/go-coordinate/coordinate.Worker
的用法示例。
在下文中一共展示了Worker.SetParent方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestWorkerAncestry
// TestWorkerAncestry does basic tests on worker parents and children.
func TestWorkerAncestry(t *testing.T) {
var (
err error
parent, child, worker coordinate.Worker
kids []coordinate.Worker
)
sts := SimpleTestSetup{NamespaceName: "TestWorkerAncestry"}
sts.SetUp(t)
defer sts.TearDown(t)
// start in the middle
parent, err = sts.Namespace.Worker("parent")
if !assert.NoError(t, err) {
return
}
worker, err = parent.Parent()
if assert.NoError(t, err) {
assert.Nil(t, worker)
}
kids, err = parent.Children()
if assert.NoError(t, err) {
assert.Empty(t, kids)
}
// Create a child
child, err = sts.Namespace.Worker("child")
if !assert.NoError(t, err) {
return
}
err = child.SetParent(parent)
assert.NoError(t, err)
// this should update the parent metadata
worker, err = parent.Parent()
if assert.NoError(t, err) {
assert.Nil(t, worker)
}
kids, err = parent.Children()
if assert.NoError(t, err) && assert.Len(t, kids, 1) {
assert.Equal(t, "child", kids[0].Name())
}
// and also the child metadata
worker, err = child.Parent()
if assert.NoError(t, err) && assert.NotNil(t, worker) {
assert.Equal(t, "parent", worker.Name())
}
kids, err = child.Children()
if assert.NoError(t, err) {
assert.Empty(t, kids)
}
}
示例2: TestWorkerAdoption
// TestWorkerAdoption hands a child worker to a new parent.
func TestWorkerAdoption(t *testing.T) {
var (
err error
child, oldParent, newParent, worker coordinate.Worker
kids []coordinate.Worker
)
sts := SimpleTestSetup{NamespaceName: "TestWorkerAdoption"}
sts.SetUp(t)
defer sts.TearDown(t)
// Create the worker objects
child, err = sts.Namespace.Worker("child")
if !assert.NoError(t, err) {
return
}
oldParent, err = sts.Namespace.Worker("old")
if !assert.NoError(t, err) {
return
}
newParent, err = sts.Namespace.Worker("new")
if !assert.NoError(t, err) {
return
}
// Set up the original ancestry
err = child.SetParent(oldParent)
assert.NoError(t, err)
// Move it to the new parent
err = child.SetParent(newParent)
assert.NoError(t, err)
// Checks
worker, err = child.Parent()
if assert.NoError(t, err) && assert.NotNil(t, worker) {
assert.Equal(t, "new", worker.Name())
}
kids, err = child.Children()
if assert.NoError(t, err) {
assert.Empty(t, kids)
}
worker, err = oldParent.Parent()
if assert.NoError(t, err) {
assert.Nil(t, worker)
}
kids, err = oldParent.Children()
if assert.NoError(t, err) {
assert.Empty(t, kids)
}
worker, err = newParent.Parent()
if assert.NoError(t, err) {
assert.Nil(t, worker)
}
kids, err = newParent.Children()
if assert.NoError(t, err) && assert.Len(t, kids, 1) {
assert.Equal(t, "child", kids[0].Name())
}
}