當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Counter.IncrementValue方法代碼示例

本文整理匯總了Golang中tools/benchmark/metricsreporter.Counter.IncrementValue方法的典型用法代碼示例。如果您正苦於以下問題:Golang Counter.IncrementValue方法的具體用法?Golang Counter.IncrementValue怎麽用?Golang Counter.IncrementValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tools/benchmark/metricsreporter.Counter的用法示例。


在下文中一共展示了Counter.IncrementValue方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1:

			BeforeEach(func() {
				counter1 = metricsreporter.NewCounter("counter1")
				counter2 = metricsreporter.NewCounter("counter2")
				counters = []*metricsreporter.Counter{counter1, counter2}
			})

			It("reports the column names", func() {
				Eventually(buffer).Should(gbytes.Say("Runtime, Sent, Received, Rate, PercentLoss, counter1, counter2"))
			})

			It("reports additional counter values", func() {
				reporter.ReceivedCounter().IncrementValue()
				reporter.SentCounter().IncrementValue()

				counter1.IncrementValue()
				counter2.IncrementValue()
				counter2.IncrementValue()

				Eventually(reporter.NumTicks, "20ms", "1ms").Should(BeEquivalentTo(1))
				Eventually(buffer, 10).Should(gbytes.Say(fmt.Sprintf("%s, 1, 1, %.2f/s, 0.00%%, 1, 2", reporter.Duration(), reporter.Rate())))
			})

			It("reports individual counter average", func() {
				reporter.SentCounter().IncrementValue()
				reporter.SentCounter().IncrementValue()
				reporter.ReceivedCounter().IncrementValue()

				counter1.IncrementValue()
				counter2.IncrementValue()
				counter2.IncrementValue()
開發者ID:kei-yamazaki,項目名稱:loggregator,代碼行數:30,代碼來源:metricsreporter_test.go

示例2:

	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))
		})
	})

	Context("Reset", func() {
		It("adds the current value to the total and resets the value to zero", func() {
			counter.IncrementValue()
			counter.IncrementValue()

			counter.Reset()

			Expect(counter.GetValue()).To(BeEquivalentTo(0))
			Expect(counter.GetTotal()).To(BeEquivalentTo(2))
		})
	})
開發者ID:lyuyun,項目名稱:loggregator,代碼行數:30,代碼來源:counter_test.go


注:本文中的tools/benchmark/metricsreporter.Counter.IncrementValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。