本文整理汇总了Golang中launchpad/net/juju-core/worker/uniter/hook.Info.ChangeVersion方法的典型用法代码示例。如果您正苦于以下问题:Golang Info.ChangeVersion方法的具体用法?Golang Info.ChangeVersion怎么用?Golang Info.ChangeVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类launchpad/net/juju-core/worker/uniter/hook.Info
的用法示例。
在下文中一共展示了Info.ChangeVersion方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: assertHook
func (s *RelationerSuite) assertHook(c *C, expect hook.Info) {
s.State.StartSync()
select {
case hi, ok := <-s.hooks:
c.Assert(ok, Equals, true)
expect.ChangeVersion = hi.ChangeVersion
c.Assert(hi, DeepEquals, expect)
c.Assert(s.dir.Write(hi), Equals, nil)
case <-time.After(500 * time.Millisecond):
c.Fatalf("timed out waiting for %#v", expect)
}
}
示例2: assertHook
func (s *RelationerSuite) assertHook(c *C, expect hook.Info) {
s.State.StartSync()
// We must ensure the local state dir exists first.
c.Assert(s.dir.Ensure(), IsNil)
select {
case hi, ok := <-s.hooks:
c.Assert(ok, Equals, true)
expect.ChangeVersion = hi.ChangeVersion
c.Assert(hi, DeepEquals, expect)
c.Assert(s.dir.Write(hi), Equals, nil)
case <-time.After(coretesting.LongWait):
c.Fatalf("timed out waiting for %#v", expect)
}
}
示例3: TestPrepareCommitHooks
func (s *RelationerSuite) TestPrepareCommitHooks(c *C) {
r := uniter.NewRelationer(s.ru, s.dir, s.hooks)
err := r.Join()
c.Assert(err, IsNil)
ctx := r.Context()
c.Assert(ctx.UnitNames(), HasLen, 0)
// Check preparing an invalid hook changes nothing.
changed := hook.Info{
Kind: hook.RelationChanged,
RemoteUnit: "u/1",
ChangeVersion: 7,
Members: map[string]map[string]interface{}{
"u/1": {"private-address": "glastonbury"},
},
}
_, err = r.PrepareHook(changed)
c.Assert(err, ErrorMatches, `inappropriate "relation-changed" for "u/1": unit has not joined`)
c.Assert(ctx.UnitNames(), HasLen, 0)
c.Assert(s.dir.State().Members, HasLen, 0)
// Check preparing a valid hook updates the context, but not persistent
// relation state.
joined := hook.Info{
Kind: hook.RelationJoined,
RemoteUnit: "u/1",
Members: map[string]map[string]interface{}{
"u/1": {"private-address": "u-1.example.com"},
},
}
name, err := r.PrepareHook(joined)
c.Assert(err, IsNil)
c.Assert(s.dir.State().Members, HasLen, 0)
c.Assert(name, Equals, "my-relation-relation-joined")
c.Assert(ctx.UnitNames(), DeepEquals, []string{"u/1"})
s1, err := ctx.ReadSettings("u/1")
c.Assert(err, IsNil)
c.Assert(s1, DeepEquals, joined.Members["u/1"])
// Clear the changed hook's Members, as though it had been deserialized.
changed.Members = nil
// Check that preparing the following hook fails as before...
_, err = r.PrepareHook(changed)
c.Assert(err, ErrorMatches, `inappropriate "relation-changed" for "u/1": unit has not joined`)
c.Assert(s.dir.State().Members, HasLen, 0)
c.Assert(ctx.UnitNames(), DeepEquals, []string{"u/1"})
s1, err = ctx.ReadSettings("u/1")
c.Assert(err, IsNil)
c.Assert(s1, DeepEquals, joined.Members["u/1"])
// ...but that committing the previous hook updates the persistent
// relation state...
err = r.CommitHook(joined)
c.Assert(err, IsNil)
c.Assert(s.dir.State().Members, DeepEquals, map[string]int64{"u/1": 0})
c.Assert(ctx.UnitNames(), DeepEquals, []string{"u/1"})
s1, err = ctx.ReadSettings("u/1")
c.Assert(err, IsNil)
c.Assert(s1, DeepEquals, joined.Members["u/1"])
// ...and allows us to prepare the next hook...
name, err = r.PrepareHook(changed)
c.Assert(err, IsNil)
c.Assert(name, Equals, "my-relation-relation-changed")
c.Assert(s.dir.State().Members, DeepEquals, map[string]int64{"u/1": 0})
c.Assert(ctx.UnitNames(), DeepEquals, []string{"u/1"})
s1, err = ctx.ReadSettings("u/1")
c.Assert(err, IsNil)
c.Assert(s1, DeepEquals, map[string]interface{}{"private-address": "u-1.example.com"})
// ...and commit it.
err = r.CommitHook(changed)
c.Assert(err, IsNil)
c.Assert(s.dir.State().Members, DeepEquals, map[string]int64{"u/1": 7})
c.Assert(ctx.UnitNames(), DeepEquals, []string{"u/1"})
// To verify implied behaviour above, prepare a new joined hook with
// missing membership information, and check relation context
// membership is updated appropriately...
joined.RemoteUnit = "u/2"
joined.ChangeVersion = 3
joined.Members = nil
name, err = r.PrepareHook(joined)
c.Assert(err, IsNil)
c.Assert(s.dir.State().Members, HasLen, 1)
c.Assert(name, Equals, "my-relation-relation-joined")
c.Assert(ctx.UnitNames(), DeepEquals, []string{"u/1", "u/2"})
// ...and so is relation state on commit.
err = r.CommitHook(joined)
c.Assert(err, IsNil)
c.Assert(s.dir.State().Members, DeepEquals, map[string]int64{"u/1": 7, "u/2": 3})
c.Assert(ctx.UnitNames(), DeepEquals, []string{"u/1", "u/2"})
}