本文整理汇总了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{
示例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")
})