本文整理汇总了Golang中github.com/dmaze/goordinate/coordinate.WorkUnit.Data方法的典型用法代码示例。如果您正苦于以下问题:Golang WorkUnit.Data方法的具体用法?Golang WorkUnit.Data怎么用?Golang WorkUnit.Data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/dmaze/goordinate/coordinate.WorkUnit
的用法示例。
在下文中一共展示了WorkUnit.Data方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestWorkUnitData
// TestWorkUnitData validates that the system can store and update
// data.
func (s *Suite) TestWorkUnitData(c *check.C) {
var (
data map[string]interface{}
unit coordinate.WorkUnit
)
spec, err := s.Namespace.SetWorkSpec(map[string]interface{}{
"name": "spec",
"min_gb": 1,
})
c.Assert(err, check.IsNil)
_, err = spec.AddWorkUnit("a", map[string]interface{}{
"name": "a",
"value": 1,
}, 0.0)
c.Assert(err, check.IsNil)
_, err = spec.AddWorkUnit("b", map[string]interface{}{
"name": "b",
"value": 2,
}, 0.0)
c.Assert(err, check.IsNil)
unit, err = spec.WorkUnit("a")
c.Assert(err, check.IsNil)
data, err = unit.Data()
c.Assert(err, check.IsNil)
c.Check(data, check.HasLen, 2)
c.Check(data["name"], check.Equals, "a")
c.Check(data["value"], Like, 1)
unit, err = spec.WorkUnit("b")
c.Assert(err, check.IsNil)
data, err = unit.Data()
c.Assert(err, check.IsNil)
c.Check(data, check.HasLen, 2)
c.Check(data["name"], check.Equals, "b")
c.Check(data["value"], Like, 2)
}
示例2: TestChainingMixed
// TestChainingMixed uses a combination of strings and tuples in its
// "output" data.
func (s *Suite) TestChainingMixed(c *check.C) {
var (
one, two coordinate.WorkSpec
worker coordinate.Worker
attempts []coordinate.Attempt
units map[string]coordinate.WorkUnit
unit coordinate.WorkUnit
data map[string]interface{}
priority float64
ok bool
err error
)
one, err = s.Namespace.SetWorkSpec(map[string]interface{}{
"name": "one",
"then": "two",
})
c.Assert(err, check.IsNil)
two, err = s.Namespace.SetWorkSpec(map[string]interface{}{
"name": "two",
})
c.Assert(err, check.IsNil)
worker, err = s.Namespace.Worker("worker")
c.Assert(err, check.IsNil)
_, err = one.AddWorkUnit("a", map[string]interface{}{}, 0.0)
c.Assert(err, check.IsNil)
attempts, err = worker.RequestAttempts(coordinate.AttemptRequest{})
c.Assert(err, check.IsNil)
c.Assert(attempts, check.HasLen, 1)
err = attempts[0].Finish(map[string]interface{}{
"output": []interface{}{
"key",
cborrpc.PythonTuple{Items: []interface{}{
"key",
map[string]interface{}{
"data": "x",
},
map[string]interface{}{
"priority": 10.0,
},
}},
},
})
c.Assert(err, check.IsNil)
units, err = two.WorkUnits(coordinate.WorkUnitQuery{})
c.Assert(err, check.IsNil)
c.Check(units, HasKeys, []string{"key"})
if unit, ok = units["key"]; ok {
data, err = unit.Data()
c.Assert(err, check.IsNil)
c.Check(data, check.DeepEquals, map[string]interface{}{"data": "x"})
priority, err = unit.Priority()
c.Assert(err, check.IsNil)
c.Check(priority, check.Equals, 10.0)
}
}
示例3: TestChainingTwoStep
// TestChainingTwoStep separately renews an attempt to insert an output
// key, then finishes the work unit; it should still chain.
func (s *Suite) TestChainingTwoStep(c *check.C) {
var (
one, two coordinate.WorkSpec
worker coordinate.Worker
attempts []coordinate.Attempt
units map[string]coordinate.WorkUnit
unit coordinate.WorkUnit
data map[string]interface{}
priority float64
ok bool
err error
)
one, err = s.Namespace.SetWorkSpec(map[string]interface{}{
"name": "one",
"then": "two",
})
c.Assert(err, check.IsNil)
two, err = s.Namespace.SetWorkSpec(map[string]interface{}{
"name": "two",
})
c.Assert(err, check.IsNil)
worker, err = s.Namespace.Worker("worker")
c.Assert(err, check.IsNil)
_, err = one.AddWorkUnit("a", map[string]interface{}{}, 0.0)
c.Assert(err, check.IsNil)
attempts, err = worker.RequestAttempts(coordinate.AttemptRequest{})
c.Assert(err, check.IsNil)
c.Assert(attempts, check.HasLen, 1)
err = attempts[0].Renew(time.Duration(900)*time.Second,
map[string]interface{}{
"output": []interface{}{
[]byte{1, 2, 3, 4},
cborrpc.PythonTuple{Items: []interface{}{
[]byte{1, 2, 3, 4},
map[interface{}]interface{}{},
map[interface{}]interface{}{
"priority": 0,
},
}},
},
})
c.Assert(err, check.IsNil)
err = attempts[0].Finish(nil)
units, err = two.WorkUnits(coordinate.WorkUnitQuery{})
c.Assert(err, check.IsNil)
c.Check(units, HasKeys, []string{"\x01\x02\x03\x04"})
if unit, ok = units["\x01\x02\x03\x04"]; ok {
data, err = unit.Data()
c.Assert(err, check.IsNil)
c.Check(data, check.DeepEquals, map[string]interface{}{})
priority, err = unit.Priority()
c.Assert(err, check.IsNil)
c.Check(priority, check.Equals, 0.0)
}
}
示例4: 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)
//.........这里部分代码省略.........