當前位置: 首頁>>代碼示例>>Golang>>正文


Golang FakeHandler.HMRequests方法代碼示例

本文整理匯總了Golang中bosh/mbus/fakes.FakeHandler.HMRequests方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeHandler.HMRequests方法的具體用法?Golang FakeHandler.HMRequests怎麽用?Golang FakeHandler.HMRequests使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bosh/mbus/fakes.FakeHandler的用法示例。


在下文中一共展示了FakeHandler.HMRequests方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: init

func init() {
	Describe("Agent", func() {
		var (
			agent            Agent
			logger           boshlog.Logger
			handler          *fakembus.FakeHandler
			platform         *fakeplatform.FakePlatform
			actionDispatcher *FakeActionDispatcher
			alertBuilder     *fakealert.FakeAlertBuilder
			alertSender      AlertSender
			jobSupervisor    *fakejobsuper.FakeJobSupervisor
			specService      *fakeas.FakeV1Service
		)

		BeforeEach(func() {
			logger = boshlog.NewLogger(boshlog.LevelDebug)
			handler = &fakembus.FakeHandler{}
			platform = fakeplatform.NewFakePlatform()
			actionDispatcher = &FakeActionDispatcher{}
			alertBuilder = fakealert.NewFakeAlertBuilder()
			alertSender = NewAlertSender(handler, alertBuilder)
			jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
			specService = fakeas.NewFakeV1Service()
			agent = New(logger, handler, platform, actionDispatcher, alertSender, jobSupervisor, specService, 5*time.Millisecond)
		})

		Describe("Run", func() {
			It("lets dispatcher handle requests arriving via handler", func() {
				err := agent.Run()
				Expect(err).ToNot(HaveOccurred())

				expectedResp := boshhandler.NewValueResponse("pong")
				actionDispatcher.DispatchResp = expectedResp

				req := boshhandler.NewRequest("fake-reply", "fake-action", []byte("fake-payload"))
				resp := handler.RunFunc(req)

				Expect(actionDispatcher.DispatchReq).To(Equal(req))
				Expect(resp).To(Equal(expectedResp))
			})

			It("resumes persistent actions *before* dispatching new requests", func() {
				resumedBeforeStartingToDispatch := false
				handler.RunCallBack = func() {
					resumedBeforeStartingToDispatch = actionDispatcher.ResumedPreviouslyDispatchedTasks
				}

				err := agent.Run()
				Expect(err).ToNot(HaveOccurred())
				Expect(resumedBeforeStartingToDispatch).To(BeTrue())
			})

			Context("when heartbeats can be sent", func() {
				BeforeEach(func() {
					handler.KeepOnRunning()
				})

				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() {
					// Configure periodic heartbeat every 5 hours
					// so that we are sure that we will not receive it
					agent = New(logger, handler, platform, actionDispatcher, alertSender, jobSupervisor, specService, 5*time.Hour)

					// Immediately exit after sending initial heartbeat
					handler.SendToHealthManagerErr = errors.New("stop")

					err := agent.Run()
					Expect(err).To(HaveOccurred())
					Expect(err.Error()).To(ContainSubstring("stop"))

					Expect(handler.HMRequests()).To(Equal([]fakembus.HMRequest{
						fakembus.HMRequest{Topic: "heartbeat", Payload: expectedHb},
					}))
				})

				It("sends periodic heartbeats", func() {
					sentRequests := 0
//.........這裏部分代碼省略.........
開發者ID:Jane4PKU,項目名稱:bosh,代碼行數:101,代碼來源:agent_test.go

示例2:

var _ = Describe("concreteNotifier", func() {
	Describe("NotifyShutdown", func() {
		var (
			handler  *fakembus.FakeHandler
			notifier Notifier
		)

		BeforeEach(func() {
			handler = fakembus.NewFakeHandler()
			notifier = NewNotifier(handler)
		})

		It("sends shutdown message to health manager", func() {
			err := notifier.NotifyShutdown()
			Expect(err).ToNot(HaveOccurred())

			Expect(handler.HMRequests()).To(Equal([]fakembus.HMRequest{
				fakembus.HMRequest{Topic: "shutdown", Payload: nil},
			}))
		})

		It("returns error if sending shutdown message fails", func() {
			handler.SendToHealthManagerErr = errors.New("fake-send-error")

			err := notifier.NotifyShutdown()
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-send-error"))
		})
	})
})
開發者ID:amulyas,項目名稱:bosh-cloudstack-cpi,代碼行數:30,代碼來源:concrete_notifier_test.go

示例3:

		alertSender = NewConcreteAlertSender(handler, alertBuilder, uuidGenerator, timeService)
	})

	Describe("SendAlert", func() {
		monitAlert := boshalert.MonitAlert{ID: "fake-monit-alert"}

		It("sends monit alerts to health manager", func() {
			builtAlert := boshalert.Alert{ID: "fake-built-alert"}
			alertBuilder.BuildAlert = builtAlert

			err := alertSender.SendAlert(monitAlert)
			Expect(err).ToNot(HaveOccurred())

			Expect(alertBuilder.BuildInput).To(Equal(monitAlert))

			Expect(handler.HMRequests()).To(Equal([]fakembus.HMRequest{
				fakembus.HMRequest{Topic: "alert", Payload: builtAlert},
			}))
		})

		It("does not send monit alerts with severity=ignored to health manager", func() {
			builtAlert := boshalert.Alert{Severity: boshalert.SeverityIgnored}
			alertBuilder.BuildAlert = builtAlert

			err := alertSender.SendAlert(monitAlert)
			Expect(err).ToNot(HaveOccurred())

			Expect(alertBuilder.BuildInput).To(Equal(monitAlert))

			Expect(handler.HMRequests()).To(Equal([]fakembus.HMRequest{}))
		})
開發者ID:amulyas,項目名稱:bosh-cloudstack-cpi,代碼行數:31,代碼來源:concrete_alert_sender_test.go


注:本文中的bosh/mbus/fakes.FakeHandler.HMRequests方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。