本文整理汇总了Golang中github.com/dmaze/goordinate/coordinate.WorkSpec.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang WorkSpec.Name方法的具体用法?Golang WorkSpec.Name怎么用?Golang WorkSpec.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/dmaze/goordinate/coordinate.WorkSpec
的用法示例。
在下文中一共展示了WorkSpec.Name方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSpecCreateDestroy
// TestSpecCreateDestroy performs basic work spec lifetime tests.
func (s *Suite) TestSpecCreateDestroy(c *check.C) {
var (
data map[string]interface{}
dict map[string]interface{}
spec coordinate.WorkSpec
name string
names []string
err error
)
name = "spec"
spec, err = s.Namespace.WorkSpec(name)
c.Check(err, check.DeepEquals,
coordinate.ErrNoSuchWorkSpec{Name: name})
names, err = s.Namespace.WorkSpecNames()
c.Assert(err, check.IsNil)
c.Check(names, check.HasLen, 0)
dict = map[string]interface{}{
"name": name,
"min_gb": 0.1,
}
spec, err = s.Namespace.SetWorkSpec(dict)
c.Assert(err, check.IsNil)
c.Check(spec, check.NotNil)
c.Check(spec.Name(), check.Equals, name)
spec, err = s.Namespace.WorkSpec(name)
c.Assert(err, check.IsNil)
c.Check(spec, check.NotNil)
c.Check(spec.Name(), check.Equals, name)
data, err = spec.Data()
c.Assert(err, check.IsNil)
c.Check(data, check.DeepEquals, dict)
names, err = s.Namespace.WorkSpecNames()
c.Assert(err, check.IsNil)
c.Check(names, check.DeepEquals, []string{name})
err = s.Namespace.DestroyWorkSpec(name)
c.Check(err, check.IsNil)
spec, err = s.Namespace.WorkSpec(name)
c.Check(err, check.DeepEquals,
coordinate.ErrNoSuchWorkSpec{Name: name})
names, err = s.Namespace.WorkSpecNames()
c.Assert(err, check.IsNil)
c.Check(names, check.HasLen, 0)
err = s.Namespace.DestroyWorkSpec(name)
c.Check(err, check.DeepEquals,
coordinate.ErrNoSuchWorkSpec{Name: name})
}
示例2: TestChangeSpecData
// TestChangeSpecData tests WorkSpec.SetData().
func (s *Suite) TestChangeSpecData(c *check.C) {
var (
err error
data map[string]interface{}
spec coordinate.WorkSpec
)
spec, err = s.Namespace.SetWorkSpec(map[string]interface{}{
"name": "spec",
"min_gb": 1,
})
c.Assert(err, check.IsNil)
c.Check(spec.Name(), check.Equals, "spec")
err = spec.SetData(map[string]interface{}{
"name": "spec",
"min_gb": 2,
"foo": "bar",
})
c.Assert(err, check.IsNil)
data, err = spec.Data()
c.Assert(err, check.IsNil)
c.Check(data["name"], check.Equals, "spec")
c.Check(data["min_gb"], Like, 2)
c.Check(data["foo"], check.Equals, "bar")
err = spec.SetData(map[string]interface{}{})
c.Assert(err, check.NotNil)
c.Check(err, check.Equals, coordinate.ErrNoWorkSpecName)
err = spec.SetData(map[string]interface{}{
"name": "name",
"min_gb": 3,
})
c.Assert(err, check.NotNil)
c.Check(err, check.Equals, coordinate.ErrChangedName)
data, err = spec.Data()
c.Assert(err, check.IsNil)
c.Check(data["name"], check.Equals, "spec")
c.Check(data["min_gb"], Like, 2)
c.Check(data["foo"], check.Equals, "bar")
}
示例3: checkWorkUnitOrder
// checkWorkUnitOrder verifies that getting all of the work possible
// retrieves work units in a specific order.
func checkWorkUnitOrder(
c *check.C,
worker coordinate.Worker,
spec coordinate.WorkSpec,
unitNames ...string,
) {
var processedUnits []string
for {
attempts, err := worker.RequestAttempts(coordinate.AttemptRequest{})
c.Assert(err, check.IsNil)
if len(attempts) == 0 {
break
}
c.Assert(attempts, check.HasLen, 1)
attempt := attempts[0]
c.Check(attempt.WorkUnit().WorkSpec().Name(), check.Equals, spec.Name())
processedUnits = append(processedUnits, attempt.WorkUnit().Name())
err = attempt.Finish(nil)
c.Assert(err, check.IsNil)
}
c.Check(processedUnits, check.DeepEquals, unitNames)
}
示例4: TestTwoWorkSpecsBasic
// TestTwoWorkSpecsBasic ensures that two work specs can be created
// and have independent lifetimes.
func (s *Suite) TestTwoWorkSpecsBasic(c *check.C) {
var (
err error
dict1, dict2 map[string]interface{}
name1, name2 string
names []string
spec coordinate.WorkSpec
)
name1 = "spec1"
name2 = "spec2"
dict1 = map[string]interface{}{"name": name1, "min_gb": 1}
dict2 = map[string]interface{}{"name": name2, "min_gb": 2}
names, err = s.Namespace.WorkSpecNames()
c.Assert(err, check.IsNil)
c.Check(names, check.HasLen, 0)
spec, err = s.Namespace.SetWorkSpec(dict1)
c.Assert(err, check.IsNil)
names, err = s.Namespace.WorkSpecNames()
c.Assert(err, check.IsNil)
c.Check(names, check.DeepEquals, []string{name1})
spec, err = s.Namespace.SetWorkSpec(dict2)
c.Assert(err, check.IsNil)
names, err = s.Namespace.WorkSpecNames()
c.Assert(err, check.IsNil)
c.Check(names, check.HasLen, 2)
if len(names) > 0 {
if names[0] == name1 {
c.Check(names, check.DeepEquals, []string{name1, name2})
} else {
c.Check(names, check.DeepEquals, []string{name2, name1})
}
}
spec, err = s.Namespace.WorkSpec(name1)
c.Assert(err, check.IsNil)
c.Assert(spec, check.NotNil)
c.Check(spec.Name(), check.Equals, name1)
spec, err = s.Namespace.WorkSpec(name2)
c.Assert(err, check.IsNil)
c.Assert(spec, check.NotNil)
c.Check(spec.Name(), check.Equals, name2)
err = s.Namespace.DestroyWorkSpec(name1)
c.Assert(err, check.IsNil)
names, err = s.Namespace.WorkSpecNames()
c.Assert(err, check.IsNil)
c.Check(names, check.DeepEquals, []string{name2})
spec, err = s.Namespace.WorkSpec(name1)
c.Check(err, check.DeepEquals, coordinate.ErrNoSuchWorkSpec{Name: name1})
spec, err = s.Namespace.WorkSpec(name2)
c.Assert(err, check.IsNil)
c.Assert(spec, check.NotNil)
c.Check(spec.Name(), check.Equals, name2)
err = s.Namespace.DestroyWorkSpec(name2)
c.Assert(err, check.IsNil)
names, err = s.Namespace.WorkSpecNames()
c.Assert(err, check.IsNil)
c.Check(names, check.HasLen, 0)
spec, err = s.Namespace.WorkSpec(name1)
c.Check(err, check.DeepEquals, coordinate.ErrNoSuchWorkSpec{Name: name1})
spec, err = s.Namespace.WorkSpec(name2)
c.Check(err, check.DeepEquals, coordinate.ErrNoSuchWorkSpec{Name: name2})
}