diff --git a/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcAction.scala b/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcAction.scala index 8154bce..a6b5988 100644 --- a/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcAction.scala +++ b/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcAction.scala @@ -14,7 +14,7 @@ import scala.util.Try */ trait JdbcAction extends ChainableAction with NameGen { - def log(start: Long, end: Long, tried: Try[_], requestName: Expression[String], session: Session, statsEngine: StatsEngine): Unit = { + def log(start: Long, end: Long, tried: Try[_], requestName: Expression[String], session: Session, statsEngine: StatsEngine): Session = { val (status, message) = tried match { case scala.util.Success(_) => (OK, None) case scala.util.Failure(exception) => (KO, Some(exception.getMessage)) @@ -22,5 +22,6 @@ trait JdbcAction extends ChainableAction with NameGen { requestName.apply(session).foreach { resolvedRequestName => statsEngine.logResponse(session, resolvedRequestName, start, end, status, None, message) } + session.logGroupRequest(start, end, status) } } diff --git a/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcCreateTableAction.scala b/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcCreateTableAction.scala index 69cb02b..7f9470b 100644 --- a/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcCreateTableAction.scala +++ b/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcCreateTableAction.scala @@ -45,8 +45,7 @@ case class JdbcCreateTableAction(requestName: Expression[String], } } future.onComplete(result => { - log(start, clock.nowMillis, result, requestName, session, statsEngine) - next ! session + next ! log(start, clock.nowMillis, result, requestName, session, statsEngine) }) case Failure(error) => throw new IllegalArgumentException(error) diff --git a/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcDeletionAction.scala b/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcDeletionAction.scala index d897b9b..4e2135b 100644 --- a/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcDeletionAction.scala +++ b/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcDeletionAction.scala @@ -41,8 +41,7 @@ case class JdbcDeletionAction(requestName: Expression[String], } result.foreach(_.onComplete(result => { - log(start, clock.nowMillis, result, requestName, session, statsEngine) - next ! session + next ! log(start, clock.nowMillis, result, requestName, session, statsEngine) })) result.onFailure(e => throw new IllegalArgumentException(e)) diff --git a/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcDropTableAction.scala b/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcDropTableAction.scala index 21030cc..a1379f4 100644 --- a/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcDropTableAction.scala +++ b/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcDropTableAction.scala @@ -33,8 +33,7 @@ case class JdbcDropTableAction(requestName: Expression[String], } } future.onComplete(result => { - log(start, clock.nowMillis, result, requestName, session, statsEngine) - next ! session + next ! log(start, clock.nowMillis, result, requestName, session, statsEngine) }) case Failure(error) => throw new IllegalArgumentException(error) diff --git a/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcInsertAction.scala b/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcInsertAction.scala index 3fd476c..137952b 100644 --- a/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcInsertAction.scala +++ b/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcInsertAction.scala @@ -40,8 +40,7 @@ case class JdbcInsertAction(requestName: Expression[String], } } result.foreach(_.onComplete(result => { - log(start, clock.nowMillis, result, requestName, session, statsEngine) - next ! session + next ! log(start, clock.nowMillis, result, requestName, session, statsEngine) })) result.onFailure(e => throw new IllegalArgumentException(e)) diff --git a/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcSelectAction.scala b/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcSelectAction.scala index 718cef6..15997d0 100644 --- a/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcSelectAction.scala +++ b/src/main/scala/dev/code_n_roll/gatling/jdbc/action/JdbcSelectAction.scala @@ -55,8 +55,7 @@ case class JdbcSelectAction[T](requestName: Expression[String], session.markAsFailed }.get case fail: Failure[_] => - log(start, clock.nowMillis, fail, requestName, session, statsEngine) - next ! session + next ! log(start, clock.nowMillis, fail, requestName, session, statsEngine) } } @@ -69,8 +68,7 @@ case class JdbcSelectAction[T](requestName: Expression[String], } modifiedSession.markAsFailed case _ => - log(start, clock.nowMillis, scala.util.Success(""), requestName, session, statsEngine) - modifiedSession + log(start, clock.nowMillis, scala.util.Success(""), requestName, modifiedSession, statsEngine) } } } diff --git a/src/test/scala/dev/code_n_roll/gatling/jdbc/simulation/GroupInsertSimulation.scala b/src/test/scala/dev/code_n_roll/gatling/jdbc/simulation/GroupInsertSimulation.scala new file mode 100644 index 0000000..f090c50 --- /dev/null +++ b/src/test/scala/dev/code_n_roll/gatling/jdbc/simulation/GroupInsertSimulation.scala @@ -0,0 +1,46 @@ +package dev.code_n_roll.gatling.jdbc.simulation + +import dev.code_n_roll.gatling.jdbc.Predef._ +import dev.code_n_roll.gatling.jdbc.builder.column.ColumnHelper._ +import io.gatling.core.Predef._ +import io.gatling.core.scenario.Simulation +import scalikejdbc.{GlobalSettings, LoggingSQLAndTimeSettings} + +import scala.concurrent.duration._ +import scala.util.Random + +/** + * Simulation to check that the reporting of times also works when using a group. + * Therefore, the response time is set to be between 0 and 1000. When the group + * time doesn't work the time will be just zero. + */ +class GroupInsertSimulation extends Simulation { + + val jdbcConfig = jdbc.url("jdbc:h2:mem:test;DB_CLOSE_ON_EXIT=FALSE").username("sa").password("sa").driver("org.h2.Driver") + + GlobalSettings.loggingSQLAndTime = LoggingSQLAndTimeSettings(singleLineMode = true, logLevel = 'warn) + + val scn = scenario("group create insert") + .group("group") { + exec(jdbc("bar table") + .create() + .table("bar") + .columns( + column( + name("abc"), + dataType("VARCHAR"), + constraint("PRIMARY KEY") + ) + ) + ).pause(3.seconds) + .exec(jdbc("insertion") + .insert() + .into("bar (abc)") + .values("'1'")) + } + + setUp( + scn.inject(atOnceUsers(1)), + ).protocols(jdbcConfig) + .assertions(details("group").responseTime.mean.between(0, 1000, inclusive = false)) +}