feed with custom protocol

Hi,

first: I’m using gatling 1.5.6.
due to special needs (some part of my script have a binary protocol over http) I must write a custom gatling protocol (following http://gatling.io/docs/1.5.6/developing_gatling/implementing_your_own_protocol_support.html). See below for the code.
It is working fine. But I would like to use feeders. But feed variables are not translated automatically from “{ip}” to session.getAttribute(“ip”).
Is there a piece of code/a way to tell gatling to parse strings to translate from feeder variables?

Thank you

Nicolas

class AppletCommunicationAction1(ip: String, requestName: String, next: ActorRef) extends Action {
def execute(session: Session) {
val requestStartDate = currentTimeMillis()
val responseEndDate = currentTimeMillis()
val requestName = “custom request”

println("execute AppletCommunication “+ip+” "+session.getAttribute(“ip”))

DataWriter.logRequest(session.scenarioName,
session.userId,
"Request " + requestName,
requestStartDate,
responseEndDate,
requestStartDate,
responseEndDate,
RequestStatus.OK)
next ! session
}
def next() = next
}

object AppletCommunicationBuilder {
def action1(ip: String, requestName: String) = new AppletCommunicationAction1Builder(ip, requestName,null)
}

class AppletCommunicationAction1Builder(val ip: String, requestName: String, next:ActorRef) extends ActionBuilder {
def withNext(next: ActorRef) = new AppletCommunicationAction1Builder(ip,requestName,next)
def build(registry: ProtocolConfigurationRegistry): ActorRef = { system.actorOf(Props(new AppletCommunicationAction1(ip, requestName, next))) }
}

object AppletCommunication {
/**

  • This method kicks off our DSL for a binary action.

Hi,

First, you have to realize that we’ll stop maintaining Gatling 1 as soon as Gatling 2 is out, which is a matter of weeks (we’ve issued RC3 yesterday, we plan to have a RC4 but that might be the last one before going final).

You must define AppletCommunicationAction1 ip parameter as an Expression, instead of a String, so your EL String gets parsed. You then have to resolve your Expression with the Session you get as a parameter in execute.

Get it?

Cheers,

Stéphane

Hi,

I think I got it, but how do I resolve an Expression (with the session)? I didn’t found a Session.resolve(Expression) method.

thanks

PS: for Gatling 2, I’m aware of, but when I used it (several weeks ago) it was crashing/having problem, so I wanted to stick first with a stable version. :frowning:

You should definitively migrate to Gatling 2.
The documentation is way more complete, and you’ll get all the explanation you’d need:

OK,

let say I switch to gatling 2, what would be concretly my code? or do you have any sample (I’m familiar with java, but not that much with scala, and the documentation is not sufficient for me to understand fully what I have to do)

Regards,

There’s 2 different things:

  • ActionBuilders are the elements that compose the DSL. They are the definitions.

  • Actions are what the ActionBuilders build. They are the live components (actors) that actually execute the Simulation workflow.
    A basic example is the PauseBuilder/Pause couple.

In order to report the stats, you just have to extends the DataWriterClient trait.

Ok thanks.

for validation (and for people that could be interested), here is what I wrote:

import io.gatling.core.result.message.{ KO, OK, Status }
import akka.actor.{Props, ActorRef}
import io.gatling.core.session.{ Expression, Session }
import io.gatling.core.action.Interruptable
import java.lang.System.currentTimeMillis
import io.gatling.core.result.writer.DataWriterClient

import akka.actor.ActorDSL.actor
import io.gatling.core.action.builder.ActionBuilder
import io.gatling.core.config.Protocols

class AppletCommunicationAction1(ip: Expression[String], requestName: String, val next: ActorRef) extends Interruptable with DataWriterClient {
def execute(session: Session) = {
val requestStartDate = currentTimeMillis()
val responseEndDate = currentTimeMillis()
val requestName = “custom request”
// println(“execute AppletCommunication “+ip(session))+”!”

writeRequestData(session,
requestName,
requestStartDate,
responseEndDate,
requestStartDate,
responseEndDate,
OK)
next ! session
}
}

object AppletCommunicationBuilder {
def action1(ip: Expression[String], requestName: String) = new AppletCommunicationAction1Builder(ip, requestName)
}

class AppletCommunicationAction1Builder(val ip: Expression[String], requestName: String) extends ActionBuilder {
//def withNext(next: ActorRef) = new AppletCommunicationAction1Builder(ip,requestName,next)
def build(next: ActorRef, protocols: Protocols) = {
actor(new AppletCommunicationAction1(ip, requestName,next))
}
}

object AppletCommunication {
/**

  • This method kicks off our DSL for a ping.

LGTM.