aboutsummaryrefslogtreecommitdiff
path: root/kamon-jdbc/src/test/scala
diff options
context:
space:
mode:
authorDiego <diegolparra@gmail.com>2014-11-23 14:55:46 -0300
committerDiego <diegolparra@gmail.com>2014-12-04 02:26:25 -0300
commitab9fd324a5df3e411e952576b78dc627595e00bf (patch)
tree85cee1b683130ab0a319d072005701327723e746 /kamon-jdbc/src/test/scala
parentbbe12e7c5c1897b6f10486cb216391b33224d5f7 (diff)
downloadKamon-ab9fd324a5df3e411e952576b78dc627595e00bf.tar.gz
Kamon-ab9fd324a5df3e411e952576b78dc627595e00bf.tar.bz2
Kamon-ab9fd324a5df3e411e952576b78dc627595e00bf.zip
! kamon-jdbc: instroduce Statements Metrics like writes, reads, errors and slows queries counter
Diffstat (limited to 'kamon-jdbc/src/test/scala')
-rw-r--r--kamon-jdbc/src/test/scala/kamon/jdbc/instrumentation/StatementInstrumentationSpec.scala67
1 files changed, 67 insertions, 0 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
new file mode 100644
index 00000000..ec8ca4a1
--- /dev/null
+++ b/kamon-jdbc/src/test/scala/kamon/jdbc/instrumentation/StatementInstrumentationSpec.scala
@@ -0,0 +1,67 @@
+/* =========================================================================================
+ * Copyright © 2013-2014 the kamon project <http://kamon.io/>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License") you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions
+ * and limitations under the License.
+ * =========================================================================================
+ */
+
+package kamon.jdbc.instrumentation
+
+import java.sql.{SQLException, DriverManager}
+
+import akka.actor.ActorSystem
+import akka.testkit.TestKit
+import kamon.trace.TraceRecorder
+import org.scalatest.{Matchers, WordSpecLike}
+
+class StatementInstrumentationSpec extends TestKit(ActorSystem("jdbc-spec")) with WordSpecLike with Matchers {
+
+ val connection = DriverManager.getConnection("jdbc:h2:mem:test","SA", "")
+
+ "the StatementInstrumentation" should {
+ "bblabals" in {
+ TraceRecorder.withNewTraceContext("jdbc-trace") {
+ connection should not be null
+
+ val create = "CREATE TABLE Address (Nr INTEGER, Name VARCHAR(128));"
+ val createStatement = connection.createStatement()
+ createStatement.executeUpdate(create)
+
+ val insert = "INSERT INTO Address (Nr, Name) VALUES(1, 'foo')"
+ val insertStatement = connection.prepareStatement(insert)
+ insertStatement.execute()
+
+ val select =
+ """
+ |/*this is a comment*/
+ |SELECT * FROM Address""".stripMargin
+ val selectStatement = connection.prepareCall(select)
+ selectStatement.execute()
+
+ val update = "UPDATE Address SET Name = 'bar' where Nr = 1"
+ val updateStatement = connection.createStatement()
+ updateStatement.execute(update)
+
+ val delete = "DELETE FROM Address where Nr = 1"
+ val deleteStatement = connection.createStatement()
+ deleteStatement.execute(delete)
+
+ intercept[SQLException] {
+ val error = "SELECT * FROM NON_EXIST_TABLE"
+ val errorStatement = connection.createStatement()
+ errorStatement.execute(error)
+ }
+
+ }
+ }
+ }
+}
+