From d23360425cf41fd5d6a6ab6d6507d3e97bb536e1 Mon Sep 17 00:00:00 2001 From: Ivan Topolnjak Date: Tue, 8 Apr 2014 02:25:47 -0300 Subject: = statsd: correctly send multiple packets for a single metric --- .../scala/kamon/statsd/StatsDMetricSenderSpec.scala | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'kamon-statsd/src/test') diff --git a/kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala b/kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala index caeaee28..94af4645 100644 --- a/kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala +++ b/kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala @@ -25,6 +25,7 @@ import org.HdrHistogram.HdrRecorder import kamon.metrics.Subscriptions.TickMetricSnapshot import java.lang.management.ManagementFactory import com.typesafe.config.ConfigFactory +import kamon.Kamon class StatsDMetricSenderSpec extends TestKitBase with WordSpecLike with Matchers { @@ -76,6 +77,26 @@ class StatsDMetricSenderSpec extends TestKitBase with WordSpecLike with Matchers data.utf8String should be(s"$testMetricKey:10|ms|@0.5") } + "flush the packet when the max-packet-size is reached" in new UdpListenerFixture { + val testMetricName = "test-metric" + val testMetricKey = buildMetricKey(testMetricName) + val testRecorder = HdrRecorder(1000L, 3, Scale.Unit) + + var bytes = testMetricKey.length + var level = 0 + while(bytes <= Kamon(StatsD).maxPacketSize) { + level += 1 + testRecorder.record(level) + bytes += s":$level|ms".length + } + + val udp = setup(Map(testMetricName -> testRecorder.collect())) + udp.expectMsgType[Udp.Send] // let the first flush pass + val Udp.Send(data, _, _) = udp.expectMsgType[Udp.Send] + + data.utf8String should be(s"$testMetricKey:$level|ms") + } + "render multiple keys in the same packet using newline as separator" in new UdpListenerFixture { val firstTestMetricName = "first-test-metric" -- cgit v1.2.3