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


Golang FakeEventEmitter.GetEvents方法代碼示例

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


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

示例1:

	AfterEach(func() {
		close(stopChan)
		Eventually(runDone).Should(BeClosed())
	})

	var perform = func() {
		go func() {
			runtimeStats.Run(stopChan)
			close(runDone)
		}()
	}

	var getMetricNames = func() []string {
		var names []string
		for _, event := range fakeEventEmitter.GetEvents() {
			names = append(names, event.(*events.ValueMetric).GetName())
		}
		return names
	}

	It("periodically emits events", func() {
		perform()

		Eventually(func() int { return len(fakeEventEmitter.GetMessages()) }).Should(BeNumerically(">=", 2))
	})

	It("emits a NumCpu metric", func() {
		perform()

		Eventually(fakeEventEmitter.GetEvents).Should(ContainElement(&events.ValueMetric{
開發者ID:davidwadden,項目名稱:lattice-release,代碼行數:30,代碼來源:runtime_stats_test.go

示例2:

		})

		It("counts number of log messages read per app", func() {
			sender.SendAppErrorLog("app-id1", "custom-log-message", "App", "0")
			sender.SendAppErrorLog("app-id1", "custom-log-message", "App", "0")
			sender.SendAppErrorLog("app-id2", "custom-log-message", "App", "0")

			Eventually(emitter.GetEvents).Should(ContainElement(&events.ValueMetric{Name: proto.String("logSenderTotalMessagesRead.app-id1"), Value: proto.Float64(2), Unit: proto.String("count")}))
			Eventually(emitter.GetEvents).Should(ContainElement(&events.ValueMetric{Name: proto.String("logSenderTotalMessagesRead.app-id2"), Value: proto.Float64(1), Unit: proto.String("count")}))
		})
	})

	Describe("counter emission", func() {
		It("emits on a timer", func() {
			Eventually(emitter.GetEvents).Should(ContainElement(&events.ValueMetric{Name: proto.String("logSenderTotalMessagesRead"), Value: proto.Float64(0), Unit: proto.String("count")}))
			Eventually(func() int { return len(emitter.GetEvents()) }).Should(BeNumerically(">", 3))

			sender.SendAppLog("app-id", "custom-log-message", "App", "0")
			Eventually(emitter.GetEvents).Should(ContainElement(&events.ValueMetric{Name: proto.String("logSenderTotalMessagesRead"), Value: proto.Float64(1), Unit: proto.String("count")}))

			sender.SendAppLog("app-id", "custom-log-message", "App", "0")
			Eventually(emitter.GetEvents).Should(ContainElement(&events.ValueMetric{Name: proto.String("logSenderTotalMessagesRead"), Value: proto.Float64(2), Unit: proto.String("count")}))

		})
	})

	Context("when messages cannot be emitted", func() {
		BeforeEach(func() {
			emitter.ReturnError = errors.New("expected error")
		})
開發者ID:jungle0755,項目名稱:gorouter,代碼行數:30,代碼來源:log_sender_test.go


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