-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fallback to reference configuration when the application config fails…
… to load, related to #564
- Loading branch information
Showing
2 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
kamon-core-tests/src/test/scala/kamon/InitialConfigLoadingSpec.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,51 @@ | ||
package kamon | ||
|
||
import java.io._ | ||
import java.util.concurrent.TimeUnit | ||
|
||
import org.scalatest.{Matchers, WordSpec} | ||
import org.scalatest.concurrent.Eventually | ||
import org.scalatest.time.SpanSugar._ | ||
|
||
import scala.util.{Failure, Success, Try} | ||
|
||
class InitialConfigLoadingSpec extends WordSpec with Matchers with Eventually { | ||
|
||
"the initial config loading" should { | ||
"fallback to using reference configuration only when application.conf files are malformed" in { | ||
val process = Runtime.getRuntime.exec(createProcessWithConfig("kamon.KamonWithCustomConfig", "{This is a bad config}")) | ||
val processOutputReader = new BufferedReader(new InputStreamReader(process.getInputStream())) | ||
|
||
eventually(timeout(10 seconds)) { | ||
val outputLine = processOutputReader.readLine() | ||
outputLine shouldBe "All Good" | ||
} | ||
|
||
if(process.isAlive) { | ||
process.destroyForcibly().waitFor(5, TimeUnit.SECONDS) | ||
} | ||
} | ||
} | ||
|
||
def createProcessWithConfig(mainClass: String, configContent: String): String = { | ||
val tempConfigFile = File.createTempFile("bad-config", ".conf") | ||
val writer = new BufferedWriter(new FileWriter(tempConfigFile)) | ||
writer.write(configContent) | ||
writer.flush() | ||
writer.close() | ||
|
||
val configOptions = "-Dconfig.trace=loads -Dconfig.file=" + tempConfigFile.getAbsolutePath() | ||
System.getProperty("java.home") + File.separator + "bin" + File.separator + "java " + configOptions + | ||
" -cp " + System.getProperty("java.class.path") + " " + mainClass | ||
} | ||
} | ||
|
||
object KamonWithCustomConfig extends App { | ||
Try { | ||
Kamon.counter("test").increment() | ||
} match { | ||
case Success(_) => println("All Good") | ||
case Failure(_) => println("All Bad") | ||
} | ||
|
||
} |
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