import ( "github.com/cloudfoundry/sonde-go/events" "tools/benchmark/messagegenerator" "tools/legacymetronbenchmark/legacyreader" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "tools/benchmark/metricsreporter" ) var _ = Describe("LegacyReader", func() { Context("Read", func() { var ( receivedCounter *metricsreporter.Counter internalMetricsCounter *metricsreporter.Counter reader fakeReader 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()
"tools/benchmark/messagegenerator" "github.com/cloudfoundry/sonde-go/events" "tools/benchmark/metricsreporter" "tools/metronbenchmark/valuemetricreader" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("ValueMetricReader", func() { Context("Read", func() { var ( receivedCounter *metricsreporter.Counter 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))
reporter.ReceivedCounter().IncrementValue() Eventually(reporter.NumTicks, "20ms", "1ms").Should(BeEquivalentTo(1)) rate := reporter.Rate() duration := reporter.Duration() reporter.Stop() Expect(reporter.NumTicks()).To(BeEquivalentTo(1), "The reporter is writing too quickly") Eventually(buffer).Should(gbytes.Say(fmt.Sprintf("%s, 1, 1, %.2f/s, 0.00%%", duration, rate))) }) }) Context("with additional counters", func() { var ( counter1 *metricsreporter.Counter counter2 *metricsreporter.Counter ) 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()
package messagewriter_test import ( "tools/benchmark/messagewriter" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "tools/benchmark/metricsreporter" ) 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))
package metricsreporter_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "tools/benchmark/metricsreporter" ) 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)) })