Skip to content

Instantly share code, notes, and snippets.

@ctranxuan
Last active December 19, 2015 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctranxuan/20004abadafba409cad2 to your computer and use it in GitHub Desktop.
Save ctranxuan/20004abadafba409cad2 to your computer and use it in GitHub Desktop.
import scala.concurrent.duration.Duration
import akka.actor.{ ActorRef, Props }
import io.gatling.core.action.system
import io.gatling.core.action.builder.ActionBuilder
import io.gatling.core.check.Check
import io.gatling.core.config.ProtocolRegistry
import io.gatling.core.session.Expression
import io.gatling.core.session.Session
import io.gatling.core.validation.Failure
// don't know what MttpCheck is, but probably only need only 1 type param now
class MttpCheck[A] extends Check[A]
case class SendMessage(actionName: String, messageType: String, content: Any, ttl: Long, guaranteed: Boolean, nberOfDataChanges: Int, checks: List[Check[_]], next: ActorRef, session: Session, duration: Duration = Duration.Undefined)
class SendStartActionBuilder(val channelName: String,
val actionName: Expression[String],
val queryString: Expression[String],
val positionalParameters: List[Expression[String]],
val namedParameters: Map[String, Expression[String]],
val nberOfDataChanges: Int,
val checks: List[MttpCheck[_]],
val duration: Duration = Duration.Undefined) extends ActionBuilder {
def build(next: ActorRef, protocolConfigurationRegistry: ProtocolConfigurationRegistry): ActorRef =
system.actorOf(Props(
new SendStartAction(channelName, actionName, queryString, positionalParameters, namedParameters, nberOfDataChanges, checks, duration, next)))
}
class SendStartAction(channelName: String,
actionName: Expression[String],
queryString: Expression[String],
positionalParameters: List[Expression[String]],
namedParameters: Map[String, Expression[String]],
val nberOfDataChanges: Int,
checks: List[Check[_]],
val duration: Duration,
val next: ActorRef) extends ClientChannelAction(actionName) {
def execute(aSession: Session) {
val execution = for {
actionName <- actionName(aSession)
actor <- aSession(channelName).validate[ActorRef]
} yield {
val bucket = new Bucket
val requestId = Buckets.addBucket(bucket)
val query = new Query(requestId,
queryString(aSession),
positionalParameters.map(content => content(aSession)).toList.asJava,
namedParameters.mapValues(value => value(aSession)).toMap.asJava,
"", -1, Array(1, 0))
actor ! SendMessage(actionName, "query.start", query, -1, false, nberOfDataChanges, checks, next, aSession, duration)
}
// this will change in the next days as it has to be done in every Action...
execution match {
case Failure(message) =>
next ! aSession
case _ =>
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment