diff options
Diffstat (limited to 'kamon-system-metrics/src/test/scala')
-rw-r--r-- | kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala b/kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala index 8c340b1c..b475a416 100644 --- a/kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala +++ b/kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala @@ -21,6 +21,7 @@ import com.typesafe.config.ConfigFactory import kamon.Kamon import kamon.metric.Subscriptions.TickMetricSnapshot import kamon.metrics.CPUMetrics.CPUMetricSnapshot +import kamon.metrics.ContextSwitchesMetrics.ContextSwitchesMetricsSnapshot import kamon.metrics.GCMetrics.GCMetricSnapshot import kamon.metrics.HeapMetrics.HeapMetricSnapshot import kamon.metrics.MemoryMetrics.MemoryMetricSnapshot @@ -100,6 +101,20 @@ class SystemMetricsSpec extends TestKitBase with WordSpecLike with Matchers { | significant-value-digits = 2 | } | } + | context-switches { + | per-process-voluntary { + | highest-trackable-value = 3600000000000 + | significant-value-digits = 2 + | } + | per-process-non-voluntary { + | highest-trackable-value = 3600000000000 + | significant-value-digits = 2 + | } + | global { + | highest-trackable-value = 3600000000000 + | significant-value-digits = 2 + | } + | } | network { | rx-bytes { | highest-trackable-value = 3600000000000 @@ -214,6 +229,17 @@ class SystemMetricsSpec extends TestKitBase with WordSpecLike with Matchers { } } + "the Kamon ContextSwitches Metrics" should { + "record Context Switches Global, Voluntary and Non Voluntary metrics" in new ContextSwitchesMetricsListenerFixture { + val metricsListener = subscribeToMetrics() + + val ContextSwitchesMetrics = expectContextSwitchesMetrics(metricsListener, 3 seconds) + ContextSwitchesMetrics.perProcessVoluntary.max should be > 0L + ContextSwitchesMetrics.perProcessNonVoluntary.max should be > 0L + ContextSwitchesMetrics.global.max should be > 0L + } + } + def expectCPUMetrics(listener: TestProbe, waitTime: FiniteDuration): CPUMetricSnapshot = { val tickSnapshot = within(waitTime) { listener.expectMsgType[TickMetricSnapshot] @@ -328,4 +354,23 @@ class SystemMetricsSpec extends TestKitBase with WordSpecLike with Matchers { metricsListener } } + + def expectContextSwitchesMetrics(listener: TestProbe, waitTime: FiniteDuration): ContextSwitchesMetricsSnapshot = { + val tickSnapshot = within(waitTime) { + listener.expectMsgType[TickMetricSnapshot] + } + val contextSwitchesMetricsOption = tickSnapshot.metrics.get(ContextSwitchesMetrics(SystemMetricsExtension.ContextSwitches)) + contextSwitchesMetricsOption should not be empty + contextSwitchesMetricsOption.get.asInstanceOf[ContextSwitchesMetricsSnapshot] + } + + trait ContextSwitchesMetricsListenerFixture { + def subscribeToMetrics(): TestProbe = { + val metricsListener = TestProbe() + Kamon(Metrics).subscribe(ContextSwitchesMetrics, "*", metricsListener.ref, permanently = true) + // Wait for one empty snapshot before proceeding to the test. + metricsListener.expectMsgType[TickMetricSnapshot] + metricsListener + } + } } |