本文整理匯總了Golang中bosh/mbus/fakes.FakeHandler.Func方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeHandler.Func方法的具體用法?Golang FakeHandler.Func怎麽用?Golang FakeHandler.Func使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bosh/mbus/fakes.FakeHandler
的用法示例。
在下文中一共展示了FakeHandler.Func方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: init
func init() {
Describe("dummyNatsJobSupervisor", func() {
var (
dummyNats JobSupervisor
handler *fakembus.FakeHandler
)
BeforeEach(func() {
handler = &fakembus.FakeHandler{}
dummyNats = NewDummyNatsJobSupervisor(handler)
})
Describe("MonitorJobFailures", func() {
It("monitors job status", func() {
dummyNats.MonitorJobFailures(func(boshalert.MonitAlert) error { return nil })
Expect(handler.ReceivedRun).To(BeTrue())
})
})
Describe("Status", func() {
BeforeEach(func() {
dummyNats.MonitorJobFailures(func(boshalert.MonitAlert) error { return nil })
})
It("returns the received status", func() {
statusMessage := boshhandler.NewRequest("", "set_dummy_status", []byte(`{"status":"failing"}`))
handler.Func(statusMessage)
Expect(dummyNats.Status()).To(Equal("failing"))
})
It("returns running as a default value", func() {
Expect(dummyNats.Status()).To(Equal("running"))
})
It("does not change the status given other messages", func() {
statusMessage := boshhandler.NewRequest("", "some_other_message", []byte(`{"status":"failing"}`))
handler.Func(statusMessage)
Expect(dummyNats.Status()).To(Equal("running"))
})
})
})
}
示例2: init
func init() {
Describe("Agent", func() {
var (
agent Agent
logger boshlog.Logger
handler *fakembus.FakeHandler
platform *fakeplatform.FakePlatform
actionDispatcher *FakeActionDispatcher
alertBuilder *fakealert.FakeAlertBuilder
jobSupervisor *fakejobsuper.FakeJobSupervisor
specService *fakeas.FakeV1Service
)
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LEVEL_NONE)
handler = &fakembus.FakeHandler{}
platform = fakeplatform.NewFakePlatform()
actionDispatcher = &FakeActionDispatcher{}
alertBuilder = fakealert.NewFakeAlertBuilder()
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
specService = fakeas.NewFakeV1Service()
agent = New(logger, handler, platform, actionDispatcher, alertBuilder, jobSupervisor, specService, 5*time.Millisecond)
})
Describe("Run", func() {
It("sets the dispatcher as message handler", func() {
actionDispatcher.DispatchResp = boshhandler.NewValueResponse("pong")
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
Expect(handler.ReceivedRun).To(BeTrue())
req := boshhandler.NewRequest("fake-reply", "fake-action", []byte("fake-payload"))
resp := handler.Func(req)
Expect(req).To(Equal(actionDispatcher.DispatchReq))
Expect(actionDispatcher.DispatchResp).To(Equal(resp))
})
It("resumes persistent actions *before* dispatching new requests", func() {
resumedBefore := false
handler.RunFunc = func() {
resumedBefore = actionDispatcher.ResumedPreviouslyDispatchedTasks
}
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
Expect(resumedBefore).To(BeTrue())
})
Context("when heartbeats can be sent", func() {
BeforeEach(func() {
jobName := "fake-job"
jobIndex := 1
specService.Spec = boshas.V1ApplySpec{
JobSpec: boshas.JobSpec{Name: &jobName},
Index: &jobIndex,
}
jobSupervisor.StatusStatus = "fake-state"
platform.FakeVitalsService.GetVitals = boshvitals.Vitals{
Load: []string{"a", "b", "c"},
}
})
expectedJobName := "fake-job"
expectedJobIndex := 1
expectedHb := boshmbus.Heartbeat{
Job: &expectedJobName,
Index: &expectedJobIndex,
JobState: "fake-state",
Vitals: boshvitals.Vitals{Load: []string{"a", "b", "c"}},
}
It("sends initial heartbeat", func() {
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
Expect(handler.InitialHeartbeatSent).To(BeTrue())
Expect(handler.TickHeartbeatsSent).To(BeFalse())
Expect(handler.SendToHealthManagerTopic).To(Equal("heartbeat"))
Expect(handler.SendToHealthManagerPayload.(boshmbus.Heartbeat)).To(Equal(expectedHb))
})
It("sends periodic heartbeats", func() {
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
Expect(handler.TickHeartbeatsSent).To(BeFalse())
time.Sleep(5 * time.Millisecond)
Expect(handler.TickHeartbeatsSent).To(BeTrue())
Expect(handler.SendToHealthManagerTopic).To(Equal("heartbeat"))
Expect(handler.SendToHealthManagerPayload.(boshmbus.Heartbeat)).To(Equal(expectedHb))
})
})
//.........這裏部分代碼省略.........