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


Golang NetworkReader.Emit方法代码示例

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


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

示例1:

	var readerStopped chan struct{}
	var writer mocks.MockByteArrayWriter
	var port int
	var address string

	BeforeEach(func() {
		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("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 func() {
				reader.Start()
				close(readerStopped)
			}()

			expectedLog := fmt.Sprintf("Listening on port %s", address)
			Eventually(loggertesthelper.TestLoggerSink.LogContents).Should(ContainSubstring(expectedLog))
开发者ID:andrew-edgar,项目名称:loggregator,代码行数:31,代码来源:network_reader_test.go

示例2:

		It("emits metrics related to data sent in on udp connection", func(done Done) {
			expectedData := "Some Data"
			otherData := "More stuff"
			connection, err := net.Dial("udp", "localhost:3456")
			dataByteCount := len(otherData + expectedData)

			_, err = connection.Write([]byte(expectedData))
			Expect(err).NotTo(HaveOccurred())

			_, err = connection.Write([]byte(otherData))
			Expect(err).NotTo(HaveOccurred())

			Eventually(writer.Data).Should(HaveLen(2))

			metrics := reader.Emit().Metrics
			Expect(metrics).To(HaveLen(2))
			for _, metric := range metrics {
				switch metric.Name {
				case "receivedMessageCount":
					Expect(metric.Value).To(Equal(uint64(2)))
				case "receivedByteCount":
					Expect(metric.Value).To(Equal(uint64(dataByteCount)))
				default:
					Fail(fmt.Sprintf("Got an invalid metric name: %s", metric.Name))
				}
			}
			close(done)
		}, 2)
	})
})
开发者ID:khj0651,项目名称:loggregator,代码行数:30,代码来源:network_reader_test.go


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