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


Golang NetworkReader.Start方法代码示例

本文整理汇总了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)
开发者ID:rakutentech,项目名称:loggregator,代码行数:30,代码来源:network_reader_test.go

示例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"
开发者ID:jvshahid,项目名称:loggregator,代码行数:31,代码来源:network_reader_test.go

示例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))
		})
	})
})
开发者ID:kei-yamazaki,项目名称:loggregator,代码行数:29,代码来源:fd_monitor_linux_test.go


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