Thanks Stephane. I am having little trouble implementing this protocol. I don't know how to get the response object. Also, I tried it with incorrect credentials but the test still passed. Can you tell how I can fix this. Here is the simulation code:
package cz.senkadam.gatlingsql.requests
import akka.actor.{ActorRef, Props}
import io.gatling.core.Predef._
import io.gatling.core.action.Chainable
import io.gatling.core.action.builder.ActionBuilder
import io.gatling.core.config.Protocols
import io.gatling.core.result.message.{KO, OK}
import io.gatling.core.result.writer.{DataWriter, RequestMessage}
import scala.concurrent.duration._
class DBSimulation extends Simulation{
val mine = new ActionBuilder {
def build(next: ActorRef, protocols: Protocols) = {
system.actorOf(Props(new RunSql(next)))
}
}
val scn = scenario("SQL load test")
.repeat(2) {
exec(mine)
}
setUp(scn.inject(atOnceUsers(1)))
class RunSql (val next: ActorRef) extends Chainable {
def begin(session: Session) {
val delegate = new SqlBuilderSpec
}
def execute(session: Session) {
var start: Long = 0L
var end: Long = 0L
var status: Status = OK
var errorMessage: Option[String] = None
try {
start = System.currentTimeMillis;
begin(session)
end = System.currentTimeMillis;
} catch {
case e: Exception =>
status = KO
errorMessage = Some(e.getMessage)
logger.error("ERROR", e)
} finally {
val requestStartDate, requestEndDate = start
val responseStartDate, responseEndDate = end
val requestName = "Test Scenario"
val message = errorMessage
val extraInfo = Nil
DataWriter.dispatch(RequestMessage(
session.scenarioName,
session.userId,
session.groupHierarchy,
requestName,
requestStartDate,
requestEndDate,
responseStartDate,
responseEndDate,
status,
message,
extraInfo))
next ! session
}
}
}
}