本文整理汇总了Golang中github.com/dmaze/goordinate/coordinate.WorkUnit.Status方法的典型用法代码示例。如果您正苦于以下问题:Golang WorkUnit.Status方法的具体用法?Golang WorkUnit.Status怎么用?Golang WorkUnit.Status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/dmaze/goordinate/coordinate.WorkUnit
的用法示例。
在下文中一共展示了WorkUnit.Status方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestAttemptLifetime
// TestAttemptLifetime validates a basic attempt lifetime.
func (s *Suite) TestAttemptLifetime(c *check.C) {
var (
err error
data map[string]interface{}
attempt, attempt2 coordinate.Attempt
aStatus coordinate.AttemptStatus
spec coordinate.WorkSpec
unit coordinate.WorkUnit
worker coordinate.Worker
uStatus coordinate.WorkUnitStatus
)
spec, worker = s.makeWorkSpecAndWorker(c)
// Create a work unit
unit, err = spec.AddWorkUnit("a", map[string]interface{}{}, 0.0)
c.Assert(err, check.IsNil)
// The work unit should be "available"
uStatus, err = unit.Status()
c.Assert(err, check.IsNil)
c.Check(uStatus, check.Equals, coordinate.AvailableUnit)
// The work unit data should be defined but empty
data, err = unit.Data()
c.Assert(err, check.IsNil)
c.Check(data, check.HasLen, 0)
// Get an attempt for it
attempts, err := worker.RequestAttempts(coordinate.AttemptRequest{})
c.Assert(err, check.IsNil)
c.Assert(attempts, check.HasLen, 1)
attempt = attempts[0]
// The work unit should be "pending"
uStatus, err = unit.Status()
c.Assert(err, check.IsNil)
c.Check(uStatus, check.Equals, coordinate.PendingUnit)
// The attempt should be "pending" too
aStatus, err = attempt.Status()
c.Assert(err, check.IsNil)
c.Check(aStatus, check.Equals, coordinate.Pending)
// The active attempt for the unit should match this
attempt2, err = unit.ActiveAttempt()
c.Assert(err, check.IsNil)
c.Check(attempt2, AttemptMatches, attempt)
// There should be one active attempt for the worker and it should
// also match
attempts, err = worker.ActiveAttempts()
c.Assert(err, check.IsNil)
c.Check(attempts, check.HasLen, 1)
if len(attempts) > 0 {
c.Check(attempts[0], AttemptMatches, attempt)
}
// The work unit data should (still) be defined but empty
data, err = unit.Data()
c.Assert(err, check.IsNil)
c.Check(data, check.HasLen, 0)
// Now finish the attempt with some updated data
err = attempt.Finish(map[string]interface{}{
"outputs": []string{"yes"},
})
c.Assert(err, check.IsNil)
// The unit should report "finished"
uStatus, err = unit.Status()
c.Assert(err, check.IsNil)
c.Check(uStatus, check.Equals, coordinate.FinishedUnit)
// The attempt should report "finished"
aStatus, err = attempt.Status()
c.Assert(err, check.IsNil)
c.Check(aStatus, check.Equals, coordinate.Finished)
// The attempt should still be the active attempt for the unit
attempt2, err = unit.ActiveAttempt()
c.Assert(err, check.IsNil)
c.Check(attempt2, AttemptMatches, attempt)
// The attempt should not be in the active attempt list for the worker
attempts, err = worker.ActiveAttempts()
c.Assert(err, check.IsNil)
c.Check(attempts, check.HasLen, 0)
// Both the unit and the worker should have one archived attempt
attempts, err = unit.Attempts()
c.Assert(err, check.IsNil)
c.Check(attempts, check.HasLen, 1)
if len(attempts) > 0 {
c.Check(attempts[0], AttemptMatches, attempt)
}
attempts, err = worker.AllAttempts()
c.Assert(err, check.IsNil)
c.Check(attempts, check.HasLen, 1)
//.........这里部分代码省略.........