本文整理汇总了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)
示例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() {
示例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),
示例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())
})