diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2014-10-25 04:45:21 +0200 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2014-10-25 04:46:59 +0200 |
commit | 096b35f93a0bafb3b0b6932d75e8d5f087cd4b2e (patch) | |
tree | 156f73c7b2145b21930d52275e47cb8b674bb27a /kamon-core/src/test | |
parent | 30940181424be69e0fd64e945fe5a64b4523457b (diff) | |
download | Kamon-096b35f93a0bafb3b0b6932d75e8d5f087cd4b2e.tar.gz Kamon-096b35f93a0bafb3b0b6932d75e8d5f087cd4b2e.tar.bz2 Kamon-096b35f93a0bafb3b0b6932d75e8d5f087cd4b2e.zip |
! core: replace Option[TraceContext] by empty object pattern and implement basic segments with renaming.
Diffstat (limited to 'kamon-core/src/test')
4 files changed, 26 insertions, 26 deletions
diff --git a/kamon-core/src/test/scala/kamon/instrumentation/akka/ActorSystemMessageInstrumentationSpec.scala b/kamon-core/src/test/scala/kamon/instrumentation/akka/ActorSystemMessageInstrumentationSpec.scala index cb39f5e6..d79ccbe0 100644 --- a/kamon-core/src/test/scala/kamon/instrumentation/akka/ActorSystemMessageInstrumentationSpec.scala +++ b/kamon-core/src/test/scala/kamon/instrumentation/akka/ActorSystemMessageInstrumentationSpec.scala @@ -3,7 +3,7 @@ package kamon.instrumentation.akka import akka.actor.SupervisorStrategy.{ Escalate, Restart, Resume, Stop } import akka.actor._ import akka.testkit.{ ImplicitSender, TestKit } -import kamon.trace.TraceRecorder +import kamon.trace.{ EmptyTraceContext, TraceRecorder } import org.scalatest.WordSpecLike import scala.concurrent.duration._ @@ -59,7 +59,7 @@ class ActorSystemMessageInstrumentationSpec extends TestKit(ActorSystem("actor-s // Ensure we didn't tie the actor with the context supervisor ! "context" - expectMsg(None) + expectMsg(EmptyTraceContext) } "the actor is restarted" in { @@ -76,7 +76,7 @@ class ActorSystemMessageInstrumentationSpec extends TestKit(ActorSystem("actor-s // Ensure we didn't tie the actor with the context supervisor ! "context" - expectMsg(None) + expectMsg(EmptyTraceContext) } "the actor is stopped" in { diff --git a/kamon-core/src/test/scala/kamon/instrumentation/akka/AskPatternInstrumentationSpec.scala b/kamon-core/src/test/scala/kamon/instrumentation/akka/AskPatternInstrumentationSpec.scala index d914ffe8..17312ba3 100644 --- a/kamon-core/src/test/scala/kamon/instrumentation/akka/AskPatternInstrumentationSpec.scala +++ b/kamon-core/src/test/scala/kamon/instrumentation/akka/AskPatternInstrumentationSpec.scala @@ -54,7 +54,6 @@ class AskPatternInstrumentationSpec extends TestKitBase with WordSpecLike with M } val capturedCtx = warn.asInstanceOf[TraceContextAware].traceContext - capturedCtx should be('defined) capturedCtx should equal(testTraceContext) } } diff --git a/kamon-core/src/test/scala/kamon/metric/TraceMetricsSpec.scala b/kamon-core/src/test/scala/kamon/metric/TraceMetricsSpec.scala index 8a87408d..6453dd77 100644 --- a/kamon-core/src/test/scala/kamon/metric/TraceMetricsSpec.scala +++ b/kamon-core/src/test/scala/kamon/metric/TraceMetricsSpec.scala @@ -5,8 +5,7 @@ import akka.testkit.{ ImplicitSender, TestKitBase } import com.typesafe.config.ConfigFactory import kamon.Kamon import kamon.metric.TraceMetrics.TraceMetricsSnapshot -import kamon.trace.TraceContext.SegmentIdentity -import kamon.trace.TraceRecorder +import kamon.trace.{ SegmentMetricIdentity, TraceRecorder } import org.scalatest.{ Matchers, WordSpecLike } class TraceMetricsSpec extends TestKitBase with WordSpecLike with Matchers with ImplicitSender { @@ -54,39 +53,37 @@ class TraceMetricsSpec extends TestKitBase with WordSpecLike with Matchers with "record the elapsed time for segments that occur inside a given trace" in { TraceRecorder.withNewTraceContext("trace-with-segments") { - val segmentHandle = TraceRecorder.startSegment(TraceMetricsTestSegment("test-segment")) - segmentHandle.get.finish() + val segment = TraceRecorder.currentContext.startSegment("test-segment", "test-label") + segment.finish() TraceRecorder.finish() } val snapshot = takeSnapshotOf("trace-with-segments") snapshot.elapsedTime.numberOfMeasurements should be(1) snapshot.segments.size should be(1) - snapshot.segments(TraceMetricsTestSegment("test-segment")).numberOfMeasurements should be(1) + snapshot.segments(SegmentMetricIdentity("test-segment", "test-label")).numberOfMeasurements should be(1) } "record the elapsed time for segments that finish after their correspondent trace has finished" in { - val segmentHandle = TraceRecorder.withNewTraceContext("closing-segment-after-trace") { - val sh = TraceRecorder.startSegment(TraceMetricsTestSegment("test-segment")) + val segment = TraceRecorder.withNewTraceContext("closing-segment-after-trace") { + val s = TraceRecorder.currentContext.startSegment("test-segment", "test-label") TraceRecorder.finish() - sh + s } val beforeFinishSegmentSnapshot = takeSnapshotOf("closing-segment-after-trace") beforeFinishSegmentSnapshot.elapsedTime.numberOfMeasurements should be(1) beforeFinishSegmentSnapshot.segments.size should be(0) - segmentHandle.get.finish() + segment.finish() val afterFinishSegmentSnapshot = takeSnapshotOf("closing-segment-after-trace") afterFinishSegmentSnapshot.elapsedTime.numberOfMeasurements should be(0) afterFinishSegmentSnapshot.segments.size should be(1) - afterFinishSegmentSnapshot.segments(TraceMetricsTestSegment("test-segment")).numberOfMeasurements should be(1) + afterFinishSegmentSnapshot.segments(SegmentMetricIdentity("test-segment", "test-label")).numberOfMeasurements should be(1) } } - case class TraceMetricsTestSegment(name: String) extends SegmentIdentity - def takeSnapshotOf(traceName: String): TraceMetricsSnapshot = { val recorder = Kamon(Metrics).register(TraceMetrics(traceName), TraceMetrics.Factory) val collectionContext = Kamon(Metrics).buildDefaultCollectionContext diff --git a/kamon-core/src/test/scala/kamon/trace/TraceContextManipulationSpec.scala b/kamon-core/src/test/scala/kamon/trace/TraceContextManipulationSpec.scala index 4d0049f1..e2031a72 100644 --- a/kamon-core/src/test/scala/kamon/trace/TraceContextManipulationSpec.scala +++ b/kamon-core/src/test/scala/kamon/trace/TraceContextManipulationSpec.scala @@ -3,7 +3,6 @@ package kamon.trace import akka.actor.ActorSystem import akka.testkit.{ ImplicitSender, TestKitBase } import com.typesafe.config.ConfigFactory -import kamon.trace.TraceContext.SegmentIdentity import org.scalatest.{ Matchers, WordSpecLike } class TraceContextManipulationSpec extends TestKitBase with WordSpecLike with Matchers with ImplicitSender { @@ -38,7 +37,7 @@ class TraceContextManipulationSpec extends TestKitBase with WordSpecLike with Ma "allow starting a trace within a specified block of code, and only within that block of code" in { val createdContext = TraceRecorder.withNewTraceContext("start-context") { TraceRecorder.currentContext should not be empty - TraceRecorder.currentContext.get + TraceRecorder.currentContext } TraceRecorder.currentContext shouldBe empty @@ -48,7 +47,7 @@ class TraceContextManipulationSpec extends TestKitBase with WordSpecLike with Ma "allow starting a trace within a specified block of code, providing a trace-token and only within that block of code" in { val createdContext = TraceRecorder.withNewTraceContext("start-context-with-token", Some("token-1")) { TraceRecorder.currentContext should not be empty - TraceRecorder.currentContext.get + TraceRecorder.currentContext } TraceRecorder.currentContext shouldBe empty @@ -70,7 +69,7 @@ class TraceContextManipulationSpec extends TestKitBase with WordSpecLike with Ma "allow renaming a trace" in { val createdContext = TraceRecorder.withNewTraceContext("trace-before-rename") { TraceRecorder.rename("renamed-trace") - TraceRecorder.currentContext.get + TraceRecorder.currentContext } TraceRecorder.currentContext shouldBe empty @@ -79,17 +78,22 @@ class TraceContextManipulationSpec extends TestKitBase with WordSpecLike with Ma "allow creating a segment within a trace" in { val createdContext = TraceRecorder.withNewTraceContext("trace-with-segments") { - val segmentHandle = TraceRecorder.startSegment(TraceManipulationTestSegment("segment-1")) - - TraceRecorder.currentContext.get + val segment = TraceRecorder.currentContext.startSegment("segment-1", "segment-1-label") + TraceRecorder.currentContext } TraceRecorder.currentContext shouldBe empty createdContext.name shouldBe ("trace-with-segments") - } - } - case class TraceManipulationTestSegment(name: String) extends SegmentIdentity + "allow renaming a segment" in { + TraceRecorder.withNewTraceContext("trace-with-renamed-segment") { + val segment = TraceRecorder.currentContext.startSegment("original-segment-name", "segment-label") + segment.name should be("original-segment-name") + segment.rename("new-segment-name") + segment.name should be("new-segment-name") + } + } + } } |