本文整理汇总了Golang中github.com/dmaze/goordinate/coordinate.Worker.Parent方法的典型用法代码示例。如果您正苦于以下问题:Golang Worker.Parent方法的具体用法?Golang Worker.Parent怎么用?Golang Worker.Parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/dmaze/goordinate/coordinate.Worker
的用法示例。
在下文中一共展示了Worker.Parent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestWorkerAdoption
// TestWorkerAdoption hands a child worker to a new parent.
func (s *Suite) TestWorkerAdoption(c *check.C) {
var (
err error
child, oldParent, newParent, worker coordinate.Worker
kids []coordinate.Worker
)
// Create the worker objects
child, err = s.Namespace.Worker("child")
c.Assert(err, check.IsNil)
oldParent, err = s.Namespace.Worker("old")
c.Assert(err, check.IsNil)
newParent, err = s.Namespace.Worker("new")
c.Assert(err, check.IsNil)
// Set up the original ancestry
err = child.SetParent(oldParent)
c.Assert(err, check.IsNil)
// Move it to the new parent
err = child.SetParent(newParent)
c.Assert(err, check.IsNil)
// Checks
worker, err = child.Parent()
c.Assert(err, check.IsNil)
c.Check(worker, check.NotNil)
if worker != nil {
c.Check(worker.Name(), check.Equals, "new")
}
kids, err = child.Children()
c.Assert(err, check.IsNil)
c.Check(kids, check.HasLen, 0)
worker, err = oldParent.Parent()
c.Assert(err, check.IsNil)
c.Check(worker, check.IsNil)
kids, err = oldParent.Children()
c.Assert(err, check.IsNil)
c.Check(kids, check.HasLen, 0)
worker, err = newParent.Parent()
c.Assert(err, check.IsNil)
c.Check(worker, check.IsNil)
kids, err = newParent.Children()
c.Assert(err, check.IsNil)
c.Check(kids, check.HasLen, 1)
if len(kids) > 0 {
c.Check(kids[0].Name(), check.Equals, "child")
}
}
示例2: TestWorkerAncestry
// TestWorkerAncestry does basic tests on worker parents and children.
func (s *Suite) TestWorkerAncestry(c *check.C) {
var (
err error
parent, child, worker coordinate.Worker
kids []coordinate.Worker
)
// start in the middle
parent, err = s.Namespace.Worker("parent")
c.Assert(err, check.IsNil)
worker, err = parent.Parent()
c.Assert(err, check.IsNil)
c.Check(worker, check.IsNil)
kids, err = parent.Children()
c.Assert(err, check.IsNil)
c.Check(kids, check.HasLen, 0)
// Create a child
child, err = s.Namespace.Worker("child")
c.Assert(err, check.IsNil)
err = child.SetParent(parent)
c.Assert(err, check.IsNil)
// this should update the parent metadata
worker, err = parent.Parent()
c.Assert(err, check.IsNil)
c.Check(worker, check.IsNil)
kids, err = parent.Children()
c.Assert(err, check.IsNil)
c.Check(kids, check.HasLen, 1)
if len(kids) > 0 {
c.Check(kids[0].Name(), check.Equals, "child")
}
// and also the child metadata
worker, err = child.Parent()
c.Assert(err, check.IsNil)
c.Check(worker, check.NotNil)
if worker != nil {
c.Check(worker.Name(), check.Equals, "parent")
}
kids, err = child.Children()
c.Assert(err, check.IsNil)
c.Check(kids, check.HasLen, 0)
}