本文整理汇总了Golang中github.com/juju/juju/worker/environ.NewTracker函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTracker函数的具体用法?Golang NewTracker怎么用?Golang NewTracker使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTracker函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: loop
func (u *updaterWorker) loop() (err error) {
// TODO(fwereade): get this as a resource from a dependency.Engine.
tracker, err := environ.NewTracker(environ.Config{
Observer: u.st,
})
if err != nil {
return errors.Trace(err)
}
if err := u.catacomb.Add(tracker); err != nil {
return errors.Trace(err)
}
u.aggregator = newAggregator(tracker.Environ())
if err := u.catacomb.Add(u.aggregator); err != nil {
return errors.Trace(err)
}
logger.Infof("instance poller received inital environment configuration")
watcher, err := u.st.WatchModelMachines()
if err != nil {
return err
}
if err := u.catacomb.Add(watcher); err != nil {
return errors.Trace(err)
}
return watchMachinesLoop(u, watcher)
}
示例2: testValidate
func (s *TrackerSuite) testValidate(c *gc.C, config environ.Config, check func(err error)) {
err := config.Validate()
check(err)
tracker, err := environ.NewTracker(config)
c.Check(tracker, gc.IsNil)
check(err)
}
示例3: TestValidateObserver
func (s *TrackerSuite) TestValidateObserver(c *gc.C) {
config := environ.Config{}
check := func(err error) {
c.Check(err, jc.Satisfies, errors.IsNotValid)
c.Check(err, gc.ErrorMatches, "nil Observer not valid")
}
err := config.Validate()
check(err)
tracker, err := environ.NewTracker(config)
c.Check(tracker, gc.IsNil)
check(err)
}
示例4: TestModelConfigInvalid
func (s *TrackerSuite) TestModelConfigInvalid(c *gc.C) {
fix := &fixture{}
fix.Run(c, func(context *runContext) {
tracker, err := environ.NewTracker(environ.Config{
Observer: context,
NewEnvironFunc: func(environs.OpenParams) (environs.Environ, error) {
return nil, errors.NotValidf("config")
},
})
c.Check(err, gc.ErrorMatches, `cannot create environ: config not valid`)
c.Check(tracker, gc.IsNil)
context.CheckCallNames(c, "ModelConfig", "CloudSpec")
})
}
示例5: TestWatchCloses
func (s *TrackerSuite) TestWatchCloses(c *gc.C) {
fix := &fixture{}
fix.Run(c, func(context *runContext) {
tracker, err := environ.NewTracker(environ.Config{
Observer: context,
})
c.Assert(err, jc.ErrorIsNil)
defer workertest.DirtyKill(c, tracker)
context.CloseNotify()
err = workertest.CheckKilled(c, tracker)
c.Check(err, gc.ErrorMatches, "environ config watch closed")
context.CheckCallNames(c, "EnvironConfig", "WatchForEnvironConfigChanges")
})
}
示例6: TestEnvironConfigInvalid
func (s *TrackerSuite) TestEnvironConfigInvalid(c *gc.C) {
fix := &fixture{
initialConfig: coretesting.Attrs{
"type": "unknown",
},
}
fix.Run(c, func(context *runContext) {
tracker, err := environ.NewTracker(environ.Config{
Observer: context,
})
c.Check(err, gc.ErrorMatches, `cannot create environ: no registered provider for "unknown"`)
c.Check(tracker, gc.IsNil)
context.CheckCallNames(c, "EnvironConfig")
})
}
示例7: TestEnvironConfigFails
func (s *TrackerSuite) TestEnvironConfigFails(c *gc.C) {
fix := &fixture{
observerErrs: []error{
errors.New("no yuo"),
},
}
fix.Run(c, func(context *runContext) {
tracker, err := environ.NewTracker(environ.Config{
Observer: context,
})
c.Check(err, gc.ErrorMatches, "cannot read environ config: no yuo")
c.Check(tracker, gc.IsNil)
context.CheckCallNames(c, "EnvironConfig")
})
}
示例8: TestWatchFails
func (s *TrackerSuite) TestWatchFails(c *gc.C) {
fix := &fixture{
observerErrs: []error{
nil, errors.New("grrk splat"),
},
}
fix.Run(c, func(context *runContext) {
tracker, err := environ.NewTracker(environ.Config{
Observer: context,
})
c.Assert(err, jc.ErrorIsNil)
defer workertest.DirtyKill(c, tracker)
err = workertest.CheckKilled(c, tracker)
c.Check(err, gc.ErrorMatches, "cannot watch environ config: grrk splat")
context.CheckCallNames(c, "EnvironConfig", "WatchForEnvironConfigChanges")
})
}
示例9: TestEnvironConfigValid
func (s *TrackerSuite) TestEnvironConfigValid(c *gc.C) {
fix := &fixture{
initialConfig: coretesting.Attrs{
"name": "this-particular-name",
},
}
fix.Run(c, func(context *runContext) {
tracker, err := environ.NewTracker(environ.Config{
Observer: context,
})
c.Assert(err, jc.ErrorIsNil)
defer workertest.CleanKill(c, tracker)
gotEnviron := tracker.Environ()
c.Assert(gotEnviron, gc.NotNil)
c.Check(gotEnviron.Config().Name(), gc.Equals, "this-particular-name")
})
}
示例10: TestWatchedEnvironConfigIncompatible
func (s *TrackerSuite) TestWatchedEnvironConfigIncompatible(c *gc.C) {
fix := &fixture{
initialConfig: coretesting.Attrs{
"broken": "SetConfig",
},
}
fix.Run(c, func(context *runContext) {
tracker, err := environ.NewTracker(environ.Config{
Observer: context,
})
c.Check(err, jc.ErrorIsNil)
defer workertest.DirtyKill(c, tracker)
context.SendNotify()
err = workertest.CheckKilled(c, tracker)
c.Check(err, gc.ErrorMatches, "cannot update environ config: dummy.SetConfig is broken")
context.CheckCallNames(c, "EnvironConfig", "WatchForEnvironConfigChanges", "EnvironConfig")
})
}
示例11: TestWatchedModelConfigFails
func (s *TrackerSuite) TestWatchedModelConfigFails(c *gc.C) {
fix := &fixture{
observerErrs: []error{
nil, nil, errors.New("blam ouch"),
},
}
fix.Run(c, func(context *runContext) {
tracker, err := environ.NewTracker(environ.Config{
Observer: context,
})
c.Check(err, jc.ErrorIsNil)
defer workertest.DirtyKill(c, tracker)
context.SendNotify()
err = workertest.CheckKilled(c, tracker)
c.Check(err, gc.ErrorMatches, "cannot read environ config: blam ouch")
context.CheckCallNames(c, "ModelConfig", "WatchForModelConfigChanges", "ModelConfig")
})
}
示例12: TestWatchedModelConfigIncompatible
func (s *TrackerSuite) TestWatchedModelConfigIncompatible(c *gc.C) {
fix := &fixture{}
fix.Run(c, func(context *runContext) {
tracker, err := environ.NewTracker(environ.Config{
Observer: context,
NewEnvironFunc: func(environs.OpenParams) (environs.Environ, error) {
env := &mockEnviron{}
env.SetErrors(errors.New("SetConfig is broken"))
return env, nil
},
})
c.Check(err, jc.ErrorIsNil)
defer workertest.DirtyKill(c, tracker)
context.SendModelConfigNotify()
err = workertest.CheckKilled(c, tracker)
c.Check(err, gc.ErrorMatches, "cannot update environ config: SetConfig is broken")
context.CheckCallNames(c, "ModelConfig", "CloudSpec", "WatchForModelConfigChanges", "ModelConfig")
})
}
示例13: TestCloudSpec
func (s *TrackerSuite) TestCloudSpec(c *gc.C) {
cloudSpec := environs.CloudSpec{
Name: "foo",
Type: "bar",
Region: "baz",
}
fix := &fixture{cloud: cloudSpec}
fix.Run(c, func(context *runContext) {
tracker, err := environ.NewTracker(environ.Config{
Observer: context,
NewEnvironFunc: func(args environs.OpenParams) (environs.Environ, error) {
c.Assert(args.Cloud, jc.DeepEquals, cloudSpec)
return nil, errors.NotValidf("cloud spec")
},
})
c.Check(err, gc.ErrorMatches, `cannot create environ: cloud spec not valid`)
c.Check(tracker, gc.IsNil)
context.CheckCallNames(c, "ModelConfig", "CloudSpec")
})
}
示例14: TestWatchedModelConfigUpdates
func (s *TrackerSuite) TestWatchedModelConfigUpdates(c *gc.C) {
fix := &fixture{
initialConfig: coretesting.Attrs{
"name": "original-name",
},
}
fix.Run(c, func(context *runContext) {
tracker, err := environ.NewTracker(environ.Config{
Observer: context,
NewEnvironFunc: newMockEnviron,
})
c.Check(err, jc.ErrorIsNil)
defer workertest.CleanKill(c, tracker)
context.SetConfig(c, coretesting.Attrs{
"name": "updated-name",
})
gotEnviron := tracker.Environ()
c.Assert(gotEnviron.Config().Name(), gc.Equals, "original-name")
timeout := time.After(coretesting.LongWait)
attempt := time.After(0)
context.SendModelConfigNotify()
for {
select {
case <-attempt:
name := gotEnviron.Config().Name()
if name == "original-name" {
attempt = time.After(coretesting.ShortWait)
continue
}
c.Check(name, gc.Equals, "updated-name")
case <-timeout:
c.Fatalf("timed out waiting for environ to be updated")
}
break
}
context.CheckCallNames(c, "ModelConfig", "CloudSpec", "WatchForModelConfigChanges", "ModelConfig")
})
}