当前位置: 首页>>代码示例>>Golang>>正文


Golang FakeEventEmitter.GetEnvelopes方法代码示例

本文整理汇总了Golang中github.com/cloudfoundry/dropsonde/emitter/fake.FakeEventEmitter.GetEnvelopes方法的典型用法代码示例。如果您正苦于以下问题:Golang FakeEventEmitter.GetEnvelopes方法的具体用法?Golang FakeEventEmitter.GetEnvelopes怎么用?Golang FakeEventEmitter.GetEnvelopes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cloudfoundry/dropsonde/emitter/fake.FakeEventEmitter的用法示例。


在下文中一共展示了FakeEventEmitter.GetEnvelopes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1:

	"github.com/cloudfoundry/dropsonde/envelopes"
	"github.com/gogo/protobuf/proto"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("ValueMetricSender", func() {
	var (
		fakeEventEmitter *fake.FakeEventEmitter
	)
	BeforeEach(func() {
		fakeEventEmitter = fake.NewFakeEventEmitter("MonitorTest")
		envelopes.Initialize(envelope_sender.NewEnvelopeSender(fakeEventEmitter))
	})

	AfterEach(func() {
		fakeEventEmitter.Close()
	})

	It("emits bosh metrics", func() {
		valueMetricSender := valuemetricsender.NewValueMetricSender()
		timeInSeconds := time.Now().Unix()
		valueMetricSender.SendValueMetric("some-deployment", "some-job", "some-index", "some-event-name", timeInSeconds, 1.23, "some-unit")

		Eventually(fakeEventEmitter.GetEnvelopes()).Should(HaveLen(1))
		Expect(fakeEventEmitter.GetEnvelopes()[0].Origin).Should(Equal(proto.String(valuemetricsender.ForwarderOrigin)))
		Expect(fakeEventEmitter.GetEnvelopes()[0].ValueMetric).ShouldNot(BeNil())
		Expect(fakeEventEmitter.GetEnvelopes()[0].Timestamp).ShouldNot(Equal(timeInSeconds * int64(time.Second)))
	})
})
开发者ID:kei-yamazaki,项目名称:loggregator,代码行数:30,代码来源:value_metric_sender_test.go

示例2:

		emitter   *fake.FakeEventEmitter
		sender    envelope_sender.EnvelopeSender
		envOrigin string
	)

	BeforeEach(func() {
		envOrigin = "original-origin"
		emitter = fake.NewFakeEventEmitter("origin")
		sender = envelope_sender.NewEnvelopeSender(emitter)
	})

	It("sends an Envelope to its emitter", func() {
		err := sender.SendEnvelope(createTestEnvelope(envOrigin))
		Expect(err).NotTo(HaveOccurred())

		Expect(emitter.GetEnvelopes()).To(HaveLen(1))
		envelope := emitter.GetEnvelopes()[0]
		metric := envelope.ValueMetric
		Expect(metric.GetName()).To(Equal("metric-name"))
		Expect(metric.GetValue()).To(BeNumerically("==", 42))
		Expect(metric.GetUnit()).To(Equal("answers"))
		Expect(envelope.Origin).To(Equal(proto.String(envOrigin)))
	})

	It("returns an error if it can't send metric value", func() {
		emitter.ReturnError = errors.New("some error")

		err := sender.SendEnvelope(createTestEnvelope(envOrigin))
		Expect(emitter.GetMessages()).To(HaveLen(0))
		Expect(err.Error()).To(Equal("some error"))
	})
开发者ID:fraenkel,项目名称:dropsonde,代码行数:31,代码来源:envelope_sender_test.go


注:本文中的github.com/cloudfoundry/dropsonde/emitter/fake.FakeEventEmitter.GetEnvelopes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。