当前位置: 首页>>代码示例>>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;未经允许,请勿转载。