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