diff options
author | Tristan Sallé <tristan.salle@teads.tv> | 2015-05-27 10:14:11 +0200 |
---|---|---|
committer | Tristan Sallé <tristan.salle@teads.tv> | 2015-07-15 09:26:38 +0200 |
commit | 02e18a1186f9b0dd9a7133ff30aa73774822db13 (patch) | |
tree | fbcf49e57eb671c47357f1b8cb151f07d9fc0522 /kamon-core/src/test/scala | |
parent | dd9fec8b235b055b7a513ac74710618ba23532a5 (diff) | |
download | Kamon-02e18a1186f9b0dd9a7133ff30aa73774822db13.tar.gz Kamon-02e18a1186f9b0dd9a7133ff30aa73774822db13.tar.bz2 Kamon-02e18a1186f9b0dd9a7133ff30aa73774822db13.zip |
+ core: add a clock-sampler, fix ordered-sampler, add unit tests for samplers
Diffstat (limited to 'kamon-core/src/test/scala')
-rw-r--r-- | kamon-core/src/test/scala/kamon/trace/SamplerSpec.scala | 76 |
1 files changed, 76 insertions, 0 deletions
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) + } + } + } + +} |