本文整理汇总了Golang中metron/networkreader.NetworkReader.Start方法的典型用法代码示例。如果您正苦于以下问题:Golang NetworkReader.Start方法的具体用法?Golang NetworkReader.Start怎么用?Golang NetworkReader.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类metron/networkreader.NetworkReader
的用法示例。
在下文中一共展示了NetworkReader.Start方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
writer = mocks.MockByteArrayWriter{}
reader = networkreader.New(address, "networkReader", &writer, loggertesthelper.Logger())
})
Context("without a running listener", func() {
It("Emit returns a context with the given name", func() {
context := reader.Emit()
Expect(context.Name).To(Equal("networkReader"))
})
})
Context("with a reader running", func() {
BeforeEach(func() {
loggertesthelper.TestLoggerSink.Clear()
go reader.Start()
expectedLog := fmt.Sprintf("Listening on port %s", address)
Eventually(loggertesthelper.TestLoggerSink.LogContents).Should(ContainSubstring(expectedLog))
})
AfterEach(func() {
reader.Stop()
})
It("sends data recieved on UDP socket to its writer", func() {
expectedData := "Some Data"
otherData := "More stuff"
connection, err := net.Dial("udp", address)
示例2:
port = 3456 + GinkgoParallelNode()
address = net.JoinHostPort("127.0.0.1", strconv.Itoa(port))
writer = mocks.MockByteArrayWriter{}
reader = networkreader.New(address, "networkReader", &writer, loggertesthelper.Logger())
readerStopped = make(chan struct{})
})
Context("with a reader running", func() {
BeforeEach(func() {
loggertesthelper.TestLoggerSink.Clear()
fakeMetricSender = fake.NewFakeMetricSender()
metricBatcher := metricbatcher.New(fakeMetricSender, time.Millisecond)
metrics.Initialize(fakeMetricSender, metricBatcher)
go func() {
reader.Start()
close(readerStopped)
}()
expectedLog := fmt.Sprintf("Listening on port %s", address)
Eventually(loggertesthelper.TestLoggerSink.LogContents).Should(ContainSubstring(expectedLog))
})
AfterEach(func() {
reader.Stop()
<-readerStopped
})
It("sends data recieved on UDP socket to its writer", func() {
expectedData := "Some Data"
otherData := "More stuff"
示例3:
var (
writer *fakeWriter
dropsondeReader *networkreader.NetworkReader
)
BeforeEach(func() {
logger := loggertesthelper.Logger()
writer = &fakeWriter{}
mockBatcher := newMockEventBatcher()
mockChainer := newMockBatchCounterChainer()
testhelpers.AlwaysReturn(mockBatcher.BatchCounterOutput, mockChainer)
testhelpers.AlwaysReturn(mockChainer.SetTagOutput, mockChainer)
var err error
dropsondeUnmarshaller := eventunmarshaller.New(writer, mockBatcher, logger)
dropsondeReader, err = networkreader.New("127.0.0.1:37474", "dropsondeAgentListener", dropsondeUnmarshaller, logger)
Expect(err).NotTo(HaveOccurred())
})
Context("LinuxFileDescriptor", func() {
It("sends open file descriptor metrics", func() {
defer dropsondeReader.Stop()
go dropsondeReader.Start()
Eventually(func() uint64 { return atomic.LoadUint64(&writer.openFileDescriptors) }, 3).Should(BeNumerically("~", 15, 3))
})
})
})