diff options
Diffstat (limited to 'kamon-jdbc/src/test/scala/kamon/jdbc/instrumentation/StatementInstrumentationSpec.scala')
-rw-r--r-- | kamon-jdbc/src/test/scala/kamon/jdbc/instrumentation/StatementInstrumentationSpec.scala | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/kamon-jdbc/src/test/scala/kamon/jdbc/instrumentation/StatementInstrumentationSpec.scala b/kamon-jdbc/src/test/scala/kamon/jdbc/instrumentation/StatementInstrumentationSpec.scala index ee68234d..ffd5a867 100644 --- a/kamon-jdbc/src/test/scala/kamon/jdbc/instrumentation/StatementInstrumentationSpec.scala +++ b/kamon-jdbc/src/test/scala/kamon/jdbc/instrumentation/StatementInstrumentationSpec.scala @@ -15,10 +15,10 @@ package kamon.jdbc.instrumentation -import java.sql.{DriverManager, SQLException} +import java.sql.{ DriverManager, SQLException } import akka.actor.ActorSystem -import akka.testkit.{TestKitBase, TestProbe} +import akka.testkit.{ TestKitBase, TestProbe } import com.typesafe.config.ConfigFactory import kamon.Kamon import kamon.jdbc.SlowQueryProcessor @@ -27,7 +27,8 @@ import kamon.jdbc.metric.StatementsMetrics.StatementsMetricsSnapshot import kamon.metric.Metrics import kamon.metric.Subscriptions.TickMetricSnapshot import kamon.trace.TraceRecorder -import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike} +import org.scalatest.{ BeforeAndAfterAll, Matchers, WordSpecLike } + import scala.concurrent.duration._ class StatementInstrumentationSpec extends TestKitBase with WordSpecLike with Matchers with BeforeAndAfterAll { @@ -44,7 +45,7 @@ class StatementInstrumentationSpec extends TestKitBase with WordSpecLike with Ma |} """.stripMargin)) - val connection = DriverManager.getConnection("jdbc:h2:mem:jdbc-spec","SA", "") + val connection = DriverManager.getConnection("jdbc:h2:mem:jdbc-spec", "SA", "") override protected def beforeAll(): Unit = { connection should not be null @@ -59,12 +60,12 @@ class StatementInstrumentationSpec extends TestKitBase with WordSpecLike with Ma } "the StatementInstrumentation" should { - "record the execution time of the INSERT operation" in new StatementsMetricsListenerFixture { + "record the execution time of INSERT operation" in new StatementsMetricsListenerFixture { TraceRecorder.withNewTraceContext("jdbc-trace-insert") { val metricsListener = subscribeToMetrics() - for(id <- 1 to 100) { + for (id ← 1 to 100) { val insert = s"INSERT INTO Address (Nr, Name) VALUES($id, 'foo')" val insertStatement = connection.prepareStatement(insert) insertStatement.execute() @@ -80,7 +81,7 @@ class StatementInstrumentationSpec extends TestKitBase with WordSpecLike with Ma val metricsListener = subscribeToMetrics() - for(id <- 1 to 100) { + for (id ← 1 to 100) { val select = s"SELECT * FROM Address where Nr = $id" val selectStatement = connection.createStatement() selectStatement.execute(select) @@ -96,8 +97,8 @@ class StatementInstrumentationSpec extends TestKitBase with WordSpecLike with Ma val metricsListener = subscribeToMetrics() - for(id <- 1 to 100) { - val update = s"UPDATE Address SET Name = 'bar$id' where Nr = $id" + for (id ← 1 to 100) { + val update = s"UPDATE Address SET Name = 'bar$id' where Nr = $id" val updateStatement = connection.prepareStatement(update) updateStatement.execute() } @@ -108,12 +109,12 @@ class StatementInstrumentationSpec extends TestKitBase with WordSpecLike with Ma } "record the execution time of DELETE operation" in new StatementsMetricsListenerFixture { - TraceRecorder.withNewTraceContext("jdbc-trace-insert") { + TraceRecorder.withNewTraceContext("jdbc-trace-delete") { val metricsListener = subscribeToMetrics() - for(id <- 1 to 100) { - val delete = s"DELETE FROM Address where Nr = $id" + for (id ← 1 to 100) { + val delete = s"DELETE FROM Address where Nr = $id" val deleteStatement = connection.createStatement() deleteStatement.execute(delete) } @@ -128,7 +129,7 @@ class StatementInstrumentationSpec extends TestKitBase with WordSpecLike with Ma val metricsListener = subscribeToMetrics() - for(id <- 1 to 2) { + for (id ← 1 to 2) { val select = s"SELECT * FROM Address; CALL SLEEP(100)" val selectStatement = connection.createStatement() selectStatement.execute(select) @@ -139,14 +140,14 @@ class StatementInstrumentationSpec extends TestKitBase with WordSpecLike with Ma } } - "count the total ERRORS" in new StatementsMetricsListenerFixture { - TraceRecorder.withNewTraceContext("jdbc-trace-slow") { + "count all SQL ERRORS" in new StatementsMetricsListenerFixture { + TraceRecorder.withNewTraceContext("jdbc-trace-errors") { val metricsListener = subscribeToMetrics() - for(_ <- 1 to 10) { + for (_ ← 1 to 10) { intercept[SQLException] { - val error = "SELECT * FROM NON_EXIST_TABLE" + val error = "SELECT * FROM NO_EXISTENT_TABLE" val errorStatement = connection.createStatement() errorStatement.execute(error) } @@ -158,7 +159,7 @@ class StatementInstrumentationSpec extends TestKitBase with WordSpecLike with Ma } trait StatementsMetricsListenerFixture { - def subscribeToMetrics( ): TestProbe = { + def subscribeToMetrics(): TestProbe = { val metricsListener = TestProbe() Kamon(Metrics).subscribe(StatementsMetrics, "*", metricsListener.ref, permanently = true) // Wait for one empty snapshot before proceeding to the test. @@ -178,7 +179,6 @@ class StatementInstrumentationSpec extends TestKitBase with WordSpecLike with Ma } class NOPSlowQueryProcessor extends SlowQueryProcessor { - override def process(sql: String, executionTimeInMillis: Long, queryThresholdInMillis: Long): Unit = {/*do nothing!!!*/} + override def process(sql: String, executionTimeInMillis: Long, queryThresholdInMillis: Long): Unit = { /*do nothing!!!*/ } } - |