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


Golang DopplerForwarder.Write方法代码示例

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


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

示例1:

var _ = Describe("DopplerForwarder", func() {
	var (
		clientPool *mockClientPool
		logger     *gosteno.Logger
		forwarder  *dopplerforwarder.DopplerForwarder
	)

	BeforeEach(func() {
		clientPool = &mockClientPool{}
		logger = loggertesthelper.Logger()
		forwarder = dopplerforwarder.New(clientPool, logger)
	})

	It("sends messages to a random doppler", func() {
		message := []byte("Some message")
		forwarder.Write(message)

		Expect(clientPool.randomClient).ToNot(BeNil())

		data := clientPool.randomClient.data
		Expect(data).To(HaveLen(1))
		Expect(data[0]).To(Equal(message))
	})

	It("sends a metric for the number of sent messages", func() {
		sender := fake.NewFakeMetricSender()
		metrics.Initialize(sender, metricbatcher.New(sender, time.Millisecond*10))

		message := []byte("Some message")
		forwarder.Write(message)
开发者ID:pkdevbox,项目名称:loggregator,代码行数:30,代码来源:doppler_forwarder_test.go

示例2:

		}()
		envelope = &events.Envelope{
			Origin:     proto.String("fake-origin-1"),
			EventType:  events.Envelope_LogMessage.Enum(),
			LogMessage: factories.NewLogMessage(events.LogMessage_OUT, "message", "appid", "sourceType"),
		}
	})

	AfterEach(func() {
		forwarder.Stop()
		<-doneChan
	})

	Context("client selection", func() {
		It("selects a random client", func() {
			forwarder.Write(envelope)
			Eventually(func() int { return clientPool.RandomClientCallCount() }).Should(Equal(1))
		})

		Context("when selecting a client errors", func() {
			It("an error is logged and returns", func() {
				clientPool.RandomClientReturns(nil, errors.New("boom"))
				forwarder.Write(envelope)

				Eventually(loggertesthelper.TestLoggerSink.LogContents).Should(ContainSubstring("can't forward message"))
				Eventually(client.SchemeCallCount).Should(Equal(0))
			})
		})
	})

	Context("udp client", func() {
开发者ID:hpcloud,项目名称:loggregator-1,代码行数:31,代码来源:doppler_forwarder_test.go

示例3:

		close(clientPool.RandomClientOutput.Err)

		logger = loggertesthelper.Logger()
		loggertesthelper.TestLoggerSink.Clear()

		fakeWrapper = newMockNetworkWrapper()
	})

	JustBeforeEach(func() {
		forwarder = dopplerforwarder.New(fakeWrapper, clientPool, logger)
	})

	Context("client selection", func() {
		It("selects a random client", func() {
			close(fakeWrapper.WriteOutput.Ret0)
			_, err := forwarder.Write(message)
			Expect(err).ToNot(HaveOccurred())
			Eventually(fakeWrapper.WriteInput.Client).Should(Receive(Equal(client)))
			Eventually(fakeWrapper.WriteInput.Message).Should(Receive(Equal(message)))
		})

		It("passes any chainers to the wrapper", func() {
			chainers := []metricbatcher.BatchCounterChainer{
				newMockBatchCounterChainer(),
				newMockBatchCounterChainer(),
			}
			close(fakeWrapper.WriteOutput.Ret0)
			_, err := forwarder.Write(message, chainers...)
			Expect(err).ToNot(HaveOccurred())
			Eventually(fakeWrapper.WriteInput).Should(BeCalled(
				With(client, message, chainers),
开发者ID:kei-yamazaki,项目名称:loggregator,代码行数:31,代码来源:doppler_forwarder_test.go

示例4:

		close(clientPool.RandomClientOutput.err)

		logger = loggertesthelper.Logger()
		loggertesthelper.TestLoggerSink.Clear()

		fakeWrapper = newMockNetworkWrapper()
	})

	JustBeforeEach(func() {
		forwarder = dopplerforwarder.New(fakeWrapper, clientPool, logger)
	})

	Context("client selection", func() {
		It("selects a random client", func() {
			close(fakeWrapper.WriteOutput.ret0)
			_, err := forwarder.Write(message)
			Expect(err).ToNot(HaveOccurred())
			Eventually(fakeWrapper.WriteInput.client).Should(Receive(Equal(client)))
			Eventually(fakeWrapper.WriteInput.message).Should(Receive(Equal(message)))
		})

		Context("when selecting a client errors", func() {
			It("logs an error and returns", func() {
				close(fakeWrapper.WriteOutput.ret0)
				clientPool.RandomClientOutput.err = make(chan error, 1)
				clientPool.RandomClientOutput.err <- errors.New("boom")
				_, err := forwarder.Write(message)
				Expect(err).To(HaveOccurred())
				Eventually(loggertesthelper.TestLoggerSink.LogContents).Should(ContainSubstring("failed to pick a client"))
				Consistently(fakeWrapper.WriteCalled).ShouldNot(Receive())
			})
开发者ID:yingkitw,项目名称:loggregator,代码行数:31,代码来源:doppler_forwarder_test.go


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