forked from kamon-io/Kamon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
turn all Kamon threads into daemon threads, except for reporters, fixes
- Loading branch information
Showing
5 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
kamon-core-tests/src/test/scala/kamon/KamonLifecycleSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters