本文整理匯總了Golang中tools/benchmark/metricsreporter.Counter.GetValue方法的典型用法代碼示例。如果您正苦於以下問題:Golang Counter.GetValue方法的具體用法?Golang Counter.GetValue怎麽用?Golang Counter.GetValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tools/benchmark/metricsreporter.Counter
的用法示例。
在下文中一共展示了Counter.GetValue方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
legacyReader *legacyreader.LegacyReader
)
BeforeEach(func() {
receivedCounter = metricsreporter.NewCounter("received")
internalMetricsCounter = metricsreporter.NewCounter("internal metrics")
reader = fakeReader{}
legacyReader = legacyreader.NewLegacyReader(receivedCounter, internalMetricsCounter, &reader)
})
It("should report legacy log messages", func() {
reader.event = messagegenerator.BasicLogMessageEnvelope("legacy", "appID")
legacyReader.Read()
Expect(receivedCounter.GetValue()).To(BeEquivalentTo(1))
})
It("should report value metrics", func() {
reader.event = messagegenerator.BasicValueMetricEnvelope("test-origin")
legacyReader.Read()
Expect(receivedCounter.GetValue()).To(BeEquivalentTo(1))
})
It("should only count test log messages", func() {
reader.event = messagegenerator.BasicLogMessageEnvelope("non-test-origin", "appID")
legacyReader.Read()
示例2:
)
var _ = Describe("MessageWriter", func() {
var (
sentCounter *metricsreporter.Counter
)
BeforeEach(func() {
sentCounter = metricsreporter.NewCounter("sent")
})
It("should keep track of the total sent messages", func() {
msgWriter := messagewriter.NewMessageWriter("localhost", 51161, "", sentCounter)
message := []byte{}
msgWriter.Write(message)
msgWriter.Write(message)
msgWriter.Write(message)
msgWriter.Write(message)
msgWriter.Write(message)
msgWriter.Write(message)
msgWriter.Write(message)
msgWriter.Write(message)
Expect(sentCounter.GetValue()).To(BeEquivalentTo(8))
})
It("should not increment total sent messages", func() {
messagewriter.NewMessageWriter("localhost", 51161, "", sentCounter)
Expect(sentCounter.GetValue()).To(BeEquivalentTo(0))
})
})
示例3:
reader fakeReader
valueMetricReader *valuemetricreader.ValueMetricReader
)
BeforeEach(func() {
receivedCounter = metricsreporter.NewCounter("counter")
reader = fakeReader{}
valueMetricReader = valuemetricreader.NewValueMetricReader(receivedCounter, &reader)
})
It("should report value metrics", func() {
reader.event = messagegenerator.BasicValueMetricEnvelope(valuemetricreader.TestOrigin)
valueMetricReader.Read()
Expect(receivedCounter.GetValue()).To(BeEquivalentTo(1))
})
It("should not report log messages", func() {
reader.event = messagegenerator.BasicLogMessageEnvelope(valuemetricreader.TestOrigin, "appID")
valueMetricReader.Read()
Expect(receivedCounter.GetValue()).To(BeEquivalentTo(0))
})
It("should only report test value metrics", func() {
reader.event = messagegenerator.BasicValueMetricEnvelope("some-other-origin")
valueMetricReader.Read()
示例4:
var _ = Describe("Counter", func() {
var counter *metricsreporter.Counter
BeforeEach(func() {
counter = metricsreporter.NewCounter("counter")
})
Context("GetName", func() {
It("returns its name", func() {
Expect(counter.GetName()).To(Equal("counter"))
})
})
Context("GetValue", func() {
It("returns its current value", func() {
Expect(counter.GetValue()).To(BeEquivalentTo(0))
})
})
Context("GetTotal", func() {
It("returns its current total", func() {
Expect(counter.GetTotal()).To(BeEquivalentTo(0))
})
})
Context("IncrementValue", func() {
It("increments the value", func() {
counter.IncrementValue()
Expect(counter.GetValue()).To(BeEquivalentTo(1))
})
})