aboutsummaryrefslogtreecommitdiff
path: root/kamon-core-tests/src/test/scala/kamon/KamonLifecycleSpec.scala
diff options
context:
space:
mode:
authorDiego Parra <diegolparra@gmail.com>2018-01-30 20:30:36 -0300
committerGitHub <noreply@github.com>2018-01-30 20:30:36 -0300
commit50e87dc33fc468628f04f6c18139cf2e6f466100 (patch)
tree21c9e11312634d9ad4e8669ab1813a0efce5ff15 /kamon-core-tests/src/test/scala/kamon/KamonLifecycleSpec.scala
parent8231d18493e33c44668e4e5a5d45034f155f64e8 (diff)
parent083c31cb0eb18dce4f2a46d52b3606a92128230b (diff)
downloadKamon-50e87dc33fc468628f04f6c18139cf2e6f466100.tar.gz
Kamon-50e87dc33fc468628f04f6c18139cf2e6f466100.tar.bz2
Kamon-50e87dc33fc468628f04f6c18139cf2e6f466100.zip
Merge pull request #508 from ivantopo/issue#502/allow-jvm-to-shutdown-when-no-reporters
turn all Kamon threads into daemon threads, except for reporters
Diffstat (limited to 'kamon-core-tests/src/test/scala/kamon/KamonLifecycleSpec.scala')
-rw-r--r--kamon-core-tests/src/test/scala/kamon/KamonLifecycleSpec.scala67
1 files changed, 67 insertions, 0 deletions
diff --git a/kamon-core-tests/src/test/scala/kamon/KamonLifecycleSpec.scala b/kamon-core-tests/src/test/scala/kamon/KamonLifecycleSpec.scala
new file mode 100644
index 00000000..b5d0425b
--- /dev/null
+++ b/kamon-core-tests/src/test/scala/kamon/KamonLifecycleSpec.scala
@@ -0,0 +1,67 @@
+package kamon
+
+import java.io.File
+import java.util.concurrent.TimeUnit
+
+import com.typesafe.config.Config
+import kamon.metric.PeriodSnapshot
+import kamon.trace.Span
+import org.scalatest.{Matchers, WordSpec}
+import org.scalatest.concurrent.Eventually
+import org.scalatest.time.SpanSugar._
+
+class KamonLifecycleSpec extends WordSpec with Matchers with Eventually{
+
+ "the Kamon lifecycle" should {
+ "keep the JVM running if reporters are running" in {
+ val process = Runtime.getRuntime.exec(createProcessCommand("kamon.KamonWithRunningReporter"))
+ Thread.sleep(5000)
+ process.isAlive shouldBe true
+ process.destroyForcibly().waitFor(5, TimeUnit.SECONDS)
+ }
+
+ "let the JVM stop after all reporters are stopped" in {
+ val process = Runtime.getRuntime.exec(createProcessCommand("kamon.KamonWithTemporaryReporter"))
+ Thread.sleep(2000)
+ process.isAlive shouldBe true
+
+ eventually(timeout(7 seconds)) {
+ process.isAlive shouldBe false
+ process.exitValue() shouldBe 0
+ }
+ }
+ }
+
+
+ def createProcessCommand(mainClass: String): String = {
+ System.getProperty("java.home") + File.separator + "bin" + File.separator + "java" +
+ " -cp " + System.getProperty("java.class.path") + " " + mainClass
+ }
+}
+
+class DummyMetricReporter extends MetricReporter {
+ override def start(): Unit = {}
+ override def stop(): Unit = {}
+ override def reconfigure(config: Config): Unit = {}
+ override def reportPeriodSnapshot(snapshot: PeriodSnapshot): Unit = {}
+}
+
+class DummySpanReporter extends SpanReporter {
+ override def start(): Unit = {}
+ override def stop(): Unit = {}
+ override def reconfigure(config: Config): Unit = {}
+ override def reportSpans(spans: Seq[Span.FinishedSpan]): Unit = {}
+}
+
+object KamonWithRunningReporter extends App {
+ Kamon.addReporter(new DummyMetricReporter())
+ Kamon.addReporter(new DummySpanReporter())
+}
+
+object KamonWithTemporaryReporter extends App {
+ Kamon.addReporter(new DummyMetricReporter())
+ Kamon.addReporter(new DummySpanReporter())
+
+ Thread.sleep(5000)
+ Kamon.stopAllReporters()
+}