本文整理汇总了Golang中github.com/juju/juju/watcher/watchertest.NewStringsWatcherC函数的典型用法代码示例。如果您正苦于以下问题:Golang NewStringsWatcherC函数的具体用法?Golang NewStringsWatcherC怎么用?Golang NewStringsWatcherC使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewStringsWatcherC函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestWatchUnits
func (s *machineSuite) TestWatchUnits(c *gc.C) {
w, err := s.apiMachine.WatchUnits()
c.Assert(err, jc.ErrorIsNil)
wc := watchertest.NewStringsWatcherC(c, w, s.BackingState.StartSync)
defer wc.AssertStops()
// Initial event.
wc.AssertChange("wordpress/0")
wc.AssertNoChange()
// Change something other than the life cycle and make sure it's
// not detected.
err = s.machines[0].SetPassword("foo")
c.Assert(err, gc.ErrorMatches, "password is only 3 bytes long, and is not a valid Agent password")
wc.AssertNoChange()
err = s.machines[0].SetPassword("foo-12345678901234567890")
c.Assert(err, jc.ErrorIsNil)
wc.AssertNoChange()
// Unassign unit 0 from the machine and check it's detected.
err = s.units[0].UnassignFromMachine()
c.Assert(err, jc.ErrorIsNil)
wc.AssertChange("wordpress/0")
wc.AssertNoChange()
}
开发者ID:makyo,项目名称:juju,代码行数:26,代码来源:machine_test.go
示例2: TestWatchModelMachines
func (s *provisionerSuite) TestWatchModelMachines(c *gc.C) {
w, err := s.provisioner.WatchModelMachines()
c.Assert(err, jc.ErrorIsNil)
wc := watchertest.NewStringsWatcherC(c, w, s.BackingState.StartSync)
defer wc.AssertStops()
// Initial event.
wc.AssertChange(s.machine.Id())
// Add another 2 machines make sure they are detected.
otherMachine, err := s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, jc.ErrorIsNil)
otherMachine, err = s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, jc.ErrorIsNil)
wc.AssertChange("1", "2")
// Change the lifecycle of last machine.
err = otherMachine.EnsureDead()
c.Assert(err, jc.ErrorIsNil)
wc.AssertChange("2")
// Add a container and make sure it's not detected.
template := state.MachineTemplate{
Series: "quantal",
Jobs: []state.MachineJob{state.JobHostUnits},
}
_, err = s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXC)
c.Assert(err, jc.ErrorIsNil)
wc.AssertNoChange()
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:30,代码来源:provisioner_test.go
示例3: TestWatchRelations
func (s *serviceSuite) TestWatchRelations(c *gc.C) {
w, err := s.apiService.WatchRelations()
c.Assert(err, jc.ErrorIsNil)
wc := watchertest.NewStringsWatcherC(c, w, s.BackingState.StartSync)
defer wc.AssertStops()
// Initial event.
wc.AssertChange()
wc.AssertNoChange()
// Change something other than the lifecycle and make sure it's
// not detected.
err = s.wordpressService.SetExposed()
c.Assert(err, jc.ErrorIsNil)
wc.AssertNoChange()
// Add another service and relate it to wordpress,
// check it's detected.
s.addMachineServiceCharmAndUnit(c, "mysql")
rel := s.addRelation(c, "wordpress", "mysql")
wc.AssertChange(rel.String())
// Destroy the relation and check it's detected.
err = rel.Destroy()
c.Assert(err, jc.ErrorIsNil)
wc.AssertChange(rel.String())
wc.AssertNoChange()
}
开发者ID:bac,项目名称:juju,代码行数:28,代码来源:application_test.go
示例4: TestWatchActionNotifications
func (s *unitSuite) TestWatchActionNotifications(c *gc.C) {
w, err := s.apiUnit.WatchActionNotifications()
c.Assert(err, jc.ErrorIsNil)
wc := watchertest.NewStringsWatcherC(c, w, s.BackingState.StartSync)
defer wc.AssertStops()
// Initial event.
wc.AssertChange()
// Add a couple of actions and make sure the changes are detected.
action, err := s.wordpressUnit.AddAction("fakeaction", map[string]interface{}{
"outfile": "foo.txt",
})
c.Assert(err, jc.ErrorIsNil)
wc.AssertChange(action.Id())
action, err = s.wordpressUnit.AddAction("fakeaction", map[string]interface{}{
"outfile": "foo.bz2",
"compression": map[string]interface{}{
"kind": "bzip",
"quality": float64(5.0),
},
})
c.Assert(err, jc.ErrorIsNil)
wc.AssertChange(action.Id())
}
开发者ID:bac,项目名称:juju,代码行数:26,代码来源:unit_test.go
示例5: TestWatchUnits
func (s *deployerSuite) TestWatchUnits(c *gc.C) {
// TODO(dfc) fix state.Machine to return a MachineTag
machine, err := s.st.Machine(s.machine.Tag().(names.MachineTag))
c.Assert(err, jc.ErrorIsNil)
w, err := machine.WatchUnits()
c.Assert(err, jc.ErrorIsNil)
wc := watchertest.NewStringsWatcherC(c, w, s.BackingState.StartSync)
defer wc.AssertStops()
// Initial event.
wc.AssertChange("mysql/0", "logging/0")
wc.AssertNoChange()
// Change something other than the lifecycle and make sure it's
// not detected.
err = s.subordinate.SetPassword("foo")
c.Assert(err, gc.ErrorMatches, "password is only 3 bytes long, and is not a valid Agent password")
wc.AssertNoChange()
err = s.subordinate.SetPassword("foo-12345678901234567890")
c.Assert(err, jc.ErrorIsNil)
wc.AssertNoChange()
// Make the subordinate dead and check it's detected.
err = s.subordinate.EnsureDead()
c.Assert(err, jc.ErrorIsNil)
wc.AssertChange("logging/0")
wc.AssertNoChange()
}
开发者ID:pmatulis,项目名称:juju,代码行数:29,代码来源:deployer_test.go
示例6: TestWatchUnitsKeepsEvents
func (s *watcherSuite) TestWatchUnitsKeepsEvents(c *gc.C) {
// Create two services, relate them, and add one unit to each - a
// principal and a subordinate.
mysql := s.AddTestingService(c, "mysql", s.AddTestingCharm(c, "mysql"))
s.AddTestingService(c, "logging", s.AddTestingCharm(c, "logging"))
eps, err := s.State.InferEndpoints("mysql", "logging")
c.Assert(err, jc.ErrorIsNil)
rel, err := s.State.AddRelation(eps...)
c.Assert(err, jc.ErrorIsNil)
principal, err := mysql.AddUnit()
c.Assert(err, jc.ErrorIsNil)
err = principal.AssignToMachine(s.rawMachine)
c.Assert(err, jc.ErrorIsNil)
relUnit, err := rel.Unit(principal)
c.Assert(err, jc.ErrorIsNil)
err = relUnit.EnterScope(nil)
c.Assert(err, jc.ErrorIsNil)
subordinate, err := s.State.Unit("logging/0")
c.Assert(err, jc.ErrorIsNil)
// Call the Deployer facade's WatchUnits for machine-0.
var results params.StringsWatchResults
args := params.Entities{Entities: []params.Entity{{Tag: s.rawMachine.Tag().String()}}}
err = s.stateAPI.APICall("Deployer", s.stateAPI.BestFacadeVersion("Deployer"), "", "WatchUnits", args, &results)
c.Assert(err, jc.ErrorIsNil)
c.Assert(results.Results, gc.HasLen, 1)
result := results.Results[0]
c.Assert(result.Error, gc.IsNil)
// Start a StringsWatcher and check the initial event.
w := watcher.NewStringsWatcher(s.stateAPI, result)
wc := watchertest.NewStringsWatcherC(c, w, s.BackingState.StartSync)
defer wc.AssertStops()
wc.AssertChange("mysql/0", "logging/0")
wc.AssertNoChange()
// Now, without reading any changes advance the lifecycle of both
// units, inducing an update server-side after each two changes to
// ensure they're reported as separate events over the API.
err = subordinate.EnsureDead()
c.Assert(err, jc.ErrorIsNil)
s.BackingState.StartSync()
err = subordinate.Remove()
c.Assert(err, jc.ErrorIsNil)
err = principal.EnsureDead()
c.Assert(err, jc.ErrorIsNil)
s.BackingState.StartSync()
// Expect these changes as 2 separate events, so that
// nothing gets lost.
wc.AssertChange("logging/0")
wc.AssertChange("mysql/0")
wc.AssertNoChange()
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:55,代码来源:watcher_test.go
示例7: TestWatchOpenedPorts
func (s *stateSuite) TestWatchOpenedPorts(c *gc.C) {
// Open some ports.
err := s.units[0].OpenPorts("tcp", 1234, 1400)
c.Assert(err, jc.ErrorIsNil)
err = s.units[2].OpenPort("udp", 4321)
c.Assert(err, jc.ErrorIsNil)
w, err := s.firewaller.WatchOpenedPorts()
c.Assert(err, jc.ErrorIsNil)
wc := watchertest.NewStringsWatcherC(c, w, s.BackingState.StartSync)
defer wc.AssertStops()
expectChanges := []string{
"0:juju-public",
"2:juju-public",
}
wc.AssertChangeInSingleEvent(expectChanges...)
wc.AssertNoChange()
// Close a port, make sure it's detected.
err = s.units[2].ClosePort("udp", 4321)
c.Assert(err, jc.ErrorIsNil)
wc.AssertChange(expectChanges[1])
wc.AssertNoChange()
// Close it again, no changes.
err = s.units[2].ClosePort("udp", 4321)
c.Assert(err, jc.ErrorIsNil)
wc.AssertNoChange()
// Close non-existing port, no changes.
err = s.units[0].ClosePort("udp", 1234)
c.Assert(err, jc.ErrorIsNil)
wc.AssertNoChange()
// Open another port range, ensure it's detected.
err = s.units[1].OpenPorts("tcp", 8080, 8088)
c.Assert(err, jc.ErrorIsNil)
wc.AssertChange("1:juju-public")
wc.AssertNoChange()
}
开发者ID:felicianotech,项目名称:juju,代码行数:42,代码来源:state_test.go
示例8: TestStringsWatcherStopsWithPendingSend
func (s *watcherSuite) TestStringsWatcherStopsWithPendingSend(c *gc.C) {
// Call the Deployer facade's WatchUnits for machine-0.
var results params.StringsWatchResults
args := params.Entities{Entities: []params.Entity{{Tag: s.rawMachine.Tag().String()}}}
err := s.stateAPI.APICall("Deployer", s.stateAPI.BestFacadeVersion("Deployer"), "", "WatchUnits", args, &results)
c.Assert(err, jc.ErrorIsNil)
c.Assert(results.Results, gc.HasLen, 1)
result := results.Results[0]
c.Assert(result.Error, gc.IsNil)
// Start a StringsWatcher and check the initial event.
w := watcher.NewStringsWatcher(s.stateAPI, result)
wc := watchertest.NewStringsWatcherC(c, w, s.BackingState.StartSync)
defer wc.AssertStops()
// Create a service, deploy a unit of it on the machine.
mysql := s.AddTestingService(c, "mysql", s.AddTestingCharm(c, "mysql"))
principal, err := mysql.AddUnit()
c.Assert(err, jc.ErrorIsNil)
err = principal.AssignToMachine(s.rawMachine)
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:22,代码来源:watcher_test.go
示例9: TestWatchContainers
func (s *provisionerSuite) TestWatchContainers(c *gc.C) {
apiMachine, err := s.provisioner.Machine(s.machine.Tag().(names.MachineTag))
c.Assert(err, jc.ErrorIsNil)
// Add one LXC container.
template := state.MachineTemplate{
Series: "quantal",
Jobs: []state.MachineJob{state.JobHostUnits},
}
container, err := s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXC)
c.Assert(err, jc.ErrorIsNil)
w, err := apiMachine.WatchContainers(instance.LXC)
c.Assert(err, jc.ErrorIsNil)
wc := watchertest.NewStringsWatcherC(c, w, s.BackingState.StartSync)
defer wc.AssertStops()
// Initial event.
wc.AssertChange(container.Id())
// Change something other than the containers and make sure it's
// not detected.
err = apiMachine.SetStatus(status.StatusStarted, "not really", nil)
c.Assert(err, jc.ErrorIsNil)
wc.AssertNoChange()
// Add a KVM container and make sure it's not detected.
container, err = s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.KVM)
c.Assert(err, jc.ErrorIsNil)
wc.AssertNoChange()
// Add another LXC container and make sure it's detected.
container, err = s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXC)
c.Assert(err, jc.ErrorIsNil)
wc.AssertChange(container.Id())
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:36,代码来源:provisioner_test.go
注:本文中的github.com/juju/juju/watcher/watchertest.NewStringsWatcherC函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论