當前位置: 首頁>>代碼示例>>Golang>>正文


Golang FakeEventEmitter.ReturnError方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/dropsonde/emitter/fake.FakeEventEmitter.ReturnError方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeEventEmitter.ReturnError方法的具體用法?Golang FakeEventEmitter.ReturnError怎麽用?Golang FakeEventEmitter.ReturnError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry/dropsonde/emitter/fake.FakeEventEmitter的用法示例。


在下文中一共展示了FakeEventEmitter.ReturnError方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Write

		Eventually(getMetricNames).Should(ContainElement("numGoRoutines"))
	})

	It("emits all memoryStats metrics", func() {
		perform()

		Eventually(getMetricNames).Should(ContainElement("memoryStats.numBytesAllocatedHeap"))
		Eventually(getMetricNames).Should(ContainElement("memoryStats.numBytesAllocatedStack"))
		Eventually(getMetricNames).Should(ContainElement("memoryStats.numBytesAllocated"))
		Eventually(getMetricNames).Should(ContainElement("memoryStats.numMallocs"))
		Eventually(getMetricNames).Should(ContainElement("memoryStats.numFrees"))
		Eventually(getMetricNames).Should(ContainElement("memoryStats.lastGCPauseTimeNS"))
	})

	It("logs an error if emitting fails", func() {
		fakeEventEmitter.ReturnError = errors.New("fake error")
		fakeLogWriter := &fakeLogWriter{make(chan []byte)}
		log.SetOutput(fakeLogWriter)
		perform()
		Eventually(fakeLogWriter.writeChan).Should(Receive(ContainSubstring("fake error")))
	})
})

type fakeLogWriter struct {
	writeChan chan []byte
}

func (w *fakeLogWriter) Write(p []byte) (int, error) {
	w.writeChan <- p
	return len(p), nil
}
開發者ID:davidwadden,項目名稱:lattice-release,代碼行數:31,代碼來源:runtime_stats_test.go

示例2:

		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")
		})

		Describe("SendAppLog", func() {
			It("sends an error when log messages cannot be emitted", func() {
				err := sender.SendAppLog("app-id", "custom-log-message", "App", "0")
				Expect(err).To(HaveOccurred())
			})

		})

		Describe("SendAppErrorLog", func() {
			It("sends an error when log error messages cannot be emitted", func() {
				err := sender.SendAppErrorLog("app-id", "custom-log-error-message", "App", "0")
				Expect(err).To(HaveOccurred())
			})
開發者ID:jungle0755,項目名稱:gorouter,代碼行數:31,代碼來源:log_sender_test.go

示例3:

		sender = metric_sender.NewMetricSender(emitter)
	})

	It("sends a metric to its emitter", func() {
		err := sender.SendValue("metric-name", 42, "answers")
		Expect(err).NotTo(HaveOccurred())

		Expect(emitter.Messages).To(HaveLen(1))
		metric := emitter.Messages[0].Event.(*events.ValueMetric)
		Expect(metric.GetName()).To(Equal("metric-name"))
		Expect(metric.GetValue()).To(BeNumerically("==", 42))
		Expect(metric.GetUnit()).To(Equal("answers"))
	})

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

		err := sender.SendValue("stuff", 12, "no answer")
		Expect(emitter.Messages).To(HaveLen(0))
		Expect(err.Error()).To(Equal("some error"))
	})

	It("sends an update counter event to its emitter", func() {
		err := sender.IncrementCounter("counter-strike")
		Expect(err).NotTo(HaveOccurred())

		Expect(emitter.Messages).To(HaveLen(1))
		counterEvent := emitter.Messages[0].Event.(*events.CounterEvent)
		Expect(counterEvent.GetName()).To(Equal("counter-strike"))

	})
開發者ID:johannespetzold,項目名稱:gorouter,代碼行數:31,代碼來源:metric_sender_test.go

示例4:

		sender = metric_sender.NewMetricSender(emitter)
	})

	It("sends a metric to its emitter", func() {
		err := sender.SendValue("metric-name", 42, "answers")
		Expect(err).NotTo(HaveOccurred())

		Expect(emitter.GetMessages()).To(HaveLen(1))
		metric := emitter.GetMessages()[0].Event.(*events.ValueMetric)
		Expect(metric.GetName()).To(Equal("metric-name"))
		Expect(metric.GetValue()).To(BeNumerically("==", 42))
		Expect(metric.GetUnit()).To(Equal("answers"))
	})

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

		err := sender.SendValue("stuff", 12, "no answer")
		Expect(emitter.GetMessages()).To(HaveLen(0))
		Expect(err.Error()).To(Equal("some error"))
	})

	It("sends an update counter event to its emitter", func() {
		err := sender.IncrementCounter("counter-strike")
		Expect(err).NotTo(HaveOccurred())

		Expect(emitter.GetMessages()).To(HaveLen(1))
		counterEvent := emitter.GetMessages()[0].Event.(*events.CounterEvent)
		Expect(counterEvent.GetName()).To(Equal("counter-strike"))
		Expect(counterEvent.GetDelta()).To(Equal(uint64(1)))
	})
開發者ID:trainchou,項目名稱:gorouter,代碼行數:31,代碼來源:metric_sender_test.go

示例5:

	)

	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,代碼行數:30,代碼來源:envelope_sender_test.go


注:本文中的github.com/cloudfoundry/dropsonde/emitter/fake.FakeEventEmitter.ReturnError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。