本文整理匯總了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")
})