From 02e18a1186f9b0dd9a7133ff30aa73774822db13 Mon Sep 17 00:00:00 2001 From: Tristan Sallé Date: Wed, 27 May 2015 10:14:11 +0200 Subject: + core: add a clock-sampler, fix ordered-sampler, add unit tests for samplers --- .../src/test/scala/kamon/trace/SamplerSpec.scala | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 kamon-core/src/test/scala/kamon/trace/SamplerSpec.scala (limited to 'kamon-core/src/test/scala/kamon/trace') diff --git a/kamon-core/src/test/scala/kamon/trace/SamplerSpec.scala b/kamon-core/src/test/scala/kamon/trace/SamplerSpec.scala new file mode 100644 index 00000000..88cdf116 --- /dev/null +++ b/kamon-core/src/test/scala/kamon/trace/SamplerSpec.scala @@ -0,0 +1,76 @@ +package kamon.trace + +import kamon.testkit.BaseKamonSpec +import kamon.util.NanoInterval + +class SamplerSpec extends BaseKamonSpec("sampler-spec") { + + "the Sampler" should { + "work as intended" when { + "using all mode" in { + val sampler = SampleAll + + sampler.shouldTrace should be(true) + + sampler.shouldReport(NanoInterval.default) should be(true) + } + + "using random mode" in { + val sampler = new RandomSampler(100) + + sampler.shouldTrace should be(true) + sampler.shouldTrace should be(true) + + sampler.shouldReport(NanoInterval.default) should be(true) + } + + "using ordered mode" in { + var sampler = new OrderedSampler(1) + + sampler.shouldTrace should be(true) + sampler.shouldTrace should be(true) + sampler.shouldTrace should be(true) + sampler.shouldTrace should be(true) + sampler.shouldTrace should be(true) + sampler.shouldTrace should be(true) + + sampler = new OrderedSampler(2) + + sampler.shouldTrace should be(false) + sampler.shouldTrace should be(true) + sampler.shouldTrace should be(false) + sampler.shouldTrace should be(true) + sampler.shouldTrace should be(false) + sampler.shouldTrace should be(true) + + sampler.shouldReport(NanoInterval.default) should be(true) + } + + "using threshold mode" in { + val sampler = new ThresholdSampler(new NanoInterval(10000000L)) + + sampler.shouldTrace should be(true) + + sampler.shouldReport(new NanoInterval(5000000L)) should be(false) + sampler.shouldReport(new NanoInterval(10000000L)) should be(true) + sampler.shouldReport(new NanoInterval(15000000L)) should be(true) + sampler.shouldReport(new NanoInterval(0L)) should be(false) + } + + "using clock mode" in { + val sampler = new ClockSampler(new NanoInterval(10000000L)) + + sampler.shouldTrace should be(true) + sampler.shouldTrace should be(false) + Thread.sleep(1L) + sampler.shouldTrace should be(false) + Thread.sleep(10L) + sampler.shouldTrace should be(true) + sampler.shouldTrace should be(false) + + sampler.shouldReport(NanoInterval.default) should be(true) + } + } + } + +} -- cgit v1.2.3