コード例 #1
0
	"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)))
	})
})
コード例 #2
0
		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"))
	})